canvas_editor.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * canvas_editor.h - on-canvas value edit/display "widgets"
  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. #ifndef __STUDIO__CANVAS_EDITOR_H__F294C054
  19. #define __STUDIO__CANVAS_EDITOR_H__F294C054
  20. #include <typeindex>
  21. #include <memory>
  22. namespace core {
  23. class AbstractValue;
  24. }
  25. namespace studio {
  26. class Canvas;
  27. class CanvasEditor {
  28. public:
  29. virtual ~CanvasEditor() = default;
  30. public:
  31. virtual void set_canvas(Canvas* canvas_);
  32. inline Canvas* get_canvas() const {
  33. return canvas;
  34. }
  35. private:
  36. Canvas* canvas = nullptr;
  37. };
  38. class CanvasEditorFactory {
  39. public:
  40. virtual std::unique_ptr<CanvasEditor> operator()() const = 0;
  41. };
  42. class CanvasEditorShowChildren {
  43. public:
  44. virtual bool operator()() const = 0;
  45. };
  46. void add_canvas_editor(Canvas& canvas, std::shared_ptr<core::AbstractValue> node);
  47. } // namespace studio
  48. #define REGISTER_CANVAS_EDITOR(Name, Type, Editor) \
  49. class Name##Factory : \
  50. public CanvasEditorFactory, \
  51. private class_init::Registered<Name##Factory, Type, CanvasEditorFactory> \
  52. { \
  53. public: \
  54. virtual std::unique_ptr<CanvasEditor> operator()() const override { \
  55. return std::make_unique<Editor>(); \
  56. } \
  57. }
  58. #define REGISTER_CANVAS_SHOW_CHILDREN(Name, node_name, value) \
  59. class Name##ShowChildren : \
  60. public CanvasEditorShowChildren, \
  61. private class_init::StringRegistered<Name##ShowChildren, CanvasEditorShowChildren> \
  62. { \
  63. public: \
  64. static std::string name() { \
  65. return node_name; \
  66. } \
  67. public: \
  68. virtual bool operator()() const override { \
  69. return value; \
  70. } \
  71. }
  72. #endif