editor.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* editor.h - abstract canvas editor
  2. * Copyright (C) 2017 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. #ifndef STUDIO_CANVAS_EDITOR_H_78E5E734_53ED_511D_B6F7_AD0003B70709
  18. #define STUDIO_CANVAS_EDITOR_H_78E5E734_53ED_511D_B6F7_AD0003B70709
  19. #include <core/abstract_factory.h>
  20. #include <core/class_init.h>
  21. #include "attachable.h"
  22. namespace rainynite::core {
  23. class AbstractValue;
  24. }
  25. namespace rainynite::studio {
  26. class CanvasEditor : public CanvasAttachable {
  27. };
  28. struct AbstractCanvasEditorFactory : public AbstractFactory<CanvasEditor> {
  29. };
  30. template <class CanvasT>
  31. struct CanvasEditorFactory : public AbstractCanvasEditorFactory {
  32. };
  33. template <class CanvasT, class EditorT>
  34. struct CanvasEditorFactoryI : public CanvasEditorFactory<CanvasT>
  35. {
  36. unique_ptr<CanvasEditor> operator()() const override {
  37. return make_unique<EditorT>();
  38. }
  39. };
  40. template <class CanvasT, class EditorT, class Type>
  41. struct CanvasEditorFactoryInstance :
  42. public CanvasEditorFactoryI<CanvasT, EditorT>,
  43. private class_init::Registered<
  44. CanvasEditorFactoryInstance<CanvasT, EditorT, Type>,
  45. Type,
  46. CanvasEditorFactory<CanvasT>
  47. >
  48. {
  49. };
  50. #define REGISTER_CANVAS_EDITOR(CanvasT, EditorT, Type) \
  51. template struct CanvasEditorFactoryInstance<CanvasT, EditorT, Type>
  52. #define REGISTER_CANVAS_EDITOR_NAME(CanvasT, EditorT, Name) \
  53. struct Name##CanvasEditorNameInfoInstance : \
  54. public CanvasEditorFactoryI<CanvasT, EditorT>, \
  55. private class_init::StringRegistered< \
  56. Name##CanvasEditorNameInfoInstance, \
  57. AbstractCanvasEditorFactory \
  58. > \
  59. { \
  60. static string name() { \
  61. return #Name; \
  62. } \
  63. }
  64. template <class CanvasT>
  65. unique_ptr<CanvasEditor> make_canvas_editor(Type type) {
  66. return class_init::type_info<CanvasEditorFactory<CanvasT>,unique_ptr<CanvasEditor>>(type);
  67. }
  68. /// Create & add canvas editor by name
  69. shared_ptr<CanvasEditor> add_canvas_named_editor(AbstractCanvas& canvas, string const& name);
  70. /// Create & add canvas node editor to canvas
  71. shared_ptr<CanvasEditor> add_canvas_node_editor(AbstractCanvas& canvas, shared_ptr<core::AbstractValue> node);
  72. } // namespace rainynite::studio
  73. #endif