Skip to content

Commit

Permalink
fix: better naming and avoid cluttering namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
luishfonseca committed Sep 27, 2023
1 parent e0a1af5 commit 798de30
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 43 deletions.
30 changes: 14 additions & 16 deletions engine/include/cubos/engine/imgui/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

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

using Package = cubos::core::data::Package;

namespace cubos::engine::tools
namespace cubos::engine
{
/// @brief Shows a packaged object's properties in the UI. Should be called inside a
/// `ImGui::BeginTable(2)` and `ImGui::EndTable()` block.
Expand All @@ -18,8 +16,8 @@ namespace cubos::engine::tools
///
/// @param pkg Packaged object to show.
/// @param name Name of the object.
/// @ingroup utils-tool-plugin
void showPackage(const Package& pkg, const std::string& name);
/// @ingroup imgui-plugin
void imguiShowPackage(const core::data::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 @@ -31,8 +29,8 @@ namespace cubos::engine::tools
/// @param pkg Packaged object to edit.
/// @param name Name of the object.
/// @return True if the object was modified, false otherwise.
/// @ingroup utils-tool-plugin
bool editPackage(Package& pkg, const std::string& name);
/// @ingroup imgui-plugin
bool imguiEditPackage(core::data::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 @@ -42,12 +40,12 @@ namespace cubos::engine::tools
/// @tparam T Type of the serializable object.
/// @param object Object to show.
/// @param name Name of the object.
/// @ingroup utils-tool-plugin
/// @ingroup imgui-plugin
template <typename T>
inline void show(const T& object, const std::string& name)
inline void imguiShow(const T& object, const std::string& name)
{
auto pkg = Package::from(object);
showPackage(pkg, name);
auto pkg = core::data::Package::from(object);
imguiShowPackage(pkg, name);
}

/// @brief Shows a serializable object's properties in the UI. Should be called inside a
Expand All @@ -60,17 +58,17 @@ namespace cubos::engine::tools
/// @param object Object to edit.
/// @param name Name of the object.
/// @return True if the object was edited, false otherwise.
/// @ingroup utils-tool-plugin
/// @ingroup imgui-plugin
template <typename T>
inline bool edit(T& object, const std::string& name)
inline bool imguiEdit(T& object, const std::string& name)
{
auto pkg = Package::from(object);
if (editPackage(pkg, name))
auto pkg = core::data::Package::from(object);
if (imguiEditPackage(pkg, name))
{
pkg.into(object);
return true;
}

return false;
}
} // namespace cubos::engine::tools
} // namespace cubos::engine
10 changes: 5 additions & 5 deletions engine/src/cubos/engine/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void main()
bd->ibSize = 0;
}

void cubos::engine::initialize(io::Window window)
void cubos::engine::imguiInitialize(io::Window window)
{
// Initialize ImGui
IMGUI_CHECKVERSION();
Expand Down Expand Up @@ -326,7 +326,7 @@ void cubos::engine::initialize(io::Window window)
CUBOS_INFO("Initialized UI");
}

void cubos::engine::terminate()
void cubos::engine::imguiTerminate()
{
auto& io = ImGui::GetIO();
IM_ASSERT(io.BackendPlatformUserData != nullptr);
Expand Down Expand Up @@ -355,7 +355,7 @@ void cubos::engine::terminate()
ImGui::DestroyContext();
}

void cubos::engine::beginFrame()
void cubos::engine::imguiBeginFrame()
{
ImGuiIO& io = ImGui::GetIO();
auto* bd = (ImGuiData*)io.BackendPlatformUserData;
Expand Down Expand Up @@ -399,7 +399,7 @@ static void setupRenderState(ImGuiData* bd, gl::Framebuffer target)
rd.setFramebuffer(std::move(target));
}

void cubos::engine::endFrame(const gl::Framebuffer& target)
void cubos::engine::imguiEndFrame(const gl::Framebuffer& target)
{
auto* bd = (ImGuiData*)ImGui::GetIO().BackendPlatformUserData;
auto& rd = bd->window->renderDevice();
Expand Down Expand Up @@ -573,7 +573,7 @@ static bool handle(auto&& /*unused*/)
return false;
}

