animated.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* animated.cpp - context menu for animated-like nodes
  2. * Copyright (C) 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 <QMenu>
  18. #include <core/util/nullptr.h>
  19. #include <generic/node_editor.h>
  20. #include <generic/timeline_editor.h>
  21. #include <widgets/timeline_area.h>
  22. #include <util/strings.h>
  23. using namespace fmt::literals;
  24. namespace rainynite::studio {
  25. class AnimatedEditor :
  26. public TimelineEditor,
  27. public NodeEditor
  28. {
  29. public:
  30. virtual bool context_menu(double seconds, QMenu& menu) {
  31. menu.addAction(
  32. QIcon::fromTheme("list-add"),
  33. "Insert frame",
  34. [this, seconds]() {
  35. if (auto node = get_node()) {
  36. if (node->can_set_any_at()) {
  37. auto ctx = no_null(get_core_context());
  38. auto nctx = make_shared<core::Context>(*ctx);
  39. nctx->set_seconds(seconds);
  40. node->set_any_at(node->get_any(nctx), nctx);
  41. }
  42. }
  43. }
  44. );
  45. return true;
  46. }
  47. };
  48. REGISTER_CANVAS_TEMPLATE_NODE_EDITOR(TimelineArea, AnimatedEditor, Interpolate);
  49. } // namespace rainynite::studio