Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
DesignerObject.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/primitive_type.h>
7#include <Utility/TSpan.h>
8#include <SDL/sdl_interface.h>
9#include <Math/math_fwd.h>
10#include <Math/Transform/TDecomposedTransform.h>
11#include "Utility/TFunction.h"
12
13#include <string>
14#include <memory>
15#include <cstddef>
16#include <vector>
17#include <type_traits>
18
19namespace ph::editor::render { class System; }
20
21namespace ph::editor
22{
23
28class RenderData;
29
31{
33
34public:
35 // Work type should be kept in sync with `RenderThread::Work`
36 using RenderWorkType = TFunction<void(render::System&)>;
37
42 static std::string generateObjectName();
43
44public:
45 ~DesignerObject() override;
46
47 virtual TSpanView<DesignerObject*> getChildren() const = 0;
48 virtual bool canHaveChildren() const = 0;
49 virtual math::TDecomposedTransform<real> getLocalToParent() const = 0;
50 virtual void setLocalToParent(const math::TDecomposedTransform<real>& transform) = 0;
51
52 virtual void init();
53 virtual void uninit();
54 virtual void renderInit(RenderThreadCaller& caller);
55 virtual void renderUninit(RenderThreadCaller& caller);
56 virtual void update(const MainThreadUpdateContext& ctx);
57 virtual void renderUpdate(const MainThreadRenderUpdateContext& ctx);
58 virtual void createRenderCommands(RenderThreadCaller& caller);
59
60 virtual void editorTranslate(const math::Vector3R& amount);
61 virtual void editorRotate(const math::QuaternionR& additionalRotation);
62 virtual void editorScale(const math::Vector3R& amount);
63
65
70 template<typename ChildType>
71 ChildType* newChild(
72 bool shouldInit = true,
73 bool shouldSetToDefault = true);
74
78 const SdlClass* clazz,
79 bool shouldInit = true,
80 bool shouldSetToDefault = true);
81
86
89 void deleteChild(DesignerObject* childObj);
90
93 void deleteAllChildren();
94
101
106 void setName(std::string name);
107
112 void setUniqueName(std::string uniqueName);
113
114 void select();
115 void deselect();
116 bool isSelected() const;
117 void setVisibility(bool isVisible);
118 bool isVisible() const;
119 void setTick(bool shouldTick);
120 void setRenderTick(bool shouldTick);
121 bool haveChildren() const;
123 const DesignerScene& getScene() const;
125 const DesignerObject* getParent() const;
126 const std::string& getName() const;
127
128protected:
132
135
136private:
137 // For accessing `setParentScene()` when creating root objects
138 friend class DesignerScene;
139
143 virtual DesignerObject* addChild(DesignerObject* childObj) = 0;
144
148 virtual bool removeChild(DesignerObject* childObj) = 0;
149
152 virtual void selected();
153
156 virtual void deselected();
157
158 void setParentObject(DesignerObject* object);
159 void setParentScene(DesignerScene* scene);
160
161private:
162 union GeneralParent
163 {
164 DesignerScene* u_scene;
165 DesignerObject* u_object;
166 };
167
168 GeneralParent m_parent;
169
170 // SDL-binded fields:
171 std::string m_name;
172
173public:
174 PH_DEFINE_SDL_CLASS(TSdlOwnerClass<DesignerObject>)
175 {
176 ClassType clazz("dobj");
177 clazz.docName("Designer Object");
178 clazz.description("Main base class of designer object.");
179
180 // Creation and removal should be handled by designer scene
181 clazz.allowCreateFromClass(false);
182
183 clazz.baseOn<AbstractDesignerObject>();
184
185 TSdlString<OwnerType> name("name", &OwnerType::m_name);
186 name.description("Name of the designer object.");
187 name.noDefault();// we are supplying custom default name in ctor
188 clazz.addField(name);
189
190 return clazz;
191 }
192};
193
194}// end namespace ph::editor
195
Definition AbstractDesignerObject.h:16
AbstractDesignerObject()
Definition AbstractDesignerObject.cpp:7
Definition DesignerObject.h:31
bool isVisible() const
Definition DesignerObject.ipp:40
virtual void renderUpdate(const MainThreadRenderUpdateContext &ctx)
Definition DesignerObject.cpp:98
virtual void update(const MainThreadUpdateContext &ctx)
Definition DesignerObject.cpp:95
DesignerObject()
Definition DesignerObject.cpp:48
UIPropertyLayout layoutProperties() override
Create custom property layout.
Definition DesignerObject.cpp:128
void setRenderTick(bool shouldTick)
Definition DesignerObject.cpp:282
DesignerObject(const DesignerObject &other)
bool isSelected() const
Definition DesignerObject.ipp:35
~DesignerObject() override
Definition DesignerObject.cpp:60
void setTick(bool shouldTick)
Definition DesignerObject.cpp:277
void select()
Definition DesignerObject.cpp:256
DesignerObject(DesignerObject &&other) noexcept
virtual void renderUninit(RenderThreadCaller &caller)
Definition DesignerObject.cpp:90
DesignerScene & getScene()
Definition DesignerObject.cpp:287
DesignerObject * getParent()
Definition DesignerObject.cpp:309
void deleteChild(DesignerObject *childObj)
Remove, uninitialize and destruct a child.
Definition DesignerObject.cpp:193
virtual void renderInit(RenderThreadCaller &caller)
Definition DesignerObject.cpp:85
ChildType * newChild(bool shouldInit=true, bool shouldSetToDefault=true)
Create and add the new object as a child.
Definition DesignerObject.ipp:14
PH_DEFINE_SDL_CLASS(TSdlOwnerClass< DesignerObject >)
Definition DesignerObject.h:174
virtual void uninit()
Definition DesignerObject.cpp:80
virtual void createRenderCommands(RenderThreadCaller &caller)
Definition DesignerObject.cpp:101
virtual void init()
Definition DesignerObject.cpp:75
void enqueueRenderWork(RenderWorkType work)
Add a render thread work for this object. This method is intended for piecemeal (better to be indepen...
Definition DesignerObject.cpp:233
virtual void editorTranslate(const math::Vector3R &amount)
Definition DesignerObject.cpp:104
bool haveChildren() const
Definition DesignerObject.ipp:71
virtual bool canHaveChildren() const =0
virtual void setLocalToParent(const math::TDecomposedTransform< real > &transform)=0
void deleteAllChildren()
Remove, uninitialize and destruct all children.
Definition DesignerObject.cpp:219
TFunction< void(render::System &)> RenderWorkType
Definition DesignerObject.h:36
void setName(std::string name)
Set name of the object. name should be unique in the scene. If not, the name will be modified automat...
Definition DesignerObject.cpp:238
void setVisibility(bool isVisible)
Definition DesignerObject.cpp:272
void setUniqueName(std::string uniqueName)
Set a unique name to the object.
Definition DesignerObject.cpp:248
static std::string generateObjectName()
Definition DesignerObject.cpp:32
virtual math::TDecomposedTransform< real > getLocalToParent() const =0
const std::string & getName() const
Definition DesignerObject.ipp:66
virtual void editorScale(const math::Vector3R &amount)
Definition DesignerObject.cpp:120
virtual TSpanView< DesignerObject * > getChildren() const =0
DesignerObject & operator=(const DesignerObject &rhs)
virtual void editorRotate(const math::QuaternionR &additionalRotation)
Definition DesignerObject.cpp:112
DesignerObject * addNewChild(DesignerObject *childObj)
Add the object as a child. This method allows an object to be created separately then added to this o...
Definition DesignerObject.cpp:166
void deselect()
Definition DesignerObject.cpp:264
Definition DesignerScene.h:58
Definition MainThreadRenderUpdateContext.h:11
Definition MainThreadUpdateContext.h:11
Thin wrapper for render thread interactions from another thread. Mainly to hide unrelated render thre...
Definition RenderThreadCaller.h:16
Definition UIPropertyLayout.h:17
Definition System.h:26
Definition DesignerObject.h:19
Definition ph_editor.h:10