forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 15
/
WrapperConverter.h
51 lines (40 loc) · 1.41 KB
/
WrapperConverter.h
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
#pragma once
#include "imgui.h"
#include "imguiWrapperTypes.h"
extern void importValue(bool &out, IggBool const &in);
extern void exportValue(IggBool &out, bool const &in);
extern void importValue(float &out, IggFloat const &in);
extern void exportValue(IggFloat &out, float const &in);
extern void importValue(ImVec2 &out, IggVec2 const &in);
extern void exportValue(IggVec2 &out, ImVec2 const &in);
extern void importValue(ImVec4 &out, IggVec4 const &in);
extern void exportValue(IggVec4 &out, ImVec4 const &in);
template <typename ImGuiType, typename IggType> class TypeWrapper {
public:
TypeWrapper(IggType *iggValue) : iggValue(iggValue), imguiValue(nullptr) {
if (iggValue != nullptr) {
imguiValue = &imguiBuffer;
importValue(*imguiValue, *iggValue);
}
}
TypeWrapper(IggType const *constIggValue) : iggValue(nullptr), imguiValue(nullptr) {
if (constIggValue != nullptr) {
imguiValue = &imguiBuffer;
importValue(*imguiValue, *constIggValue);
}
}
~TypeWrapper() {
if (iggValue != nullptr) {
exportValue(*iggValue, *imguiValue);
}
}
operator ImGuiType *() { return imguiValue; }
private:
IggType *iggValue;
ImGuiType *imguiValue;
ImGuiType imguiBuffer;
};
typedef TypeWrapper<float, IggFloat> FloatWrapper;
typedef TypeWrapper<bool, IggBool> BoolWrapper;
typedef TypeWrapper<ImVec2, IggVec2> Vec2Wrapper;
typedef TypeWrapper<ImVec4, IggVec4> Vec4Wrapper;