canvas_editor.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. void add_canvas_editor(Canvas& canvas, std::shared_ptr<core::AbstractValue> node);
  43. }
  44. #define REGISTER_CANVAS_EDITOR(Name, Type, Editor) \
  45. class Name##Factory : \
  46. public CanvasEditorFactory, \
  47. class_init::Registered<Name##Factory, Type, CanvasEditorFactory> \
  48. { \
  49. public: \
  50. virtual std::unique_ptr<CanvasEditor> operator()() const override { \
  51. return std::make_unique<Editor>(); \
  52. } \
  53. }
  54. #endif