node_editor.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* node_editor.cpp - abstract node editor widget class
  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. #include <core/node_tree/transform.h>
  18. #include <core/action_stack.h>
  19. #include <core/util/nullptr.h>
  20. #include "node_editor.h"
  21. namespace rainynite::studio {
  22. void NodeEditor::set_node(core::NodeTreeIndex index) {
  23. if (node_connection.connected())
  24. node_connection.disconnect();
  25. node_index = index;
  26. auto node = get_context()->get_node(node_index);
  27. if (node == nullptr)
  28. return;
  29. node_update();
  30. node_connection = node->subscribe([this]() {
  31. node_update();
  32. });
  33. }
  34. Geom::Affine get_transform(NodeEditor const& editor) {
  35. if (auto ctx = editor.get_context()) {
  36. if (auto tree = ctx->tree())
  37. return core::get_transform(ctx->get_context(), *tree, editor.get_node_index());
  38. }
  39. return {};
  40. }
  41. void NodeEditor::write_value(any value) {
  42. auto action_stack = no_null(get_context()->action_stack());
  43. action_stack->emplace<core::actions::ChangeValueAt>(
  44. get_node(),
  45. value,
  46. get_core_context()
  47. );
  48. }
  49. void NodeEditor::close_action() {
  50. auto action_stack = no_null(get_context()->action_stack());
  51. action_stack->close();
  52. }
  53. } // namespace rainynite::studio