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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#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;
ImGuiIO& getIO();
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 Imgui ImGui
#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(ImBeginMenuBar, Imgui::BeginMenuBar)
STRUCT_FUNCTOR(ImEndMenuBar, Imgui::EndMenuBar)
using ImMenuBar = ConditionalRaii<ImBeginMenuBar, ImEndMenuBar>;
STRUCT_FUNCTOR_ARGS(ImBeginMenu, Imgui::BeginMenu)
STRUCT_FUNCTOR(ImEndMenu, Imgui::EndMenu)
using ImMenu = ConditionalRaii<ImBeginMenu, ImEndMenu>;
STRUCT_FUNCTOR_ARGS(ImBeginPopupModal, Imgui::BeginPopupModal)
// N.B. EndPopup is needed for BeginPopupModal
STRUCT_FUNCTOR(ImEndPopupModal, Imgui::EndPopup)
using ImPopupModal = ConditionalRaii<ImBeginPopupModal, ImEndPopupModal>;
STRUCT_FUNCTOR_ARGS(ImBeginTable, Imgui::BeginTable)
STRUCT_FUNCTOR(ImEndTable, Imgui::EndTable)
using ImTable = ConditionalRaii<ImBeginTable, ImEndTable>;
// STRUCT_FUNCTOR_ARGS(Im
#undef Imgui
#undef STRUCT_FUNCTOR
#undef STRUCT_FUNCTOR_ARGS
constexpr auto ImBegin = ImGui::Begin;
constexpr auto ImEnd = ImGui::End;
inline void ImSameLine(float xOffset = 0.0, float spacing = 0.0)
{
ImGui::SameLine(xOffset, spacing);
}
#define ImText ImGui::Text
inline bool ImButton(const char* label, const ImVec2& size = ImVec2(0, 0))
{
return ImGui::Button(label, size);
}
constexpr auto ImGetTime = ImGui::GetTime;
inline void ImNextRow(ImGuiTableRowFlags row_flags = 0, float min_row_height = 0.0f)
{
ImGui::TableNextRow(row_flags, min_row_height);
}
constexpr auto ImNextColumn = ImGui::TableNextColumn;
#define ImSelectable ImGui::Selectable
} // namespace bookmouse
#endif
|