Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions editor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
#include <thread>
#include <core/exceptions/Exceptions.hpp>

/**
* @brief Entry point for the Nexo Editor application.
*
* Initializes logging and retrieves singleton instances for the editor and scene view manager. Sets up the default scene
* and registers the main application windows including the Scene Tree, Scene View Manager, Console, and Asset Manager.
* Enters the main loop where it continuously renders and updates the editor until it is closed, ensuring a consistent
* frame rate by adjusting the sleep duration based on frame execution time. If a nexo::Exception is thrown, the error is
* logged and the application exits with a non-zero status.
*
* @param argc Number of command-line arguments.
* @param argv Array of command-line argument strings.
* @return int Returns 0 on normal shutdown, or 1 if an exception occurs.
*/
int main(int argc, char **argv)
{
try {
Expand Down
85 changes: 85 additions & 0 deletions editor/src/DocumentWindows/AssetManagerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@

namespace nexo::editor {

/**
* @brief Initializes the asset manager with default and imported assets.
*
* Populates the asset list with 100 default assets, assigning alternating asset types.
* Retrieves the singleton asset catalog and registers a new model asset under a predefined location.
* Additionally, imports a model and a texture from file paths relative to the executable,
* setting up asset references for use within the manager.
*/
void AssetManagerWindow::setup() {
// Initialize assets
for (int i = 0; i < 100; ++i) {
Expand Down Expand Up @@ -53,10 +61,23 @@ namespace nexo::editor {

}

/**
* @brief Clears all managed asset references.
*
* This method clears the internal list of assets, effectively releasing any references held
* by the AssetManagerWindow. It is typically invoked during the shutdown process to ensure that
* all assets are properly released.
*/
void AssetManagerWindow::shutdown() {
m_assets.clear();
}

/**
* @brief Displays the asset manager window.
*
* Sets the initial window size, opens the "Asset Manager" window, and renders its contents including
* the menu bar and the grid of assets. If the window cannot be opened, it ends the session early.
*/
void AssetManagerWindow::show() {
ImGui::SetNextWindowSize(ImVec2(800, 600), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Asset Manager", nullptr, ImGuiWindowFlags_MenuBar)) {
Expand All @@ -74,10 +95,24 @@ namespace nexo::editor {
ImGui::End();
}

/**
* @brief Placeholder for update operations in the asset manager.
*
* This method is designed for future expansion to handle updating the asset manager's state.
*/
void AssetManagerWindow::update() {
// Update logic if necessary
}

/**
* @brief Calculates layout parameters for asset display based on available width.
*
* This function computes the number of columns that can fit in the current available width and determines
* the size and spacing for each asset item. It also updates various color settings for UI elements such as thumbnails
* and titles using ImGui's color scheme.
*
* @param availWidth The total available width for laying out asset items.
*/
void AssetManagerWindow::calculateLayout(float availWidth) {
// Sizes
m_layout.size.columnCount = std::max(static_cast<int>(availWidth / (m_layout.size.iconSize + m_layout.size.iconSpacing)), 1);
Expand All @@ -100,6 +135,13 @@ namespace nexo::editor {
m_layout.color.titleText = ImGui::GetColorU32(ImGuiCol_Text);
}

/**
* @brief Renders the menu bar with layout customization options.
*
* This function creates an "Options" menu within the asset manager's menu bar,
* providing sliders to adjust the icon size (ranging from 32 to 128) and icon spacing
* (ranging from 0 to 32) used in the asset grid layout.
*/
void AssetManagerWindow::drawMenuBar() {
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("Options")) {
Expand All @@ -111,6 +153,14 @@ namespace nexo::editor {
}
}

/**
* @brief Renders the asset grid within the asset manager window.
*
* Retrieves the current list of assets from the asset catalog and uses an ImGuiListClipper
* to efficiently process and display only the visible asset rows according to the layout settings.
* For each asset in the visible grid segment, it calculates the screen position based on the current
* cursor position and layout parameters, and delegates rendering to drawAsset().
*/
void AssetManagerWindow::drawAssetsGrid() {
ImVec2 startPos = ImGui::GetCursorScreenPos();

Expand All @@ -132,6 +182,18 @@ namespace nexo::editor {
clipper.End();
}

/**
* @brief Renders an asset within the asset grid.
*
* Draws the asset’s thumbnail, type overlay, title background, and selection indicators in the specified display area.
* The function sets up an invisible button to handle user interaction for selection and shows a tooltip with the asset's full location on hover.
* If the asset reference is expired, no rendering occurs.
*
* @param asset Reference to the asset to be rendered.
* @param index Index of the asset in the grid, used for unique identification.
* @param itemPos Screen coordinates for the top-left corner of the asset's display area.
* @param itemSize Dimensions of the asset's display area.
*/
void AssetManagerWindow::drawAsset(const assets::GenericAssetRef& asset, int index, const ImVec2& itemPos, const ImVec2& itemSize) {
auto assetData = asset.lock();
if (!assetData)
Expand Down Expand Up @@ -195,6 +257,19 @@ namespace nexo::editor {

}

/**
* @brief Updates the selection state of an asset based on user interaction.
*
* This function modifies the set of selected assets using the asset's index and the
* current state of modifier keys:
* - With Ctrl held, it toggles the selection state of the asset.
* - With Shift held, it selects all assets in the range from the last selected asset to
* the current asset.
* - Without any modifier keys, it clears previous selections and selects only the current asset.
*
* @param index The index of the asset to update.
* @param isSelected Indicates whether the asset is already selected.
*/
void AssetManagerWindow::handleSelection(int index, bool isSelected)
{
LOG(NEXO_INFO, "Asset {} {}", index, isSelected ? "deselected" : "selected");
Expand All @@ -220,6 +295,16 @@ namespace nexo::editor {
}
}

/**
* @brief Returns the overlay color for a given asset type.
*
* This method maps a specific asset type to a predefined 32-bit color value used for overlay rendering.
* For recognized asset types such as TEXTURE and MODEL, it returns their corresponding colors;
* for other types, it returns a fully transparent color.
*
* @param type The asset type for which to determine the overlay color.
* @return ImU32 The packed 32-bit color value corresponding to the asset type.
*/
ImU32 AssetManagerWindow::getAssetTypeOverlayColor(assets::AssetType type) const {
switch (type) {
case assets::AssetType::TEXTURE: return IM_COL32(200, 70, 70, 255);
Expand Down
8 changes: 7 additions & 1 deletion editor/src/DocumentWindows/AssetManagerWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ namespace nexo::editor {

class AssetManagerWindow final : public ADocumentWindow {
public:
AssetManagerWindow() = default;
/**
* @brief Default constructor for AssetManagerWindow.
*
* Creates an instance of AssetManagerWindow without performing any initialization.
* Call setup() after construction to initialize the window.
*/
AssetManagerWindow() = default;

void setup() override;
void shutdown() override;
Expand Down
31 changes: 27 additions & 4 deletions editor/src/Editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,42 @@ namespace nexo::editor {
private:
// Singleton: private constructor and destructor
Editor();
~Editor() = default;
/**
* @brief Destroys the Editor instance.
*
* This default destructor cleans up the Editor singleton using the compiler-generated behavior.
*/
~Editor() = default;

public:
// Singleton: Meyers' Singleton Pattern
/**
* @brief Retrieves the singleton instance of the Editor.
*
* Implements the Meyers' Singleton pattern to lazily initialize and return the single Editor instance.
* The instance is created on the first call in a thread-safe manner (guaranteed by the C++11 standard).
*
* @return Editor& A reference to the Editor singleton instance.
*/
static Editor& getInstance()
{
static Editor s_instance;
return s_instance;
}

// Singleton: delete copy constructor and assignment operator
/**
* @brief Deleted copy constructor to enforce singleton behavior.
*
* This function is explicitly deleted to prevent copying of the Editor instance,
* ensuring that only one instance of the Editor class exists.
*/
Editor(Editor const&) = delete;
void operator=(Editor const&) = delete;
/**
* @brief Deleted assignment operator to enforce the Singleton design pattern.
*
* This operator is explicitly deleted to prevent assignment of the Editor instance,
* ensuring that only a single instance exists.
*/
void operator=(Editor const&) = delete;

/**
* @brief Initializes the engine, setting up necessary components and systems.
Expand Down
11 changes: 11 additions & 0 deletions editor/src/SceneManagerBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ namespace nexo::editor {
m_isEntitySelected = false;
}

/**
* @brief Renames a scene or layer according to the provided selection type and properties.
*
* This function updates the name for either a scene or a layer based on the given selection type:
* - When `type` is `SelectionType::SCENE` and `data` holds `SceneProperties`, the scene's name is updated.
* - When `type` is `SelectionType::LAYER` and `data` holds `LayerProperties`, the layer's name within the scene is updated.
*
* @param type The selection type indicating whether to rename a scene or a layer.
* @param data A variant containing the properties (either scene or layer) associated with the object to rename.
* @param newName The new name to assign to the selected scene or layer.
*/
void SceneManagerBridge::renameObject(const SelectionType type, VariantData &data, const std::string &newName) const
{
if (type == SelectionType::SCENE && std::holds_alternative<SceneProperties>(data))
Expand Down
10 changes: 10 additions & 0 deletions editor/src/backends/ImGuiBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ namespace nexo::editor {
THROW_EXCEPTION(BackendRendererApiNotSupported, "UNKNOWN");
}

/**
* @brief Sets the error callback for the ImGui backend on the specified window.
*
* For OpenGL systems, this function retrieves the error callback from the OpenGL-specific backend
* and assigns it to the provided window. If the current graphics API is not OpenGL, it throws a
* BackendRendererApiNotSupported exception.
*
* @param window The window on which to set the error callback.
* @throws BackendRendererApiNotSupported If the graphics API is not OpenGL.
*/
void ImGuiBackend::setErrorCallback([[maybe_unused]] const std::shared_ptr<renderer::Window> &window)
{
#ifdef GRAPHICS_API_OPENGL
Expand Down
Loading