context.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* context.h - Context
  2. * Copyright (C) 2017 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef CORE_CONTEXT_H_1B1FD015_F94D_5409_AC92_8B1D26396EFA
  18. #define CORE_CONTEXT_H_1B1FD015_F94D_5409_AC92_8B1D26396EFA
  19. #include <boost/signals2/signal.hpp>
  20. #include <core/std/memory.h>
  21. #include <core/std/any.h>
  22. #include <core/time/period.h>
  23. namespace rainynite::core {
  24. class Document;
  25. template <typename>
  26. class Value;
  27. /**
  28. * Context for node calculation and rendering.
  29. *
  30. * For now it mostly contains document, time, fps and time period.
  31. */
  32. class Context {
  33. public:
  34. Context() = default;
  35. explicit Context(weak_ptr<Document> document_);
  36. Context(Context const& context_);
  37. Context(Context&& context_) = default;
  38. Context& operator=(Context const& context_) = default;
  39. Context& operator=(Context&& context_) = default;
  40. virtual ~Context() = default;
  41. public:
  42. inline shared_ptr<Document> get_document() const {
  43. return document.lock();
  44. }
  45. inline Time get_time() const {
  46. return time;
  47. }
  48. inline void set_time(Time time_) {
  49. time = time_;
  50. changed_time(time);
  51. }
  52. inline void set_frames(double frames) {
  53. time.set_frames(frames);
  54. changed_time(time);
  55. }
  56. inline void set_seconds(double seconds) {
  57. time.set_seconds(seconds);
  58. changed_time(time);
  59. }
  60. inline void to_start() {
  61. set_time(get_period().get_first());
  62. }
  63. inline void to_end() {
  64. set_time(get_period().get_last());
  65. }
  66. void set_period(TimePeriod const& period);
  67. TimePeriod get_period() const;
  68. inline any get_render_settings() const {
  69. return render_settings;
  70. }
  71. inline any& mod_render_settings() {
  72. return render_settings;
  73. }
  74. inline Time::fps_type get_fps() {
  75. return fps;
  76. }
  77. void set_fps(Time::fps_type fps_);
  78. public:
  79. boost::signals2::signal<void(Time)> changed_time;
  80. boost::signals2::signal<void(Time::fps_type)> changed_fps;
  81. private:
  82. weak_ptr<Document> document;
  83. Time::fps_type fps = 1;
  84. Time time;
  85. shared_ptr<Value<TimePeriod>> time_period;
  86. any render_settings;
  87. };
  88. } // namespace rainynite::core
  89. #endif