editor_context.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* editor_context.h - editor Context
  2. * Copyright (C) 2017-2018 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 STUDIO_GENERIC_EDITOR_CONTEXT_H_E5FE1C55_3375_5F79_8BBB_5D6A55CA2AA0
  18. #define STUDIO_GENERIC_EDITOR_CONTEXT_H_E5FE1C55_3375_5F79_8BBB_5D6A55CA2AA0
  19. #include <core/std/string.h>
  20. #include <core/context.h>
  21. #include <core/node_tree/index.h>
  22. namespace rainynite::core {
  23. class AbstractValue;
  24. class ActionStack;
  25. }
  26. namespace rainynite::studio {
  27. class EditorContext {
  28. public:
  29. template <typename... Args>
  30. using Signal = boost::signals2::signal<Args...>;
  31. EditorContext(shared_ptr<core::Context> context_) :
  32. context(context_)
  33. {}
  34. shared_ptr<core::Context> get_context() const {
  35. return context;
  36. }
  37. void set_active_node(core::NodeTreeIndex index);
  38. core::NodeTreeIndex get_active_node_index() const {
  39. return active_node;
  40. }
  41. shared_ptr<core::AbstractValue> get_active_node() const {
  42. return get_node(get_active_node_index());
  43. }
  44. template <class T>
  45. shared_ptr<T> get_active_node_as() const {
  46. return dynamic_pointer_cast<T>(get_active_node());
  47. }
  48. shared_ptr<core::AbstractValue> get_node(core::NodeTreeIndex index) const;
  49. // Get tree
  50. shared_ptr<core::NodeTree> tree() const;
  51. /// Get action stack
  52. shared_ptr<core::ActionStack> action_stack() const;
  53. void set_file_name(string const& fname) {
  54. file_name = fname;
  55. }
  56. string get_file_name() const {
  57. return file_name;
  58. }
  59. Signal<void(core::Time)>& changed_time() {
  60. return context->changed_time;
  61. }
  62. Signal<void(core::Time::fps_type)>& changed_fps() {
  63. return context->changed_fps;
  64. }
  65. Signal<void(core::NodeTreeIndex)>& changed_active_node() {
  66. return changed_active_node_;
  67. }
  68. Signal<void(bool)> playback_change;
  69. private:
  70. shared_ptr<core::Context> context;
  71. core::NodeTreeIndex active_node;
  72. string file_name;
  73. Signal<void(core::NodeTreeIndex)> changed_active_node_;
  74. };
  75. shared_ptr<EditorContext> global_dummy_context();
  76. } // namespace rainynite::studio
  77. #endif