Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
EditorComponent.h
Go to the documentation of this file.
1/* Copyright (c) 2018 DIVIDE-Studio
2Copyright (c) 2009 Ionut Cava
3
4This file is part of DIVIDE Framework.
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software
8and associated documentation files (the "Software"), to deal in the Software
9without restriction,
10including without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense,
12and/or sell copies of the Software, and to permit persons to whom the Software
13is furnished to do so,
14subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in all
17copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22PARTICULAR PURPOSE AND NONINFRINGEMENT.
23IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24DAMAGES OR OTHER LIABILITY,
25WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26CONNECTION WITH THE SOFTWARE
27OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29*/
30
31#pragma once
32#ifndef DVD_SGN_EDITOR_COMPONENT_H_
33#define DVD_SGN_EDITOR_COMPONENT_H_
34
36
37namespace Divide
38{
39 class Editor;
40 class SGNComponent;
41 class ByteBuffer;
42 class SceneNode;
43 class SceneGraphNode;
44 class PropertyWindow;
45
46 namespace Attorney
47 {
48 class EditorComponentEditor;
49 class EditorComponentSceneGraphNode;
50 }; //namespace Attorney
51
52 enum class ComponentType : U32
53 {
54 TRANSFORM = toBit(1),
55 ANIMATION = toBit(2),
57 RAGDOLL = toBit(4),
58 NAVIGATION = toBit(5),
59 BOUNDS = toBit(6),
60 RENDERING = toBit(7),
61 NETWORKING = toBit(8),
62 UNIT = toBit(9),
63 RIGID_BODY = toBit(10),
64 SELECTION = toBit(11),
66 POINT_LIGHT = toBit(13),
67 SPOT_LIGHT = toBit(14),
68 SCRIPT = toBit(15),
70 COUNT = 16
71 };
72
73 namespace Names {
74 static const char* componentType[] =
75 {
76 "TRANSFORM",
77 "ANIMATION",
78 "INVERSE_KINEMATICS",
79 "RAGDOLL",
80 "NAVIGATION",
81 "BOUNDS",
82 "RENDERING",
83 "NETWORKING",
84 "UNIT",
85 "RIGID_BODY",
86 "SELECTION",
87 "DIRECTIONAL_LIGHT",
88 "POINT_LIGHT",
89 "SPOT_LIGHT",
90 "SCRIPT",
91 "ENVIRONMENT_PROBE",
92 "NONE",
93 };
94 };
95
96 static_assert(ArrayCount(Names::componentType) == to_base(ComponentType::COUNT) + 1u, "ComponentType name array out of sync!");
97 namespace TypeUtil
98 {
99 [[nodiscard]] const char* ComponentTypeToString(const ComponentType compType) noexcept;
100 [[nodiscard]] ComponentType StringToComponentType(const string & name);
101 };
102
104 {
105 PUSH_TYPE = 0,
108 SEPARATOR,
109 BUTTON,
114 TRANSFORM,
115 MATERIAL,
116 COUNT
117 };
118
120 {
124
126 void* _data = nullptr;
127 vec2<F32> _range = { 0.0f, 0.0f };
129 F32 _step = 0.0f;
131 const char* _format = "";
132 const char* const* _labels = nullptr;
135 // Use this to configure smaller data sizes for integers only (signed or unsigned) like:
136 // U8: (PushConstantType::UINT, _byteCount=BYTE)
137 // I16: (PushConstantType::INT, _byteCount=WORD)
138 // etc
139 // byteCount of 3 is currently NOT supported
141
142 bool _readOnly = false;
143 bool _serialise = true;
144 bool _hexadecimal = false;
145
146 template<typename T>
147 T* getPtr() const;
148 template<typename T>
149 T get() const;
150
151 template<typename T>
152 void get(T& dataOut) const;
153
154 template<typename T>
155 void set(const T& dataIn);
156
157 [[nodiscard]] const char* getDisplayName(const U8 index) const;
158 [[nodiscard]] bool supportsByteCount() const noexcept;
159 [[nodiscard]] bool isMatrix() const noexcept;
160 };
161
163 {
166
167 public:
168
169 explicit EditorComponent( PlatformContext& context, ComponentType type, std::string_view name);
170 ~EditorComponent() override;
171
172 void addHeader(const Str<32>& name) {
173 EditorComponentField field = {};
174 field._name = name;
176 field._readOnly = true;
177 registerField(MOV(field));
178 }
179
180 void registerField(EditorComponentField&& field);
181
182 [[nodiscard]] vector<EditorComponentField>& fields() noexcept { return _fields; }
183 [[nodiscard]] const vector<EditorComponentField>& fields() const noexcept { return _fields; }
184
185 void onChangedCbk(const DELEGATE<void, std::string_view>& cbk) { _onChangedCbk = cbk; }
186 void onChangedCbk(DELEGATE<void, std::string_view>&& cbk) noexcept { _onChangedCbk = MOV(cbk); }
187
188
191
192 protected:
193 void onChanged(const EditorComponentField& field) const;
194 void saveToXML(boost::property_tree::ptree& pt) const;
195 void loadFromXML(const boost::property_tree::ptree& pt);
196
197 bool saveCache(ByteBuffer& outputBuffer) const;
198 bool loadCache(ByteBuffer& inputBuffer);
199
200 void saveFieldToXML(const EditorComponentField& field, boost::property_tree::ptree& pt) const;
201 void loadFieldFromXML(EditorComponentField& field, const boost::property_tree::ptree& pt);
202
203 protected:
206 };
207
208 namespace Attorney {
211 return comp._fields;
212 }
213
214 static const vector<EditorComponentField>& fields(const EditorComponent& comp) noexcept {
215 return comp._fields;
216 }
217
218 static void onChanged(const EditorComponent& comp, const EditorComponentField& field) {
219 comp.onChanged(field);
220 }
221
223 };
224
226 static void saveToXML(const EditorComponent& comp, boost::property_tree::ptree& pt)
227 {
228 comp.saveToXML(pt);
229 }
230
231 static void loadFromXML(EditorComponent& comp, const boost::property_tree::ptree& pt)
232 {
233 comp.loadFromXML(pt);
234 }
235
236 static bool saveCache( const EditorComponent& comp, ByteBuffer& outputBuffer )
237 {
238 return comp.saveCache(outputBuffer);
239 }
240
241 static bool loadCache( EditorComponent& comp, ByteBuffer& inputBuffer )
242 {
243 return comp.loadCache(inputBuffer);
244 }
245
246 friend class Divide::SceneNode;
249 };
250 }; // namespace Attorney
251
252}; // namespace Divide
253#endif //DVD_SGN_EDITOR_COMPONENT_H_
254
255#include "EditorComponent.inl"
#define MOV(...)
constexpr auto ArrayCount(Args &&... args) -> decltype(std::size(FWD(args)...))
static void onChanged(const EditorComponent &comp, const EditorComponentField &field)
static const vector< EditorComponentField > & fields(const EditorComponent &comp) noexcept
static vector< EditorComponentField > & fields(EditorComponent &comp) noexcept
static bool loadCache(EditorComponent &comp, ByteBuffer &inputBuffer)
static void loadFromXML(EditorComponent &comp, const boost::property_tree::ptree &pt)
static bool saveCache(const EditorComponent &comp, ByteBuffer &outputBuffer)
static void saveToXML(const EditorComponent &comp, boost::property_tree::ptree &pt)
void onChangedCbk(const DELEGATE< void, std::string_view > &cbk)
PROPERTY_R(ComponentType, componentType, ComponentType::COUNT)
void saveToXML(boost::property_tree::ptree &pt) const
void loadFromXML(const boost::property_tree::ptree &pt)
const vector< EditorComponentField > & fields() const noexcept
void addHeader(const Str< 32 > &name)
void onChangedCbk(DELEGATE< void, std::string_view > &&cbk) noexcept
bool loadCache(ByteBuffer &inputBuffer)
bool saveCache(ByteBuffer &outputBuffer) const
vector< EditorComponentField > _fields
DELEGATE< void, std::string_view > _onChangedCbk
void onChanged(const EditorComponentField &field) const
vector< EditorComponentField > & fields() noexcept
PROPERTY_RW(Str< 128 >, name, "")
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
static const char * componentType[]
ComponentType StringToComponentType(const std::string_view name)
const char * ComponentTypeToString(const ComponentType compType) noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
DELEGATE_STD< Ret, Args... > DELEGATE
std::function< Ret(Args...) > DELEGATE_STD
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
uint32_t U32
EditorComponentFieldType
@ DROPDOWN_TYPE
Only U8 types supported!
constexpr T toBit(const T X)
Converts an arbitrary positive integer value to a bitwise value used for masks.
constexpr auto to_base(const Type value) -> Type
void set(const T &dataIn)
DELEGATE_STD< void, void * > _dataGetter
DELEGATE_STD< void, const void * > _dataSetter
vec2< F32 > _range
Used by slider_type as a min / max range or dropdown as selected_index / count.
F32 _step
0.0f == no +- buttons
DELEGATE_STD< const char *, U8 > _displayNameGetter
bool isMatrix() const noexcept
const char *const * _labels
bool supportsByteCount() const noexcept
EditorComponentFieldType _type
const char * getDisplayName(const U8 index) const