#ifndef IMGUI_CONTEXT_HPP #define IMGUI_CONTEXT_HPP #include "gl_context.hpp" #include "sdl_context.hpp" #include "sdl_main_window.hpp" #include namespace bookmouse { class ImguiContext { public: ImguiContext(GlContext& glContext, SdlContext& sdlContext, SdlMainWindow& mainWindow); ~ImguiContext(); const ImGuiIO& getIO() const; void setIOFlag(ImGuiConfigFlags_ flag) const; bool processEvent(SDL_Event& event) const; void startFrame() const; void render() const; private: SdlMainWindow& m_mainWindow; }; template class ConditionalRaii { public: template ConditionalRaii(Args&&... args) : m_expr{false} { Expr expr{}; m_expr = expr(std::forward(args)...); } ~ConditionalRaii() { Cleanup cleanup{}; if (m_expr) { cleanup(); } } ConditionalRaii(const ConditionalRaii& rhs) = delete; ConditionalRaii(ConditionalRaii&& rhs) = delete; ConditionalRaii& operator=(const ConditionalRaii& rhs) = delete; ConditionalRaii& operator=(ConditionalRaii&& rhs) = delete; operator bool() const { return m_expr; } private: bool m_expr; }; #define STRUCT_FUNCTOR(FUNCTOR_NAME, FUNCTOR_FUNCTION) \ struct FUNCTOR_NAME { \ auto operator()() -> decltype(FUNCTOR_FUNCTION()) \ { \ return FUNCTOR_FUNCTION(); \ } \ }; #define STRUCT_FUNCTOR_ARGS(FUNCTOR_NAME, FUNCTOR_FUNCTION) \ struct FUNCTOR_NAME { \ template \ auto operator()(Args&&... args) -> /* FORCE BREAK */ \ decltype(FUNCTOR_FUNCTION(std::forward(args)...)) \ { \ return FUNCTOR_FUNCTION(std::forward(args)...); \ } \ }; STRUCT_FUNCTOR_ARGS(ImGuiBeginMenu, ImGui::BeginMenu) STRUCT_FUNCTOR(ImGuiEndMenu, ImGui::EndMenu) using ImguiMenu = ConditionalRaii; #undef STRUCT_FUNCTOR #undef STRUCT_FUNCTOR_ARGS } // namespace bookmouse #endif