context_listener.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * context_listener.cpp - Context-dependent entity
  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 "context_listener.h"
  20. namespace studio {
  21. ContextListener::ContextListener(std::shared_ptr<EditorContext> context_) :
  22. destroy_detector(std::make_shared<Null>())
  23. {
  24. set_context(context_);
  25. }
  26. void ContextListener::set_context(std::shared_ptr<EditorContext> context_) {
  27. // TODO: disconnect from previous context!
  28. context = context_;
  29. if (context == nullptr)
  30. context = global_dummy_context();
  31. connect_boost(
  32. context->changed_time(),
  33. [this](core::Time time) {
  34. time_changed(time);
  35. }
  36. );
  37. connect_boost(
  38. context->changed_active_node(),
  39. [this](std::shared_ptr<core::AbstractValue> node) {
  40. active_node_changed(node);
  41. }
  42. );
  43. time_changed(get_core_context()->get_time());
  44. fps_changed(get_core_context()->get_fps());
  45. }
  46. }