3#include "Editor/IEditor.h"
4#include "EventBasedInput.h"
6#include "EditorExtension.h"
8#include "Commands/EditorCommand.h"
9#include "Foundation/Geometry/BoundingBox.hpp"
25 using CommandCreator = std::function<EditorCommand* (EditorState*)>;
30 CommandCreator creator;
82 static void COGSCORE_EDITOR_API registerExtensionCommand(
const StringView & key, CommandCreator creator);
83 static COGSCORE_EDITOR_API std::vector<ExtensionCommand> & getExtensionCommands();
85 static void COGSCORE_EDITOR_API registerExtensionItem(
const StringView & key,
const StringView & name);
86 static COGSCORE_EDITOR_API std::vector<ExtensionItem> & getExtensionItems();
88 void initialize()
override;
89 void cleanup()
override;
92 void processShortcuts();
94 void beginFrame()
override;
96 bool isActive()
const override {
return active; }
101 void showText(
const char* format, ...)
const;
106 bool imageButton(Icon icon,
int size,
int padding);
108 void clear(
bool interactive=
true)
override;
116 void open(
const StringView & path,
bool openInRoot,
bool synchronous)
override;
117 void save()
override;
118 void saveAs()
override;
119 void saveIncremental()
override;
122 void exportEntities(
bool exportScene =
false);
125 void copy()
override;
126 void paste()
override;
128 void invokeCommand(
const StringView & key)
override;
130 void destroy()
override;
131 void destroyPermanently();
133 void changeMode(EditingMode mode);
134 void focusSelected();
136 bool focusBoundingBox(
const Cogs::Geometry::DBoundingBox& boundingBox);
159 void selectOne(EntityId
id);
161 void clearCommands();
163 void onlineHelp(
bool generalHelp);
168 EditorCommand * doApply(std::unique_ptr<EditorCommand>&& newCommand)
176 if (commands.size() && commands.back()->merge(newCommand.get())) {
177 return commands.back().get();
181 commands.resize(commandIndex + 1);
182 commands.emplace_back(std::move(newCommand));
185 return commands.back().get();
189 template<
typename Command,
typename... Args>
190 Command * apply(Args... args)
192 assert(modalCommand ==
nullptr);
193 auto newCommand = std::make_unique<Command>(state.get(), std::move(args)...);
194 return (Command*)doApply(std::move(newCommand));
197 template<
typename Command,
typename... Args>
198 Command * applySelected(Args... args)
200 return apply<Command, EntityIds, Args...>(state->selected, std::move(args)...);
225 void openInternal(
const StringView& path,
bool openInRoot,
bool synchronous,
bool interactive);
230 std::unique_ptr<struct EditorState> state;
234 std::vector<std::unique_ptr<EditorCommand>> commands;
235 static constexpr size_t NoCommand =
static_cast<size_t>(-1);
236 size_t commandIndex = NoCommand;
238 std::unique_ptr<class MaterialEditor> materialEditor;
243 mutable int textElementId = 0;
245 bool initialized =
false;
249 float sidebarWidth = 200;
250 float inspectorWidth = 250;
251 float menuHeight = 20;
252 float toolbarHeight = 40;
253 glm::vec2 buttonSize = glm::vec2{ 24 };
255 float statusbarHeight = 20;
256 bool showStatusbar =
true;
257 std::string statusbarText;
258 bool guiStatusInStatusbar =
true;
260 bool showToolbar =
true;
261 bool showSidebar =
true;
262 bool showInspector =
true;
263 bool showMenu =
true;
266 const std::string& getStatusbarText()
const {
return statusbarText; }
267 bool showingGuiStatusbarText()
const {
return guiStatusInStatusbar; }
268 float getStatusbarHeight()
const {
return showStatusbar ? statusbarHeight : 0.0f; }
269 float getToolbarHeight()
const {
return showToolbar ? toolbarHeight : 0.0f; }
270 float getSidebarWidth()
const {
return showSidebar ? sidebarWidth : 0.0f; }
271 float getInspectorWidth()
const {
return showInspector ? inspectorWidth : 0.0f; }
272 float getMenuHeight()
const {
return showMenu ? menuHeight : 0.0f; }
274 virtual void exportScene(
const StringView & path)
override;
275 virtual EntityIds getSelected()
const override;
276 virtual void select(
const EntityIds & ids, SelectMode mode = SelectMode::Exclusive)
override;
277 virtual EditorCommand * createCommand(
const StringView & key)
override;
278 virtual void createEntity(
const StringView & type,
const StringView & name)
override;
Container for components, providing composition of dynamic entities.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
bool getLayerVisibility(const ComponentModel::Entity *entity, StringView layer)
Returns true if any Node in layer is visible.
std::vector< Cogs::Core::WeakEntityPtr > standardEntities
Set of entities created when the Editor loads.
bool isUserRootEntity(const Cogs::ComponentModel::Entity *entity) const
Checks if the entity is.
void showAll()
Make all entities visible.
void showHide(bool visible)
Show or hide selected entity and all children.
void showText(const char *format,...) const
Show the same type of label as ImGui::Text, but with the added ability to highlight and copy text....
void selectFurthestAway()
Search and select visible entity furthest away from selection. Ie.e. find outliers.
void open(const StringView &path, bool openInRoot, bool synchronous) override
Open file.
void setStatusbarText(const std::string &text, bool guiStatus)
void hideUnselected()
Make all non-selected entities invisible.
bool isStandardEntity(const Cogs::ComponentModel::Entity *entity) const
Provides a weakly referenced view over the contents of a string.
Contains code for composing and managing entities built from components.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ Wireframe
Wireframe rendering.
@ Solid
Opaque geometry in arbitrary order.
Base class for Cogs Editor commands.
Abstract base class for all editor commands showing GUI in interactive mode.
virtual void beginModal()=0
Called when the command is initiated.