blob: c6059d67e8c7a3177be860849d61af1646995105 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#ifndef IMGUI_CONTEXT_HPP
#define IMGUI_CONTEXT_HPP
#include "gl_context.hpp"
#include "sdl_context.hpp"
#include "sdl_main_window.hpp"
#include <imgui/imgui.h>
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 <typename Expr, typename Cleanup>
class ConditionalRaii {
public:
template <typename... Args>
ConditionalRaii(Args&&... args) : m_expr{false}
{
Expr expr{};
m_expr = expr(std::forward<Args>(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 <typename... Args> \
auto operator()(Args&&... args) -> /* FORCE BREAK */ \
decltype(FUNCTOR_FUNCTION(std::forward<Args>(args)...)) \
{ \
return FUNCTOR_FUNCTION(std::forward<Args>(args)...); \
} \
};
STRUCT_FUNCTOR_ARGS(ImGuiBeginMenuBar, ImGui::BeginMenuBar)
STRUCT_FUNCTOR(ImGuiEndMenuBar, ImGui::EndMenuBar)
using ImguiMenuBar = ConditionalRaii<ImGuiBeginMenuBar, ImGuiEndMenuBar>;
STRUCT_FUNCTOR_ARGS(ImGuiBeginMenu, ImGui::BeginMenu)
STRUCT_FUNCTOR(ImGuiEndMenu, ImGui::EndMenu)
using ImguiMenu = ConditionalRaii<ImGuiBeginMenu, ImGuiEndMenu>;
// STRUCT_FUNCTOR_ARGS(ImGui
#undef STRUCT_FUNCTOR
#undef STRUCT_FUNCTOR_ARGS
} // namespace bookmouse
#endif
|