Brunot
Loading...
Searching...
No Matches
Editor.h
Go to the documentation of this file.
1// File: Editor.h
2// Description: The system manager, handles all systems in the engine
3// Author(s): Marcelo Escamilla, Bryley Elder (marcelo.escamilla@digipen.edu), (bryley.elder@digipen.edu)
4// 2025 / 10 / 03
5// (C) Digipen 2025
6// ____ __ __ __
7// /\__ _\/\ \ /\ \/\ \
8// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
9// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
10// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
11// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
12// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
13#pragma once
14
15#include "System/opengl.h"
16
17// NOTE: Some of these includes are unused, so that you can include editor.h for all the ImGui things
18#define IMGUI_DEFINE_MATH_OPERATORS
19#include "../Submodules/imgui/imgui.h"
20#include "../Submodules/imgui/backends/imgui_impl_opengl3.h"
21#include "../Submodules/imgui/backends/imgui_impl_glfw.h"
22#include "../Submodules/ImGuizmo/src/ImGuizmo.h"
23#include "misc/cpp/imgui_stdlib.h"
24#include "Audio/AudioObject.h"
25
26#ifndef EDITOR_H
27#define EDITOR_H
28#endif
29
30#ifndef NDEBUG
31#define START_WITH_IMGUI true
32#else
33#define START_WITH_IMGUI false
34#endif
35
36class ParticleEmitter;
37
38namespace gfx
39{
40class Texture;
41class Mesh;
42}
43
44namespace sys
45{
46class Editor : public System
47{
48public:
49 auto getDefaultFont() -> ImFont*
50 {
51 return defaultFont;
52 }
53
54#pragma region static_functions
55
59 static auto getEnum() -> Type
60 {
61 return Type::Editor;
62 }
63
64
65#pragma endregion
66
67 Editor();
68 ~Editor() override;
69 Editor(const Editor& other) = default;
70 Editor(Editor&& other) noexcept;
71 auto operator=(const Editor& other) -> Editor&;
72
73 auto operator=(Editor&& other) noexcept -> Editor& = default;
74
75
76#pragma region overridden_functions
77
78 auto clone() const -> std::unique_ptr<GameObject> override
79 {
80 return std::make_unique<Editor>(*this);
81 }
82
83 auto onUpdate(float dt) -> void override;
84
85 auto endWindow() -> void override
86 {
87 }; // for debug ImGUI
88
89 auto onRender() -> void override;
90 auto load(const Stream& stream) -> void override;
91 auto save(Stream& stream) const -> void override;
92
93#pragma endregion
94
95#pragma region Editor_Functions
96
97 auto PreRender() -> void;
98 auto PostRender() -> void;
99
100 auto shouldShowGui() const -> bool
101 {
102 return showImGui;
103 }
104
105
109 auto drawSystemMenu() -> void;
110
111
112 // Scene Menu Things
113
117 auto drawSceneMenu() -> void;
118
119 auto EntityComponentsEditor() const -> void;
120
125 auto drawEntitiesCompact() -> bool;
126
130 auto EmitterEditor() const -> void;
131
132
137 static auto showTexturePickerMenu() -> gfx::Texture*;
138
143 static auto showMeshPickerMenu() -> gfx::Mesh*;
144
145
150 static auto displayTexture(const gfx::Texture* texture) -> void;
151
157 auto receiveShowGUIKeyPressed(const Message* message) -> Message;
158
163 auto select(Entity* selected) -> void;
164
170 auto isSelected(Entity* entity) -> bool;
171
177 auto getSelectedEntity() -> Entity*;
178
184 auto deselect(Entity* entity) -> void;
185
193 auto isPassingFilter(Entity* entity) -> bool;
194
195 // Helper function to toggle the guizmos baseed on key input. W for translate, E for scale, R for rotate.
196 // Called in the Editor's sceneViewport function
197 auto toggleGuizmos() -> void;
198
199 [[nodiscard]] auto getSliderRatio() const -> float;
200
205 auto select(ParticleEmitter* selected) -> void;
206
207
213 auto isSelected(ParticleEmitter* emitter) -> bool;
214
220 auto deselect(ParticleEmitter* toDeselect) -> void;
221
223 ;
224
225#pragma endregion
226
227private:
228#pragma region member_variables
230 ImFont* defaultFont;
232 float sliderRatio = 0.4f;
233
235 ImGuiTextFilter entityFilter;
239 bool compactEntityView = false;
240
241
244
246 Vector4D editorMousePos = {0.f, 0.f, 0.f, 1.f};
247
248
251#pragma endregion
252
253#pragma region helper_functions
254
255 auto SceneViewPort() -> void;
256
260 static void drawEditorTopBar();
261
267 void calculateViewportCoords(float width, float height);
268
269#pragma endregion
270
271#pragma region static_variables
272
273#pragma endregion
274};
275} // namespace sys
276
277
278#undef START_WITH_IMGUI
sys::Json Stream
Definition AudioObject.h:20
#define START_WITH_IMGUI
Definition Editor.h:31
Definition Entity.h:39
friend Entity
Definition GameObject.h:84
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
An object that manages many of a single type of particle.
Definition ParticleEmitter.h:32
Type
Definition System.h:20
@ Editor
Definition System.h:25
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
bool compactEntityView
Whether the Scene Tree should be rendered more compact.
Definition Editor.h:239
auto getSliderRatio() const -> float
Definition Editor.cpp:791
ParticleEmitter * selectedEmitter
the emitter last selected on a particleGenerator
Definition Editor.h:250
Entity * selectedEntity
The entity currently selected in the Scene Tree.
Definition Editor.h:237
auto PreRender() -> void
Definition Editor.cpp:380
auto shouldShowGui() const -> bool
Definition Editor.h:100
static void drawEditorTopBar()
draw the top bar of the editor
Definition Editor.cpp:916
auto drawEntitiesCompact() -> bool
used to determine how much spacing to give entities in the scene view
Definition Editor.cpp:456
static auto getEnum() -> Type
function required by all systems
Definition Editor.h:59
auto deselect(Entity *entity) -> void
deselects and entity if it is currently selected.
Definition Editor.cpp:776
auto operator=(Editor &&other) noexcept -> Editor &=default
ImFont * defaultFont
The default font of the Editor.
Definition Editor.h:230
auto drawSceneMenu() -> void
draw the tree of Entities that exist in a scene
Definition Editor.cpp:416
auto getSceneViewPortMousePosition() -> Vector4D &
Definition Editor.cpp:745
void calculateViewportCoords(float width, float height)
helper function to calculate the coordinates of the mouse over the viewport
Definition Editor.cpp:944
auto isPassingFilter(Entity *entity) -> bool
See if the an Entity is passing the filter and should be drawn in the Scene View Currently unimplemen...
Definition Editor.cpp:784
auto getSelectedEntity() -> Entity *
return selected entity, or nullptr if no entity is selected
Definition Editor.cpp:771
auto EntityComponentsEditor() const -> void
Definition Editor.cpp:536
auto isSelected(Entity *entity) -> bool
check whether an entity is currently selected in the editor
Definition Editor.cpp:766
auto select(Entity *selected) -> void
selects an Entity, and shows it's children in the Component view editor
Definition Editor.cpp:761
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Editor.h:85
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Editor.h:78
static auto displayTexture(const gfx::Texture *texture) -> void
show a texture in a small square
Definition Editor.cpp:629
Vector4D editorMousePos
Position of the mouse relative to the scene viewport.
Definition Editor.h:246
~Editor() override
Definition Editor.cpp:508
auto PostRender() -> void
Post render will run all the normal Render() stuff instead of old function to allow for frame bufferi...
Definition Editor.cpp:798
auto operator=(const Editor &other) -> Editor &
Definition Editor.cpp:522
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Editor.cpp:722
auto EmitterEditor() const -> void
draw editor for adjusting settings of the selected emitter
Definition Editor.cpp:548
auto toggleGuizmos() -> void
Definition Editor.cpp:823
auto receiveShowGUIKeyPressed(const Message *message) -> Message
Definition Editor.cpp:753
Editor()
Definition Editor.cpp:461
auto drawSystemMenu() -> void
Draw the window that shows all the systems in the game.
Definition Editor.cpp:390
bool showImGui
Whether the Editor should be shown.
Definition Editor.h:243
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Editor.cpp:713
float sliderRatio
The ratio of the total width a slider should take up.
Definition Editor.h:232
Editor(const Editor &other)=default
static auto showTexturePickerMenu() -> gfx::Texture *
creates a dropdown menu to select a new texture.
Definition Editor.cpp:558
ImGuiTextFilter entityFilter
IMGui filter for searching the scene tree. currently unused, as filtering a tree is non-trivial.
Definition Editor.h:235
auto getDefaultFont() -> ImFont *
Definition Editor.h:49
auto onUpdate(float dt) -> void override
called once every frame.
Definition Editor.cpp:682
auto SceneViewPort() -> void
This is the Window that activates the viewport and renders the framebuffer.
Definition Editor.cpp:968
static auto showMeshPickerMenu() -> gfx::Mesh *
shows a dropdown menu to choose meshes
Definition Editor.cpp:637
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Editor.cpp:717
Definition Sprite.h:25
the type of elements in a basic_json container
Definition GameObject.h:32
Definition Message.h:34
Definition Vector4D.h:23