context_listener.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* context_listener.cpp - Context-dependent entity
  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/context.h>
  18. #include <core/action_stack.h>
  19. #include "context_listener.h"
  20. namespace rainynite::studio {
  21. ContextListener::ContextListener(shared_ptr<EditorContext> context_) {
  22. set_context(context_);
  23. }
  24. void ContextListener::set_context(shared_ptr<EditorContext> context_) {
  25. // TODO: disconnect from previous context!
  26. context = context_;
  27. if (context == nullptr)
  28. context = global_dummy_context();
  29. connect_boost(
  30. context->changed_time(),
  31. [this](core::Time time) {
  32. time_changed(time);
  33. }
  34. );
  35. connect_boost(
  36. context->changed_fps(),
  37. [this](core::Time::fps_type fps) {
  38. fps_changed(fps);
  39. }
  40. );
  41. connect_boost(
  42. context->changed_active_node(),
  43. [this](auto index) {
  44. active_node_index_changed(index);
  45. }
  46. );
  47. time_changed(get_core_context()->get_time());
  48. fps_changed(get_core_context()->get_fps());
  49. }
  50. void ContextListener::undo() {
  51. get_context()->action_stack()->undo();
  52. }
  53. void ContextListener::redo() {
  54. get_context()->action_stack()->redo();
  55. }
  56. void ContextListener::clear_undo_history() {
  57. get_context()->action_stack()->clear();
  58. }
  59. void ContextListener::set_active_node(core::NodeTreeIndex index) {
  60. get_context()->set_active_node(index);
  61. }
  62. void ContextListener::active_node_index_changed(core::NodeTreeIndex index) {
  63. active_node_changed(get_context()->get_node(index));
  64. }
  65. } // namespace rainynite::studio