bool cubos::engine::handleEvent(const io::WindowEvent& event)
bool cubos::engine::imguiHandleEvent(const io::WindowEvent& event)
{
return std::visit([&](const auto& e) { return handle(e); }, event);
}
24 changes: 10 additions & 14 deletions engine/src/cubos/engine/imgui/imgui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,34 @@
#include <cubos/core/gl/render_device.hpp>
#include <cubos/core/io/window.hpp>

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(Window window);
/// @ingroup imgui-plugin
void imguiInitialize(core::io::Window window);

/// @brief Shuts down ImGui.
/// @note Should only be called once, after @ref initialize(), and no ImGui calls should be
/// made after this is called.
/// @ingroup core-ui
void terminate();
/// @ingroup imgui-plugin
void imguiTerminate();

/// @brief Begins a new ImGui frame. ImGui calls should be made between this and @ref
/// endFrame().
/// @ingroup core-ui
void beginFrame();
/// @ingroup imgui-plugin
void imguiBeginFrame();

/// @brief Ends the current ImGui frame, and renders the ImGui draw data to the @p target
/// framebuffer, or the default framebuffer if @p target is null.
/// @param target Framebuffer to render to.
/// @ingroup core-ui
void endFrame(const Framebuffer& target = nullptr);
/// @ingroup imgui-plugin
void imguiEndFrame(const core::gl::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 WindowEvent& event);
/// @ingroup imgui-plugin
bool imguiHandleEvent(const core::io::WindowEvent& event);
} // namespace cubos::engine
8 changes: 4 additions & 4 deletions engine/src/cubos/engine/imgui/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace cubos::engine;

static void init(Read<Window> window)
{
initialize(*window);
imguiInitialize(*window);
}

static void begin(EventReader<WindowEvent> events)
Expand All @@ -24,15 +24,15 @@ static void begin(EventReader<WindowEvent> events)
// Not sure how we will propagate that information to other systems yet.
for (auto event : events)
{
handleEvent(event);
imguiHandleEvent(event);
}

beginFrame();
imguiBeginFrame();
}

static void end()
{
endFrame();
imguiEndFrame();
}

void cubos::engine::imguiPlugin(Cubos& cubos)
Expand Down
6 changes: 4 additions & 2 deletions engine/src/cubos/engine/imgui/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

using namespace cubos::engine;

using Package = cubos::core::data::Package;

// Converts a scalar (must not be an Object, Array or Dictionary) value to a
// string.
static std::string valueToString(const Package& pkg)
Expand Down Expand Up @@ -155,7 +157,7 @@ static void showInternal(const Package& pkg, const std::string& name)
pkg.isStructured() ? showStructured(pkg, name) : showScalar(pkg, name);
}

void cubos::engine::tools::showPackage(const Package& pkg, const std::string& name)
void cubos::engine::imguiShowPackage(const Package& pkg, const std::string& name)
{
ImGui::TableNextRow();
showInternal(pkg, name);
Expand Down Expand Up @@ -410,7 +412,7 @@ static bool editInternal(Package& pkg, const std::string& name)
return pkg.isStructured() ? editStructured(pkg, name) : editScalar(pkg, name);
}

bool cubos::engine::tools::editPackage(Package& pkg, const std::string& name)
bool cubos::engine::imguiEditPackage(Package& pkg, const std::string& name)
{
ImGui::TableNextRow();
return editInternal(pkg, name);
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cubos/engine/tools/entity_inspector/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void inspectEntity(Write<World> world)
if (!selection.isNull() && world->isAlive(selection))
{
auto pkg = world->pack(selection);
if (tools::editPackage(pkg, std::to_string(selection.index)))
if (imguiEditPackage(pkg, std::to_string(selection.index)))
{
world->unpack(selection, pkg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void inspector(Write<Settings> settings)
ImGui::BeginTable("split", 2, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable);
for (auto& setting : map)
{
tools::edit(setting.second, setting.first);
imguiEdit(setting.second, setting.first);
}
ImGui::EndTable();
}
Expand Down

0 comments on commit 798de30

Please sign in to comment.