document.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* document.cpp - document
  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. #include <core/node_info.h>
  18. #include <core/document.h>
  19. #include <core/context.h>
  20. #include <core/node_tree.h>
  21. #include <core/action_stack.h>
  22. namespace rainynite::core {
  23. REGISTER_NODE(Document);
  24. Document::Document(shared_ptr<BaseValue<Renderable>> root_) :
  25. default_context(nullptr),
  26. action_stack(make_shared<ActionStack>())
  27. {
  28. init<Renderable>(root, {});
  29. init<Geom::Point>(size, {320, 240});
  30. init<TimePeriod>(main_time_period, {Time(0, 12), Time(5, 12)});
  31. // TODO: use constraints
  32. init_property(soundtrack, Type(typeid(Audio)), make_node_with_name("EmptyAudio"));
  33. if (root_)
  34. set_root(root_);
  35. else
  36. set_root(make_node_with_name<BaseValue<Renderable>>("Empty"));
  37. new_id();
  38. }
  39. Document::~Document() {
  40. }
  41. shared_ptr<NodeTree> Document::get_tree() {
  42. if (tree == nullptr)
  43. tree = make_shared<NodeTree>(static_pointer_cast<Document>(shared_from_this()), action_stack);
  44. return tree;
  45. }
  46. DocumentType Document::get(shared_ptr<Context> /*context*/) const {
  47. return {};
  48. }
  49. shared_ptr<Context> Document::get_default_context() {
  50. if (!default_context) {
  51. default_context = make_shared<Context>(static_pointer_cast<Document>(shared_from_this()));
  52. }
  53. return default_context;
  54. }
  55. } // namespace rainynite::core