forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imguiWrapper.cpp
668 lines (541 loc) · 13.9 KB
/
imguiWrapper.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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
#include "imguiWrappedHeader.h"
#include "imguiWrapper.h"
#include "WrapperConverter.h"
IggContext iggCreateContext(IggFontAtlas sharedFontAtlas)
{
ImGuiContext *context = ImGui::CreateContext(reinterpret_cast<ImFontAtlas *>(sharedFontAtlas));
return reinterpret_cast<IggContext>(context);
}
void iggDestroyContext(IggContext context)
{
ImGui::DestroyContext(reinterpret_cast<ImGuiContext *>(context));
}
IggContext iggGetCurrentContext()
{
return reinterpret_cast<IggContext>(ImGui::GetCurrentContext());
}
void iggSetCurrentContext(IggContext context)
{
ImGui::SetCurrentContext(reinterpret_cast<ImGuiContext *>(context));
}
IggIO iggGetCurrentIO()
{
return reinterpret_cast<IggIO>(&ImGui::GetIO());
}
IggGuiStyle iggGetCurrentStyle()
{
return reinterpret_cast<IggGuiStyle>(&ImGui::GetStyle());
}
void iggNewFrame()
{
ImGui::NewFrame();
}
void iggRender()
{
ImGui::Render();
}
IggDrawData iggGetDrawData()
{
return reinterpret_cast<IggDrawData>(ImGui::GetDrawData());
}
void iggEndFrame()
{
ImGui::EndFrame();
}
char const *iggGetVersion()
{
return ImGui::GetVersion();
}
void iggShowDemoWindow(IggBool *open)
{
BoolWrapper openArg(open);
ImGui::ShowDemoWindow(openArg);
}
void iggShowUserGuide(void)
{
ImGui::ShowUserGuide();
}
IggBool iggBegin(char const *id, IggBool *open, int flags)
{
BoolWrapper openArg(open);
return ImGui::Begin(id, openArg, flags) ? 1 : 0;
}
void iggEnd(void)
{
ImGui::End();
}
IggBool iggBeginChild(char const *id, IggVec2 const *size, IggBool border, int flags)
{
Vec2Wrapper sizeArg(size);
return ImGui::BeginChild(id, *sizeArg, border, flags) ? 1 : 0;
}
void iggEndChild(void)
{
ImGui::EndChild();
}
void iggWindowPos(IggVec2 *pos)
{
exportValue(*pos, ImGui::GetWindowPos());
}
void iggWindowSize(IggVec2 *size)
{
exportValue(*size, ImGui::GetWindowSize());
}
float iggWindowWidth(void)
{
return ImGui::GetWindowWidth();
}
float iggWindowHeight(void)
{
return ImGui::GetWindowHeight();
}
void iggContentRegionAvail(IggVec2 *size)
{
exportValue(*size, ImGui::GetContentRegionAvail());
}
void iggSetNextWindowPos(IggVec2 const *pos, int cond, IggVec2 const *pivot)
{
Vec2Wrapper posArg(pos);
Vec2Wrapper pivotArg(pivot);
ImGui::SetNextWindowPos(*posArg, cond, *pivotArg);
}
void iggSetNextWindowSize(IggVec2 const *size, int cond)
{
Vec2Wrapper sizeArg(size);
ImGui::SetNextWindowSize(*sizeArg, cond);
}
void iggSetNextWindowFocus(void)
{
ImGui::SetNextWindowFocus();
}
void iggSetNextWindowBgAlpha(float value)
{
ImGui::SetNextWindowBgAlpha(value);
}
void iggPushFont(IggFont handle)
{
ImFont *font = reinterpret_cast<ImFont *>(handle);
ImGui::PushFont(font);
}
void iggPopFont(void)
{
ImGui::PopFont();
}
void iggPushStyleColor(int index, IggVec4 const *col)
{
Vec4Wrapper colArg(col);
ImGui::PushStyleColor(index, *colArg);
}
void iggPopStyleColor(int count)
{
ImGui::PopStyleColor(count);
}
void iggPushStyleVarFloat(int index, float value)
{
ImGui::PushStyleVar(index, value);
}
void iggPushStyleVarVec2(int index, IggVec2 const *value)
{
Vec2Wrapper valueArg(value);
ImGui::PushStyleVar(index, *valueArg);
}
void iggPopStyleVar(int count)
{
ImGui::PopStyleVar(count);
}
float iggGetFontSize()
{
return ImGui::GetFontSize();
}
void iggPushItemWidth(float width)
{
ImGui::PushItemWidth(width);
}
void iggPopItemWidth(void)
{
ImGui::PopItemWidth();
}
float iggCalcItemWidth(void)
{
return ImGui::CalcItemWidth();
}
void iggPushTextWrapPos(float wrapPosX)
{
ImGui::PushTextWrapPos(wrapPosX);
}
void iggPopTextWrapPos(void)
{
ImGui::PopTextWrapPos();
}
void iggPushID(char const *id)
{
ImGui::PushID(id);
}
void iggPopID(void)
{
ImGui::PopID();
}
void iggTextUnformatted(char const *text)
{
ImGui::TextUnformatted(text);
}
void iggLabelText(char const *label, char const *text)
{
ImGui::LabelText(label, "%s", text);
}
IggBool iggButton(char const *label, IggVec2 const *size)
{
Vec2Wrapper sizeArg(size);
return ImGui::Button(label, *sizeArg) ? 1 : 0;
}
void iggImage(IggTextureID textureID,
IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1,
IggVec4 const *tintCol, IggVec4 const *borderCol)
{
Vec2Wrapper sizeArg(size);
Vec2Wrapper uv0Arg(uv0);
Vec2Wrapper uv1Arg(uv1);
Vec4Wrapper tintColArg(tintCol);
Vec4Wrapper borderColArg(borderCol);
ImGui::Image(static_cast<ImTextureID>(textureID), *sizeArg, *uv0Arg, *uv1Arg, *tintColArg, *borderColArg);
}
IggBool iggImageButton(IggTextureID textureID,
IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1,
int framePadding, IggVec4 const *bgCol,
IggVec4 const *tintCol)
{
Vec2Wrapper sizeArg(size);
Vec2Wrapper uv0Arg(uv0);
Vec2Wrapper uv1Arg(uv1);
Vec4Wrapper bgColArg(bgCol);
Vec4Wrapper tintColArg(tintCol);
return ImGui::ImageButton(static_cast<ImTextureID>(textureID), *sizeArg, *uv0Arg, *uv1Arg, framePadding, *bgColArg, *tintColArg) ? 1 : 0;
}
IggBool iggCheckbox(char const *label, IggBool *selected)
{
BoolWrapper selectedArg(selected);
return ImGui::Checkbox(label, selectedArg) ? 1 : 0;
}
void iggProgressBar(float fraction, IggVec2 const *size, char const *overlay)
{
Vec2Wrapper sizeArg(size);
ImGui::ProgressBar(fraction, *sizeArg, overlay);
}
IggBool iggBeginCombo(char const *label, char const *previewValue, int flags)
{
return ImGui::BeginCombo(label, previewValue, flags) ? 1 : 0;
}
void iggEndCombo(void)
{
ImGui::EndCombo();
}
IggBool iggDragFloat(char const *label, float *value, float speed, float min, float max, char const *format, float power)
{
return ImGui::DragFloat(label, value, speed, min, max, format, power) ? 1 : 0;
}
IggBool iggDragInt(char const *label, int *value, float speed, int min, int max, char const *format)
{
return ImGui::DragInt(label, value, speed, min, max, format) ? 1 : 0;
}
IggBool iggSliderFloat(char const *label, float *value, float minValue, float maxValue, char const *format, float power)
{
return ImGui::SliderFloat(label, value, minValue, maxValue, format, power) ? 1 : 0;
}
IggBool iggSliderFloatN(char const *label, float *value, int n, float minValue, float maxValue, char const *format, float power)
{
return ImGui::SliderScalarN(label, ImGuiDataType_Float, (void *)value, n, &minValue, &maxValue, format, power) ? 1 : 0;
}
IggBool iggSliderInt(char const *label, int *value, int minValue, int maxValue, char const *format)
{
return ImGui::SliderInt(label, value, minValue, maxValue, format) ? 1 : 0;
}
extern "C" int iggInputTextCallback(IggInputTextCallbackData data, int key);
static int iggInputTextCallbackWrapper(ImGuiInputTextCallbackData *data)
{
return iggInputTextCallback(reinterpret_cast<IggInputTextCallbackData>(data), static_cast<int>(reinterpret_cast<size_t>(data->UserData)));
}
IggBool iggInputText(char const *label, char* buf, unsigned int bufSize, int flags, int callbackKey)
{
return ImGui::InputText(label, buf, static_cast<size_t>(bufSize), flags,
iggInputTextCallbackWrapper, reinterpret_cast<void *>(callbackKey)) ? 1 : 0;
}
IggBool iggInputTextMultiline(char const *label, char* buf, unsigned int bufSize, IggVec2 const *size, int flags, int callbackKey)
{
Vec2Wrapper sizeArg(size);
return ImGui::InputTextMultiline(label, buf, static_cast<size_t>(bufSize), *sizeArg, flags,
iggInputTextCallbackWrapper, reinterpret_cast<void *>(callbackKey)) ? 1 : 0;
}
void iggSeparator(void)
{
ImGui::Separator();
}
void iggSameLine(float posX, float spacingW)
{
ImGui::SameLine(posX, spacingW);
}
void iggSpacing(void)
{
ImGui::Spacing();
}
void iggDummy(IggVec2 const *size)
{
Vec2Wrapper sizeArg(size);
ImGui::Dummy(*sizeArg);
}
void iggBeginGroup(void)
{
ImGui::BeginGroup();
}
void iggEndGroup(void)
{
ImGui::EndGroup();
}
void iggCursorPos(IggVec2 *pos)
{
exportValue(*pos, ImGui::GetCursorPos());
}
float iggCursorPosX(void)
{
return ImGui::GetCursorPosX();
}
float iggCursorPosY(void)
{
return ImGui::GetCursorPosY();
}
void iggCursorStartPos(IggVec2 *pos)
{
exportValue(*pos, ImGui::GetCursorStartPos());
}
void iggCursorScreenPos(IggVec2 *pos)
{
exportValue(*pos, ImGui::GetCursorScreenPos());
}
void iggSetCursorPos(IggVec2 const *localPos)
{
Vec2Wrapper localPosArg(localPos);
ImGui::SetCursorPos(*localPosArg);
}
void iggSetCursorScreenPos(IggVec2 const *absPos)
{
Vec2Wrapper absPosArg(absPos);
ImGui::SetCursorScreenPos(*absPosArg);
}
void iggAlignTextToFramePadding()
{
ImGui::AlignTextToFramePadding();
}
float iggGetTextLineHeight(void)
{
return ImGui::GetTextLineHeight();
}
float iggGetTextLineHeightWithSpacing(void)
{
return ImGui::GetTextLineHeightWithSpacing();
}
IggBool iggTreeNode(char const *label, int flags)
{
return ImGui::TreeNodeEx(label, flags) ? 1 : 0;
}
void iggTreePop(void)
{
ImGui::TreePop();
}
void iggSetNextItemOpen(IggBool open, int cond)
{
ImGui::SetNextItemOpen(open != 0, cond);
}
float iggGetTreeNodeToLabelSpacing(void)
{
return ImGui::GetTreeNodeToLabelSpacing();
}
IggBool iggSelectable(char const *label, IggBool selected, int flags, IggVec2 const *size)
{
Vec2Wrapper sizeArg(size);
return ImGui::Selectable(label, selected != 0, flags, *sizeArg) ? 1 : 0;
}
IggBool iggListBoxV(char const *label, int *currentItem, char const *const items[], int itemsCount, int heightItems)
{
return ImGui::ListBox(label, currentItem, items, itemsCount, heightItems) ? 1 : 0;
}
void iggPlotLines(char const *label, float const *values, int valuesCount, int valuesOffset, char const *overlayText, float scaleMin, float scaleMax, IggVec2 const *graphSize)
{
Vec2Wrapper graphSizeArg(graphSize);
ImGui::PlotLines(label, values, valuesCount, valuesOffset, overlayText, scaleMin, scaleMax, *graphSizeArg);
}
void iggPlotHistogram(char const *label, float const *values, int valuesCount, int valuesOffset, char const *overlayText, float scaleMin, float scaleMax, IggVec2 const *graphSize)
{
Vec2Wrapper graphSizeArg(graphSize);
ImGui::PlotHistogram(label, values, valuesCount, valuesOffset, overlayText, scaleMin, scaleMax, *graphSizeArg);
}
void iggSetTooltip(char const *text)
{
ImGui::SetTooltip("%s", text);
}
void iggBeginTooltip(void)
{
ImGui::BeginTooltip();
}
void iggEndTooltip(void)
{
ImGui::EndTooltip();
}
IggBool iggBeginMainMenuBar(void)
{
return ImGui::BeginMainMenuBar() ? 1 : 0;
}
void iggEndMainMenuBar(void)
{
ImGui::EndMainMenuBar();
}
IggBool iggBeginMenuBar(void)
{
return ImGui::BeginMenuBar() ? 1 : 0;
}
void iggEndMenuBar(void)
{
ImGui::EndMenuBar();
}
IggBool iggBeginMenu(char const *label, IggBool enabled)
{
return ImGui::BeginMenu(label, enabled != 0) ? 1 : 0;
}
void iggEndMenu(void)
{
ImGui::EndMenu();
}
IggBool iggMenuItem(char const *label, char const *shortcut, IggBool selected, IggBool enabled)
{
return ImGui::MenuItem(label, shortcut, selected != 0, enabled != 0) ? 1 : 0;
}
void iggOpenPopup(char const *id)
{
ImGui::OpenPopup(id);
}
IggBool iggBeginPopupModal(char const *name, IggBool *open, int flags)
{
BoolWrapper openArg(open);
return ImGui::BeginPopupModal(name, openArg, flags) ? 1 : 0;
}
IggBool iggBeginPopupContextItem(char const *label, int mouseButton)
{
return ImGui::BeginPopupContextItem(label, mouseButton) ? 1 : 0;
}
void iggEndPopup(void)
{
ImGui::EndPopup();
}
void iggCloseCurrentPopup(void)
{
ImGui::CloseCurrentPopup();
}
IggBool iggIsItemHovered(int flags)
{
return ImGui::IsItemHovered(flags) ? 1 : 0;
}
IggBool iggIsKeyDown(int key)
{
return ImGui::IsKeyDown(key);
}
IggBool iggIsKeyPressed(int key, IggBool repeat)
{
return ImGui::IsKeyPressed(key, repeat);
}
IggBool iggIsKeyReleased(int key)
{
return ImGui::IsKeyReleased(key);
}
IggBool iggIsMouseDown(int button)
{
return ImGui::IsMouseDown(button);
}
IggBool iggIsAnyMouseDown()
{
return ImGui::IsAnyMouseDown();
}
IggBool iggIsMouseClicked(int button, IggBool repeat)
{
return ImGui::IsMouseClicked(button, repeat);
}
IggBool iggIsMouseReleased(int button)
{
return ImGui::IsMouseReleased(button);
}
IggBool iggIsMouseDoubleClicked(int button)
{
return ImGui::IsMouseDoubleClicked(button);
}
void iggColumns(int count, char const *label, IggBool border)
{
ImGui::Columns(count, label, border);
}
void iggNextColumn()
{
ImGui::NextColumn();
}
int iggGetColumnIndex()
{
return ImGui::GetColumnIndex();
}
int iggGetColumnWidth(int index)
{
return ImGui::GetColumnWidth(index);
}
void iggSetColumnWidth(int index, float width)
{
ImGui::SetColumnWidth(index, width);
}
float iggGetColumnOffset(int index)
{
return ImGui::GetColumnOffset(index);
}
void iggSetColumnOffset(int index, float offsetX)
{
ImGui::SetColumnOffset(index, offsetX);
}
int iggGetColumnsCount()
{
return ImGui::GetColumnsCount();
}
void iggSetScrollHereY(float centerYRatio)
{
ImGui::SetScrollHereY(centerYRatio);
}
void iggSetItemDefaultFocus()
{
ImGui::SetItemDefaultFocus();
}
IggBool iggIsItemFocused()
{
return ImGui::IsItemFocused();
}
IggBool iggIsAnyItemFocused()
{
return ImGui::IsAnyItemFocused();
}
int iggGetMouseCursor()
{
return ImGui::GetMouseCursor();
}
void iggSetMouseCursor(int cursor)
{
ImGui::SetMouseCursor(cursor);
}
IggBool iggBeginTabBar(char const *str_id, int flags) {
return ImGui::BeginTabBar(str_id, flags) ? 1 : 0;
}
void iggEndTabBar() {
ImGui::EndTabBar();
}
IggBool iggBeginTabItem(char const *label, IggBool *p_open, int flags) {
BoolWrapper openArg(p_open);
return ImGui::BeginTabItem(label, openArg, flags) ? 1 : 0;
}
void iggEndTabItem() {
ImGui::EndTabItem();
}
void iggSetTabItemClosed(char const * tab_or_docked_window_label) {
ImGui::SetTabItemClosed(tab_or_docked_window_label);
}
void iggCalcTextSize(const char* text, const char* text_end, IggBool hide_text_after_double_hash, float wrap_width, IggVec2 *size) {
exportValue(*size, ImGui::CalcTextSize(text, text_end, hide_text_after_double_hash, wrap_width));
}