forked from AngelMonica126/GraphicAlgorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.cpp
545 lines (469 loc) · 17.4 KB
/
GUI.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
//--------------------------------------------------------------------------------------
// Copyright (c) Elay Pu. All rights reserved.
//--------------------------------------------------------------------------------------
#include "GUI.h"
#include <vector>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <imgui.h>
#include <examples/imgui_impl_glfw.h>
#include <examples/imgui_impl_opengl3.h>
#include "GLFWWindow.h"
#include "App.h"
#include "ResourceManager.h"
#include "MainGUI.h"
//using namespace ElayGraphics;
IGUI::IGUI()
{
}
IGUI::IGUI(const std::string& vName, int vExcutionOrder) : m_Name(vName), m_ExecutionOrder(vExcutionOrder)
{
}
IGUI::~IGUI()
{
}
//************************************************************************************
//Function:
bool IGUI::operator <(const IGUI& vOtherGUI) const
{
return m_ExecutionOrder < vOtherGUI.getExecutionOrder();
}
//************************************************************************************
//Function:
const std::shared_ptr<ImFont>& IGUI::getFontByName(const std::string& vFontName)
{
_ASSERT(m_FontMap.find(vFontName) != m_FontMap.end());
return m_FontMap[vFontName];
}
//************************************************************************************
//Function:
void IGUI::loadFont(const std::string& vFontFilePath, float vFontSize)
{
ImFontConfig IconsConfig;
IconsConfig.MergeMode = true;
auto pIO = CResourceManager::getOrCreateInstance()->getOrCreateMainGUI()->getIO();
auto pFont = std::shared_ptr<ImFont>(pIO->Fonts->AddFontFromFileTTF(vFontFilePath.c_str(), vFontSize));
_ASSERT(pFont);
pIO->Fonts->AddFontFromFileTTF("../Fonts/fontawesome-webfont.ttf", 16.0f, &IconsConfig, m_IconRanges.data());
std::vector<std::string> SplitedStringSet;
boost::split(SplitedStringSet, vFontFilePath, boost::is_any_of("/\\"));
std::string FontName = *(SplitedStringSet.end() - 1);
m_FontMap[FontName] = pFont;
}
//************************************************************************************
//Function:
void IGUI::pushFont(const std::shared_ptr<ImFont>& vFont)
{
ImGui::PushFont(vFont.get());
}
//************************************************************************************
//Function:
void IGUI::popFont()
{
ImGui::PopFont();
}
//************************************************************************************
//Function:
bool IGUI::combo(const std::string& vLabel, int &vioCurrentItem, const std::vector<std::string>& vItems)
{
std::vector<const char*> Items;
for (const auto &e : vItems)
Items.push_back(e.c_str());
return ImGui::Combo(vLabel.c_str(), &vioCurrentItem, Items.data(), static_cast<int>(vItems.size()));
}
//************************************************************************************
//Function:
void IGUI::text(const std::string& vText)
{
ImGui::Text(vText.c_str());
}
//************************************************************************************
//Function:
void IGUI::textDisabled(const std::string& vText)
{
ImGui::TextDisabled(vText.c_str());
}
//************************************************************************************
//Function:
void IGUI::textColored(const glm::vec4& vColor, const std::string& vText)
{
ImGui::TextColored(ImVec4(vColor[0], vColor[1], vColor[2], vColor[3]), vText.c_str());
}
//************************************************************************************
//Function:
void IGUI::bulletText(const std::string& vText)
{
ImGui::BulletText(vText.c_str());
}
//************************************************************************************
//Function:
bool IGUI::beginMenuBar()
{
return ImGui::BeginMenuBar();
}
//************************************************************************************
//Function:
void IGUI::endMenuBar()
{
ImGui::EndMenuBar();
}
//************************************************************************************
//Function:
bool IGUI::beginMenu(const std::string& vLable)
{
return ImGui::BeginMenu(vLable.c_str());
}
//************************************************************************************
//Function:
void IGUI::endMenu()
{
ImGui::EndMenu();
}
//************************************************************************************
//Function:
bool IGUI::menuItem(const std::string& vLabel)
{
return ImGui::MenuItem(vLabel.c_str());
}
//************************************************************************************
//Function:
bool IGUI::checkBox(const std::string& vLable, bool &voCheckValue)
{
return ImGui::Checkbox(vLable.c_str(), &voCheckValue);
}
//************************************************************************************
//Function:
void IGUI::verticalSpacing()
{
ImGui::Spacing();
}
//************************************************************************************
//Function:
bool IGUI::sliderScalar(const std::string& vLable, ElayGraphics::EDataType vDataType, void* vValue, const void* vMin, const void* vMax)
{
return ImGui::SliderScalar(vLable.c_str(), static_cast<int>(vDataType), vValue, vMin, vMax);
}
//************************************************************************************
//Function:
bool IGUI::sliderScalarN(const std::string& vLable, ElayGraphics::EDataType vDataType, int vComponentsNum, void* vValue, const void* vMin, const void* vMax)
{
return ImGui::SliderScalarN(vLable.c_str(), static_cast<int>(vDataType), vValue, vComponentsNum, vMin, vMax);
}
//************************************************************************************
//Function:
bool IGUI::sliderFloat4(const std::string& vLable, glm::vec4& vioValue, float vMin, float vMax)
{
float TmpData[4];
return ImGui::SliderFloat4(vLable.c_str(), TmpData, vMin, vMax);
vioValue = glm::vec4(TmpData[0], TmpData[1], TmpData[2], TmpData[3]);
}
//************************************************************************************
//Function:
bool IGUI::verticalSilderScalar(const std::string& vLable, const glm::vec2& vSliderSize, ElayGraphics::EDataType vDataType, void* vValue, const void* vMin, const void* vMax)
{
return ImGui::VSliderScalar(vLable.c_str(), ImVec2(vSliderSize[0], vSliderSize[1]), static_cast<int>(vDataType), vValue, vMin, vMax);
}
//************************************************************************************
//Function:
void IGUI::horizontalLine()
{
ImGui::Separator();
}
//************************************************************************************
//Function:
void IGUI::sameLine()
{
ImGui::SameLine();
}
//************************************************************************************
//Function:
bool IGUI::button(const std::string& vLable, const glm::vec2& vSize /* = glm::vec2(0) */)
{
return ImGui::Button(vLable.c_str(), ImVec2(vSize[0], vSize[1]));
}
//************************************************************************************
//Function:
bool IGUI::colorButton(const std::string& vLable, const glm::vec4& vColor, const glm::vec2& vSize)
{
return ImGui::ColorButton(vLable.c_str(), ImVec4(vColor[0], vColor[1], vColor[2], vColor[3]), 0, ImVec2(vSize[0], vSize[1]));
}
//************************************************************************************
//Function:
void IGUI::setColorPickerType(int vPickerType)
{
vPickerType ? ImGui::SetColorEditOptions(ImGuiColorEditFlags_PickerHueWheel) : ImGui::SetColorEditOptions(ImGuiColorEditFlags_PickerHueBar);
}
//************************************************************************************
//Function:
bool IGUI::colorEdit(const std::string& vLable, glm::vec4& voColor, bool vIsEditAlpha /* = true */)
{
ImGuiColorEditFlags Flags = 0;
if (!vIsEditAlpha)
Flags |= ImGuiColorEditFlags_NoAlpha;
return ImGui::ColorEdit4(vLable.c_str(), &voColor[0], Flags);
}
//************************************************************************************
//Function:
bool IGUI::collapsingHeader(const std::string& vLabel)
{
return ImGui::CollapsingHeader(vLabel.c_str());
}
//************************************************************************************
//Function:
bool IGUI::treeNode(const std::string& vLable)
{
return ImGui::TreeNode(vLable.c_str());
}
//************************************************************************************
//Function:
void IGUI::treePop()
{
ImGui::TreePop();
}
//************************************************************************************
//Function:
void IGUI::bullet()
{
ImGui::Bullet();
}
//************************************************************************************
//Function:
void IGUI::indent()
{
ImGui::Indent();
}
//************************************************************************************
//Function:
void IGUI::unIndent()
{
ImGui::Unindent();
}
//************************************************************************************
//Function:
bool IGUI::isLastItemHovered()
{
return ImGui::IsItemHovered();
}
//************************************************************************************
//Function:
void IGUI::beginTooltip()
{
return ImGui::BeginTooltip();
}
//************************************************************************************
//Function:
void IGUI::endTooltip()
{
ImGui::EndTooltip();
}
//************************************************************************************
//Function:
void IGUI::promptMarker(const std::string& vPromptMarker, const std::string& vPromptText)
{
ImGui::Text(vPromptMarker.c_str());
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text(vPromptText.c_str());
ImGui::EndTooltip();
}
}
//************************************************************************************
//Function:
bool IGUI::radioButton(const std::string& vLabel, int &voValue, int vButtonIndex)
{
return ImGui::RadioButton(vLabel.c_str(), &voValue, vButtonIndex);
}
//************************************************************************************
//Function:
void IGUI::plotLines(const std::string& vLabel, const std::vector<float> &vValueSet, float vMin, float vMax, const glm::vec2& vSize/* = glm::vec2(0)*/)
{
ImGui::PlotLines(vLabel.c_str(), vValueSet.data(), static_cast<int>(vValueSet.size()), 0, nullptr, vMin, vMax, ImVec2(vSize[0], vSize[1]));
}
//************************************************************************************
//Function:
void IGUI::plotLines(const std::string& vLabel, float(*Func)(void*, int), int vSampleCount, float vMin, float vMax, const glm::vec2& vSize/* = glm::vec2(0)*/)
{
ImGui::PlotLines(vLabel.c_str(), Func, nullptr, vSampleCount, 0, nullptr, vMin, vMax, ImVec2(vSize[0], vSize[1]));
}
//************************************************************************************
//Function:
void IGUI::plotHistogram(const std::string& vLable, const std::vector<float> &vValueSet, float vMin/* = MAX_VALUE*/, float vMax/* = MAX_VALUE*/, const glm::vec2& vSize/* = glm::vec2(0)*/)
{
ImGui::PlotHistogram(vLable.c_str(), vValueSet.data(), static_cast<int>(vValueSet.size()), 0, nullptr, vMin, vMax, ImVec2(vSize[0], vSize[1]));
}
//************************************************************************************
//Function:
void IGUI::plotHistogram(const std::string& vLabel, float(*Func)(void*, int), int vSampleCount, float vMin, float vMax, const glm::vec2& vSize/* = glm::vec2(0)*/)
{
ImGui::PlotHistogram(vLabel.c_str(), Func, nullptr, vSampleCount, 0, nullptr, vMin, vMax, ImVec2(vSize[0], vSize[1]));
}
//************************************************************************************
//Function:
void IGUI::processBar(float vProcessValue, const glm::vec2& vSize/* = glm::vec2(0, 1)*/)
{
ImGui::ProgressBar(vProcessValue, ImVec2(vSize[0], vSize[1]));
}
//************************************************************************************
//Function:
bool IGUI::inputText(const std::string& vLabel, std::string& voValue, size_t vValueBufferSize/* = 128*/, bool vIsPassword/* = false*/)
{
voValue.resize(vValueBufferSize);
ImGuiInputTextFlags Flags = 0;
if (vIsPassword)
Flags |= ImGuiInputTextFlags_Password;
return ImGui::InputText(vLabel.c_str(), &voValue[0], vValueBufferSize, Flags);
}
//************************************************************************************
//Function:
bool IGUI::inputInt(const std::string& vLabel, int &voValue)
{
return ImGui::InputInt(vLabel.c_str(), &voValue);
}
//************************************************************************************
//Function:
bool IGUI::inputFloat(const std::string& vLabel, float &voValue)
{
return ImGui::InputFloat(vLabel.c_str(), &voValue);
}
//************************************************************************************
//Function:
bool IGUI::inputDouble(const std::string& vLabel, double &voValue)
{
return ImGui::InputDouble(vLabel.c_str(), &voValue);
}
//************************************************************************************
//Function:
bool IGUI::inputFloat3(const std::string& vLabel, glm::vec3& voValue)
{
return ImGui::InputFloat3(vLabel.c_str(), &voValue[0]);
}
//************************************************************************************
//Function:
bool IGUI::inputFloat4(const std::string& vLabel, glm::vec4& voValue)
{
return ImGui::InputFloat4(vLabel.c_str(), &voValue[0]);
}
//************************************************************************************
//Function:
void IGUI::pushItemWidth(float vItemWidth)
{
ImGui::PushItemWidth(vItemWidth);
}
//************************************************************************************
//Function:
void IGUI::popItemWidth()
{
ImGui::PopItemWidth();
}
//************************************************************************************
//Function:
bool IGUI::dragScalar(const std::string& vLabel, ElayGraphics::EDataType vDataType, void* vValue, float vDragSpeed, const void* vMin, const void* vMax)
{
return ImGui::DragScalar(vLabel.c_str(), static_cast<int>(vDataType), vValue, vDragSpeed, vMin, vMax);
}
//************************************************************************************
//Function:
bool IGUI::dragScalarN(const std::string& vLabel, ElayGraphics::EDataType vDataType, void* vValue, int vComponentsNum, float vDragSpeed, const void* vMin, const void* vMax)
{
return ImGui::DragScalarN(vLabel.c_str(), static_cast<int>(vDataType), vValue, vComponentsNum, vDragSpeed, vMin, vMax);
}
//************************************************************************************
//Function:
bool IGUI::listBox(const std::string& vLabel, int &voCurrentItem, const std::vector<std::string>& vItems, int vDisplayedNumInBox/* = -1*/)
{
std::vector<const char*> Items;
for (const auto &e : vItems)
Items.push_back(e.c_str());
return ImGui::ListBox(vLabel.c_str(), &voCurrentItem, Items.data(), static_cast<int>(vItems.size()), vDisplayedNumInBox);
}
//************************************************************************************
//Function:
bool IGUI::beginChild(const std::string& vLabel, const glm::vec2& vSize /* = glm::vec2(0) */, bool vIsBorder /* = true */)
{
return ImGui::BeginChild(vLabel.c_str(), ImVec2(vSize[0], vSize[1]), vIsBorder);
}
//************************************************************************************
//Function:
void IGUI::endChild()
{
ImGui::EndChild();
}
//************************************************************************************
//Function:
void IGUI::columns(int vColNum, const std::string& vNameId /* = "" */, bool vIsBorder /* = true */)
{
ImGui::Columns(vColNum, vNameId.c_str(), vIsBorder);
}
//************************************************************************************
//Function:
void IGUI::nextColumn()
{
ImGui::NextColumn();
}
//************************************************************************************
//Function:
bool IGUI::begin(const std::string& vName)
{
return ImGui::Begin(vName.c_str());
}
//************************************************************************************
//Function:
bool IGUI::begin(const std::string &vName, bool &voIsOpen)
{
return ImGui::Begin(vName.c_str(), &voIsOpen);
}
//************************************************************************************
//Function:
void IGUI::end()
{
ImGui::End();
}
//************************************************************************************
//Function:
bool IGUI::beginPopupContextItem()
{
return ImGui::BeginPopupContextItem();
}
//************************************************************************************
//Function:
void IGUI::endPopup()
{
ImGui::EndPopup();
}
//************************************************************************************
//Function:
void IGUI::openPopup(const std::string& vNameId)
{
ImGui::OpenPopup(vNameId.c_str());
}
//************************************************************************************
//Function:
bool IGUI::beginPopup(const std::string& vNameId)
{
return ImGui::BeginPopup(vNameId.c_str());
}
//************************************************************************************
//Function:
bool IGUI::beginPopupModal(const std::string& vNameId)
{
return ImGui::BeginPopupModal(vNameId.c_str());
}
//************************************************************************************
//Function:
void IGUI::closeCurrentPopup()
{
ImGui::CloseCurrentPopup();
}
//************************************************************************************
//Function:
void IGUI::pushStyleColor(ElayGraphics::EGUIItemColor vItemColor, const glm::vec4& vColor)
{
ImGui::PushStyleColor(static_cast<int>(vItemColor), (ImVec4)ImColor::HSV(vColor[0], vColor[1], vColor[2], vColor[3]));
}
//************************************************************************************
//Function:
void IGUI::popStyleColor(int vPopCount/* = 1*/)
{
ImGui::PopStyleColor(vPopCount);
}