context.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * context.cpp - Context
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <core/context.h>
  19. #include <core/document.h>
  20. namespace rainynite::core {
  21. Context::Context(weak_ptr<Document> document_) :
  22. document(document_)
  23. {
  24. auto doc = get_document();
  25. if (!doc)
  26. return;
  27. time_period = doc->get_main_time_period();
  28. fps = get_period().get_fps();
  29. time = Time(0, fps);
  30. }
  31. Context::Context(Context const& context_) :
  32. document(context_.document),
  33. fps(context_.fps),
  34. time(context_.time),
  35. time_period(context_.time_period),
  36. render_settings(context_.render_settings)
  37. {
  38. }
  39. void Context::set_period(TimePeriod const& period) {
  40. time_period = make_value<TimePeriod>(period);
  41. }
  42. TimePeriod Context::get_period() const {
  43. return time_period->mod();
  44. }
  45. void Context::set_fps(Time::fps_type fps_) {
  46. fps = fps_;
  47. time.set_fps(fps);
  48. time_period->mod().set_fps(fps);
  49. time_period->changed();
  50. changed_fps(fps);
  51. }
  52. } // namespace rainynite::core