context_listener.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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<core::Context> context_) :
  22. context(context_),
  23. destroy_detector(std::make_shared<Null>())
  24. {}
  25. std::shared_ptr<core::Context> ContextListener::get_context() const {
  26. return context;
  27. }
  28. void ContextListener::set_context(std::shared_ptr<core::Context> context_) {
  29. context = context_;
  30. if (auto context = get_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(context->get_time());
  44. fps_changed(context->get_fps());
  45. }
  46. }
  47. }