context_listener.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* context_listener.h - Context-dependent entity
  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_CONTEXT_LISTENER_H_4EE76790_980D_55BC_9584_1B71A700816E
  18. #define STUDIO_GENERIC_CONTEXT_LISTENER_H_4EE76790_980D_55BC_9584_1B71A700816E
  19. #include <core/std/memory.h>
  20. #include <core/util/destroy_detector.h>
  21. #include <core/node_tree/index.h>
  22. #include "editor_context.h"
  23. namespace rainynite::studio {
  24. class ContextListener : public DestroyDetector {
  25. public:
  26. ContextListener(shared_ptr<EditorContext> context_=nullptr);
  27. virtual ~ContextListener() = default;
  28. public:
  29. shared_ptr<core::Context> get_core_context() const {
  30. return context->get_context();
  31. }
  32. shared_ptr<EditorContext> get_context() const {
  33. return context;
  34. }
  35. void set_core_context(shared_ptr<core::Context> core_context) {
  36. set_context(make_shared<EditorContext>(core_context));
  37. }
  38. virtual void set_context(shared_ptr<EditorContext> context_);
  39. void undo();
  40. void redo();
  41. void clear_undo_history();
  42. void set_active_node(core::NodeTreeIndex index);
  43. protected:
  44. core::Time get_time() const {
  45. return time;
  46. }
  47. virtual void time_changed(core::Time time_) {
  48. time = time_;
  49. }
  50. virtual void fps_changed(core::Time::fps_type) {}
  51. virtual void active_node_index_changed(core::NodeTreeIndex index);
  52. virtual void active_node_changed(shared_ptr<core::AbstractValue>) {}
  53. private:
  54. shared_ptr<EditorContext> context;
  55. core::Time time;
  56. core::NodeTreeIndex active_node_index;
  57. };
  58. } // namespace rainynite::studio
  59. #endif