Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move UI Code to the Engine #594

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[submodule "core/lib/spdlog"]
path = core/lib/spdlog
url = https://github.com/gabime/spdlog
[submodule "core/lib/imgui"]
path = core/lib/imgui
url = https://github.com/ocornut/imgui.git
[submodule "core/lib/fmt"]
path = core/lib/fmt
url = https://github.com/fmtlib/fmt.git
Expand All @@ -25,3 +22,6 @@
[submodule "docs/css/m.css"]
path = docs/css
url = https://github.com/mosra/m.css
[submodule "engine/lib/imgui"]
path = engine/lib/imgui
url = https://github.com/ocornut/imgui.git
17 changes: 1 addition & 16 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ set(CUBOS_CORE_SOURCE
"src/cubos/core/al/oal_audio_device.cpp"
"src/cubos/core/al/oal_audio_device.hpp"

"src/cubos/core/ui/imgui.cpp"
"src/cubos/core/ui/serialization.cpp"
"src/cubos/core/ui/ecs.cpp"

"src/cubos/core/ecs/entity_manager.cpp"
"src/cubos/core/ecs/component_manager.cpp"
"src/cubos/core/ecs/commands.cpp"
Expand Down Expand Up @@ -154,25 +150,14 @@ endif ()

add_subdirectory(lib/json)

add_library(imgui STATIC
"lib/imgui/imgui.cpp"
"lib/imgui/imgui_draw.cpp"
"lib/imgui/imgui_tables.cpp"
"lib/imgui/imgui_widgets.cpp"
"lib/imgui/imgui_demo.cpp"
"lib/imgui/misc/cpp/imgui_stdlib.cpp"
)

target_include_directories(imgui PUBLIC "lib/imgui" "lib/imgui/misc/cpp/imgui_stdlib.hpp")

add_subdirectory(lib/stduuid)
target_link_libraries(cubos-core PUBLIC stduuid)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

target_compile_definitions(cubos-core PUBLIC GLM_FORCE_SILENT_WARNINGS) # Needed for compilation to succeed on MSVC
target_link_libraries(cubos-core PUBLIC glm::glm spdlog imgui fmt::fmt json ${CMAKE_DL_LIBS})
target_link_libraries(cubos-core PUBLIC glm::glm spdlog fmt::fmt json ${CMAKE_DL_LIBS})
target_link_libraries(cubos-core PRIVATE glad Threads::Threads)

# Add core tests
Expand Down
25 changes: 0 additions & 25 deletions core/include/cubos/core/ui/ecs.hpp

This file was deleted.

16 changes: 0 additions & 16 deletions core/include/cubos/core/ui/module.dox

This file was deleted.

1 change: 0 additions & 1 deletion core/lib/imgui
Submodule imgui deleted from 075f4a
1 change: 0 additions & 1 deletion core/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ make_sample(DIR "ecs/general")
make_sample(DIR "gl/compute")
make_sample(DIR "gl/debug_renderer")
make_sample(DIR "gl/quad")
make_sample(DIR "ui")
95 changes: 0 additions & 95 deletions core/samples/ui/main.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions core/src/cubos/core/ui/ecs.cpp

This file was deleted.

14 changes: 14 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ set(CUBOS_ENGINE_SOURCE
"src/cubos/engine/window/plugin.cpp"

"src/cubos/engine/imgui/plugin.cpp"
"src/cubos/engine/imgui/imgui.cpp"
"src/cubos/engine/imgui/serialization.cpp"

"src/cubos/engine/tools/asset_explorer/plugin.cpp"
"src/cubos/engine/tools/settings_inspector/plugin.cpp"
Expand Down Expand Up @@ -67,6 +69,18 @@ target_include_directories(cubos-engine PUBLIC "include" PRIVATE "src")
target_link_libraries(cubos-engine PUBLIC cubos-core)
cubos_common_target_options(cubos-engine)

add_library(imgui STATIC
"lib/imgui/imgui.cpp"
"lib/imgui/imgui_draw.cpp"
"lib/imgui/imgui_tables.cpp"
"lib/imgui/imgui_widgets.cpp"
"lib/imgui/imgui_demo.cpp"
"lib/imgui/misc/cpp/imgui_stdlib.cpp"
)

target_include_directories(imgui PUBLIC "lib/imgui" "lib/imgui/misc/cpp/imgui_stdlib.hpp")
target_link_libraries(cubos-engine PUBLIC imgui)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(cubos-engine PUBLIC -Wno-attributes)
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
/// @file
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved
/// @brief Functions for initializing and using ImGui.
/// @ingroup core-ui
/// @ingroup imgui-plugin

#pragma once

#include <cubos/core/gl/render_device.hpp>
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved
#include <cubos/core/io/window.hpp>

namespace cubos::core::ui
using Framebuffer = cubos::core::gl::Framebuffer;
using Window = cubos::core::io::Window;
using WindowEvent = cubos::core::io::WindowEvent;

namespace cubos::engine
{
/// @brief Initializes ImGui for use with the given window.
/// @note Should only be called once and no ImGui calls should be made before this is called.
/// @param window The window to use.
/// @ingroup core-ui
void initialize(io::Window window);
void initialize(Window window);

/// @brief Shuts down ImGui.
/// @note Should only be called once, after @ref initialize(), and no ImGui calls should be
Expand All @@ -30,11 +34,11 @@ namespace cubos::core::ui
/// framebuffer, or the default framebuffer if @p target is null.
/// @param target Framebuffer to render to.
/// @ingroup core-ui
void endFrame(const gl::Framebuffer& target = nullptr);
void endFrame(const Framebuffer& target = nullptr);

/// @brief Passes a window event to ImGui.
/// @param event Event to pass.
/// @return True if the event was handled by ImGui, false otherwise.
/// @ingroup core-ui
bool handleEvent(const io::WindowEvent& event);
} // namespace cubos::core::ui
bool handleEvent(const WindowEvent& event);
} // namespace cubos::engine
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/// @file
/// @brief Functions for showing and editing serializable objects in the UI.
/// @ingroup core-ui
/// @ingroup imgui-plugin

#pragma once

#include <cubos/core/data/package.hpp>

namespace cubos::core::ui
using Package = cubos::core::data::Package;
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved

namespace cubos::engine::tools
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved
{
/// @brief Shows a packaged object's properties in the UI. Should be called inside a
/// `ImGui::BeginTable(2)` and `ImGui::EndTable()` block.
Expand All @@ -16,8 +18,8 @@ namespace cubos::core::ui
///
/// @param pkg Packaged object to show.
/// @param name Name of the object.
/// @ingroup core-ui
void showPackage(const data::Package& pkg, const std::string& name);
/// @ingroup utils-tool-plugin
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved
void showPackage(const Package& pkg, const std::string& name);

/// @brief Shows a packaged object's properties in the UI, allowing the user to edit the
/// object. Should be called inside a `ImGui::BeginTable(3)` and `ImGui::EndTable()` block.
Expand All @@ -29,8 +31,8 @@ namespace cubos::core::ui
/// @param pkg Packaged object to edit.
/// @param name Name of the object.
/// @return True if the object was modified, false otherwise.
/// @ingroup core-ui
bool editPackage(data::Package& pkg, const std::string& name);
/// @ingroup utils-tool-plugin
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved
bool editPackage(Package& pkg, const std::string& name);

/// @brief Shows a serializable object's properties in the UI. Should be called inside a
/// `ImGui::BeginTable(2)` and `ImGui::EndTable()` block.
Expand All @@ -40,11 +42,11 @@ namespace cubos::core::ui
/// @tparam T Type of the serializable object.
/// @param object Object to show.
/// @param name Name of the object.
/// @ingroup core-ui
/// @ingroup utils-tool-plugin
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved
template <typename T>
inline void show(const T& object, const std::string& name)
{
auto pkg = data::Package::from(object);
auto pkg = Package::from(object);
showPackage(pkg, name);
}

Expand All @@ -58,11 +60,11 @@ namespace cubos::core::ui
/// @param object Object to edit.
/// @param name Name of the object.
/// @return True if the object was edited, false otherwise.
/// @ingroup core-ui
/// @ingroup utils-tool-plugin
luishfonseca marked this conversation as resolved.
Show resolved Hide resolved
template <typename T>
inline bool edit(T& object, const std::string& name)
{
auto pkg = data::Package::from(object);
auto pkg = Package::from(object);
if (editPackage(pkg, name))
{
pkg.into(object);
Expand All @@ -71,4 +73,4 @@ namespace cubos::core::ui

return false;
}
} // namespace cubos::core::ui
} // namespace cubos::engine::tools
1 change: 1 addition & 0 deletions engine/lib/imgui
Submodule imgui added at 94da58
Loading
Loading