123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- /* abstract_editor.h - abstract canvas editor
- * Copyright (C) 2017 caryoscelus
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef STUDIO_CANVAS_ABSTRACT_EDITOR_H_78E5E734_53ED_511D_B6F7_AD0003B70709
- #define STUDIO_CANVAS_ABSTRACT_EDITOR_H_78E5E734_53ED_511D_B6F7_AD0003B70709
- #include <core/std/vector.h>
- #include <core/abstract_factory.h>
- #include <core/util/class_init.h>
- #include <core/node_tree/index.h>
- #include <core/node_info/node_info.h>
- #include "attachable.h"
- namespace rainynite::core {
- class AbstractValue;
- }
- namespace rainynite::studio {
- class AbstractCanvasEditor : public CanvasAttachable {
- };
- struct AbstractAbstractCanvasEditorFactory : public AbstractFactory<AbstractCanvasEditor> {
- };
- template <class CanvasT>
- struct AbstractCanvasEditorFactory : public AbstractAbstractCanvasEditorFactory {
- };
- template <class CanvasT>
- struct AbstractCanvasNodeEditorFactory : public AbstractAbstractCanvasEditorFactory {
- };
- template <class CanvasT, class EditorT>
- struct AbstractCanvasEditorFactoryI : public AbstractCanvasEditorFactory<CanvasT>
- {
- unique_ptr<AbstractCanvasEditor> operator()() const override {
- return make_unique<EditorT>();
- }
- };
- template <class CanvasT, class EditorT>
- struct AbstractCanvasNodeEditorFactoryI : public AbstractCanvasNodeEditorFactory<CanvasT>
- {
- unique_ptr<AbstractCanvasEditor> operator()() const override {
- return make_unique<EditorT>();
- }
- };
- template <class CanvasT, class EditorT, class Type>
- struct AbstractCanvasEditorFactoryInstance :
- public AbstractCanvasEditorFactoryI<CanvasT, EditorT>,
- private class_init::Registered<
- AbstractCanvasEditorFactoryInstance<CanvasT, EditorT, Type>,
- Type,
- AbstractCanvasEditorFactory<CanvasT>
- >
- {
- };
- template <class CanvasT, class EditorT, class NodeT>
- struct AbstractCanvasNodeEditorFactoryInstance :
- public AbstractCanvasNodeEditorFactoryI<CanvasT, EditorT>,
- private class_init::Registered<
- AbstractCanvasNodeEditorFactoryInstance<CanvasT, EditorT, NodeT>,
- NodeT,
- AbstractCanvasNodeEditorFactory<CanvasT>
- >
- {
- };
- #define REGISTER_CANVAS_EDITOR(CanvasT, EditorT, Type) \
- template struct AbstractCanvasEditorFactoryInstance<CanvasT, EditorT, Type>
- #define REGISTER_CANVAS_NODE_EDITOR(CanvasT, EditorT, NodeT) \
- template struct AbstractCanvasNodeEditorFactoryInstance<CanvasT, EditorT, NodeT>
- #define REGISTER_CANVAS_TEMPLATE_NODE_EDITOR(CanvasT, EditorT, Name) \
- template <typename T> \
- class Name##CanvasT##NodeEditorFactoryInstance : \
- public AbstractCanvasNodeEditorFactoryI<CanvasT, EditorT>, \
- private class_init::StringRegistered< \
- Name##CanvasT##NodeEditorFactoryInstance<T>, \
- AbstractCanvasNodeEditorFactory<CanvasT> \
- > \
- { \
- public: \
- static string name() {\
- return #Name+string("/")+core::get_primitive_type(typeid(T))(); \
- } \
- }; \
- TYPE_INSTANCES(Name##CanvasT##NodeEditorFactoryInstance)
- #define REGISTER_CANVAS_EDITOR_NAME(CanvasT, EditorT, Name) \
- struct Name##AbstractCanvasEditorNameInfoInstance : \
- public AbstractCanvasEditorFactoryI<CanvasT, EditorT>, \
- private class_init::StringRegistered< \
- Name##AbstractCanvasEditorNameInfoInstance, \
- AbstractAbstractCanvasEditorFactory \
- > \
- { \
- static string name() { \
- return #Name; \
- } \
- }
- template <class CanvasT>
- unique_ptr<AbstractCanvasEditor> make_canvas_editor(Type type) {
- return class_init::type_info<AbstractCanvasEditorFactory<CanvasT>,unique_ptr<AbstractCanvasEditor>>(type);
- }
- template <class CanvasT>
- unique_ptr<AbstractCanvasEditor> make_canvas_node_editor(std::type_index node_type) {
- using core::node_type_name;
- return class_init::name_info<AbstractCanvasNodeEditorFactory<CanvasT>>(node_type_name(node_type))();
- }
- /// Create & add canvas editor by name
- shared_ptr<AbstractCanvasEditor> add_canvas_named_editor(AbstractCanvas& canvas, string const& name);
- /// Create & add canvas node editor to canvas
- vector<shared_ptr<AbstractCanvasEditor>> add_canvas_node_editor(AbstractCanvas& canvas, core::NodeTreeIndex index);
- } // namespace rainynite::studio
- #endif
|