forked from KhronosGroup/Vulkan-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawer.cpp
169 lines (148 loc) · 3.59 KB
/
drawer.cpp
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* Copyright (c) 2024, Mobica Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "drawer.h"
namespace vkb
{
void Drawer::clear()
{
dirty = false;
}
bool Drawer::is_dirty()
{
return dirty;
}
void Drawer::set_dirty(bool dirty)
{
this->dirty = dirty;
}
bool Drawer::header(const char *caption)
{
return ImGui::CollapsingHeader(caption, ImGuiTreeNodeFlags_DefaultOpen);
}
bool Drawer::checkbox(const char *caption, bool *value)
{
bool res = ImGui::Checkbox(caption, value);
if (res)
{
dirty = true;
};
return res;
}
bool Drawer::checkbox(const char *caption, int32_t *value)
{
bool val = (*value == 1);
bool res = ImGui::Checkbox(caption, &val);
*value = val;
if (res)
{
dirty = true;
};
return res;
}
bool Drawer::radio_button(const char *caption, int32_t *selectedOption, const int32_t elementOption)
{
bool res = ImGui::RadioButton(caption, selectedOption, elementOption);
if (res)
{
dirty = true;
}
return res;
}
bool Drawer::input_float(const char *caption, float *value, float step, const char *precision)
{
bool res = ImGui::InputFloat(caption, value, step, step * 10.0f, precision);
if (res)
{
dirty = true;
};
return res;
}
bool Drawer::slider_float(const char *caption, float *value, float min, float max)
{
bool res = ImGui::SliderFloat(caption, value, min, max);
if (res)
{
dirty = true;
};
return res;
}
bool Drawer::slider_int(const char *caption, int32_t *value, int32_t min, int32_t max)
{
bool res = ImGui::SliderInt(caption, value, min, max);
if (res)
{
dirty = true;
};
return res;
}
bool Drawer::combo_box(const char *caption, int32_t *itemindex, std::vector<std::string> items)
{
if (items.empty())
{
return false;
}
std::vector<const char *> charitems;
charitems.reserve(items.size());
for (size_t i = 0; i < items.size(); i++)
{
charitems.push_back(items[i].c_str());
}
uint32_t itemCount = static_cast<uint32_t>(charitems.size());
bool res = ImGui::Combo(caption, itemindex, &charitems[0], itemCount, itemCount);
if (res)
{
dirty = true;
};
return res;
}
bool Drawer::button(const char *caption)
{
bool res = ImGui::Button(caption);
if (res)
{
dirty = true;
};
return res;
}
void Drawer::text(const char *formatstr, ...)
{
va_list args;
va_start(args, formatstr);
ImGui::TextV(formatstr, args);
va_end(args);
}
template <>
bool Drawer::color_op_impl<Drawer::ColorOp::Edit, 3>(const char *caption, float *colors, ImGuiColorEditFlags flags)
{
return ImGui::ColorEdit3(caption, colors, flags);
}
template <>
bool Drawer::color_op_impl<Drawer::ColorOp::Edit, 4>(const char *caption, float *colors, ImGuiColorEditFlags flags)
{
return ImGui::ColorEdit4(caption, colors, flags);
}
template <>
bool Drawer::color_op_impl<Drawer::ColorOp::Pick, 3>(const char *caption, float *colors, ImGuiColorEditFlags flags)
{
return ImGui::ColorPicker3(caption, colors, flags);
}
template <>
bool Drawer::color_op_impl<Drawer::ColorOp::Pick, 4>(const char *caption, float *colors, ImGuiColorEditFlags flags)
{
return ImGui::ColorPicker4(caption, colors, flags);
}
} // namespace vkb