-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgpulib_imgui.h
executable file
·601 lines (540 loc) · 24.5 KB
/
gpulib_imgui.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
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
#pragma once
#ifndef SDL_MAIN_HANDLED
#define SDL_MAIN_HANDLED 1
#endif
#include "opengl_functions.h"
#include "imgui/cimgui.h"
#include <SDL2/SDL.h>
struct ImVec2 {
float x, y;
};
struct ImVec3 {
float x, y, z;
};
struct ImVec4 {
float x, y, z, w;
};
struct ImGuiIO {
struct ImVec2 DisplaySize;
float DeltaTime;
float IniSavingRate;
char * IniFilename;
char * LogFilename;
float MouseDoubleClickTime;
float MouseDoubleClickMaxDist;
float MouseDragThreshold;
int KeyMap[19];
float KeyRepeatDelay;
float KeyRepeatRate;
void * UserData;
struct ImFontAtlas * Fonts;
float FontGlobalScale;
bool FontAllowUserScaling;
struct ImVec2 DisplayFramebufferScale;
struct ImVec2 DisplayVisibleMin;
struct ImVec2 DisplayVisibleMax;
bool OSXBehaviors;
void (*RenderDrawListsFn)(struct ImDrawData * data);
char * (*GetClipboardTextFn)();
void (*SetClipboardTextFn)(char * text);
void * (*MemAllocFn)(size_t sz);
void (*MemFreeFn)(void * ptr);
void (*ImeSetInputScreenPosFn)(int x, int y);
void * ImeWindowHandle;
struct ImVec2 MousePos;
bool MouseDown[5];
float MouseWheel;
bool MouseDrawCursor;
bool KeyCtrl;
bool KeyShift;
bool KeyAlt;
bool KeySuper;
bool KeysDown[512];
unsigned short InputCharacters[17];
bool WantCaptureMouse;
bool WantCaptureKeyboard;
bool WantTextInput;
float Framerate;
int MetricsAllocs;
int MetricsRenderVertices;
int MetricsRenderIndices;
int MetricsActiveWindows;
struct ImVec2 MousePosPrev;
struct ImVec2 MouseDelta;
bool MouseClicked[5];
struct ImVec2 MouseClickedPos[5];
float MouseClickedTime[5];
bool MouseDoubleClicked[5];
bool MouseReleased[5];
bool MouseDownOwned[5];
float MouseDownDuration[5];
float MouseDownDurationPrev[5];
float MouseDragMaxDistanceSqr[5];
float KeysDownDuration[512];
float KeysDownDurationPrev[512];
};
struct ImDrawData {
bool Valid;
struct ImDrawList ** CmdLists;
int CmdListsCount;
int TotalVtxCount;
int TotalIdxCount;
};
struct ImDrawCmd {
int ElemCount;
struct ImVec4 ClipRect;
ImTextureID TextureId;
ImDrawCallback UserCallback;
void * UserCallbackData;
};
typedef struct {
struct ImVec2 pos;
struct ImVec2 uv;
unsigned col;
} ImDrawVtx;
enum ImGuiKey {
ImGuiKey_Tab,
ImGuiKey_LeftArrow,
ImGuiKey_RightArrow,
ImGuiKey_UpArrow,
ImGuiKey_DownArrow,
ImGuiKey_PageUp,
ImGuiKey_PageDown,
ImGuiKey_Home,
ImGuiKey_End,
ImGuiKey_Delete,
ImGuiKey_Backspace,
ImGuiKey_Enter,
ImGuiKey_Escape,
ImGuiKey_A,
ImGuiKey_C,
ImGuiKey_V,
ImGuiKey_X,
ImGuiKey_Y,
ImGuiKey_Z,
ImGuiKey_COUNT
};
enum ImGuiCol {
ImGuiCol_Text,
ImGuiCol_TextDisabled,
ImGuiCol_WindowBg,
ImGuiCol_ChildWindowBg,
ImGuiCol_PopupBg,
ImGuiCol_Border,
ImGuiCol_BorderShadow,
ImGuiCol_FrameBg,
ImGuiCol_FrameBgHovered,
ImGuiCol_FrameBgActive,
ImGuiCol_TitleBg,
ImGuiCol_TitleBgCollapsed,
ImGuiCol_TitleBgActive,
ImGuiCol_MenuBarBg,
ImGuiCol_ScrollbarBg,
ImGuiCol_ScrollbarGrab,
ImGuiCol_ScrollbarGrabHovered,
ImGuiCol_ScrollbarGrabActive,
ImGuiCol_ComboBg,
ImGuiCol_CheckMark,
ImGuiCol_SliderGrab,
ImGuiCol_SliderGrabActive,
ImGuiCol_Button,
ImGuiCol_ButtonHovered,
ImGuiCol_ButtonActive,
ImGuiCol_Header,
ImGuiCol_HeaderHovered,
ImGuiCol_HeaderActive,
ImGuiCol_Column,
ImGuiCol_ColumnHovered,
ImGuiCol_ColumnActive,
ImGuiCol_ResizeGrip,
ImGuiCol_ResizeGripHovered,
ImGuiCol_ResizeGripActive,
ImGuiCol_CloseButton,
ImGuiCol_CloseButtonHovered,
ImGuiCol_CloseButtonActive,
ImGuiCol_PlotLines,
ImGuiCol_PlotLinesHovered,
ImGuiCol_PlotHistogram,
ImGuiCol_PlotHistogramHovered,
ImGuiCol_TextSelectedBg,
ImGuiCol_ModalWindowDarkening,
ImGuiCol_COUNT
};
struct ImGuiStyle {
float Alpha;
struct ImVec2 WindowPadding;
struct ImVec2 WindowMinSize;
float WindowRounding;
struct ImVec2 WindowTitleAlign;
float ChildWindowRounding;
struct ImVec2 FramePadding;
float FrameRounding;
struct ImVec2 ItemSpacing;
struct ImVec2 ItemInnerSpacing;
struct ImVec2 TouchExtraPadding;
float IndentSpacing;
float ColumnsMinSpacing;
float ScrollbarSize;
float ScrollbarRounding;
float GrabMinSize;
float GrabRounding;
struct ImVec2 ButtonTextAlign;
struct ImVec2 DisplayWindowPadding;
struct ImVec2 DisplaySafeAreaPadding;
bool AntiAliasedLines;
bool AntiAliasedShapes;
float CurveTessellationTol;
struct ImVec4 Colors[43];
};
static double g_time = 0;
static float g_mouse_wheel = 0;
static bool g_is_mouse_pressed[3] = {0};
static unsigned g_font_texture = 0, g_ppo = 0, g_vert = 0, g_frag = 0;
static void imgui_render_draw_list(struct ImDrawData * draw_data) {
struct ImGuiIO * io = igGetIO();
struct ImVec2 fb_scale = io->DisplayFramebufferScale;
int w = (int)(io->DisplaySize.x * fb_scale.x);
int h = (int)(io->DisplaySize.y * fb_scale.y);
ImDrawData_ScaleClipRects(draw_data, fb_scale);
glViewport(0, 0, w, h);
glDisable(0x0B44); // GL_CULL_FACE
glDisable(0x0B71); // GL_DEPTH_TEST
glEnable(0x0C11); // GL_SCISSOR_TEST
glDisable(0x8DB9); // GL_FRAMEBUFFER_SRGB
float scale[2] = {0}, translate[2] = {0};
scale[0] = 2.0 / w;
scale[1] = 2.0 / -h;
translate[0] = -1.0;
translate[1] = 1.0;
glProgramUniform2fv(g_vert, 0, 1, scale);
glProgramUniform2fv(g_vert, 1, 1, translate);
glBindProgramPipeline(g_ppo);
ptrdiff_t idx_bytes = draw_data->TotalIdxCount * (ptrdiff_t)sizeof(ImDrawIdx);
ptrdiff_t vtx_bytes = draw_data->TotalVtxCount * (ptrdiff_t)sizeof(ImDrawVtx);
unsigned idx_mem_id = 0;
unsigned vtx_mem_id = 0;
glCreateBuffers(1, &idx_mem_id);
glCreateBuffers(1, &vtx_mem_id);
glNamedBufferStorage(idx_mem_id, idx_bytes, 0, 194);
glNamedBufferStorage(vtx_mem_id, vtx_bytes, 0, 194);
void * idx = glMapNamedBufferRange(idx_mem_id, 0, idx_bytes, 194);
void * vtx = glMapNamedBufferRange(vtx_mem_id, 0, vtx_bytes, 194);
unsigned idx_tex_id = 0;
unsigned vtx_f32_tex_id = 0;
unsigned vtx_u32_tex_id = 0;
glCreateTextures(35882, 1, &idx_tex_id);
glCreateTextures(35882, 1, &vtx_f32_tex_id);
glCreateTextures(35882, 1, &vtx_u32_tex_id);
glTextureBufferRange(idx_tex_id, 0x8234, idx_mem_id, 0, idx_bytes); // GL_R16UI
glTextureBufferRange(vtx_f32_tex_id, 0x822E, vtx_mem_id, 0, vtx_bytes); // GL_R32F
glTextureBufferRange(vtx_u32_tex_id, 0x8236, vtx_mem_id, 0, vtx_bytes); // GL_R32UI
ImDrawIdx * idx_dest = idx;
ImDrawVtx * vtx_dest = vtx;
for (ptrdiff_t i = 0, c = draw_data->CmdListsCount; i < c; i += 1) {
struct ImDrawList * cmd_list = draw_data->CmdLists[i];
int idx_size = ImDrawList_GetIndexBufferSize(cmd_list);
int vtx_size = ImDrawList_GetVertexBufferSize(cmd_list);
SDL_memcpy(idx_dest, ImDrawList_GetIndexPtr(cmd_list, 0), (size_t)idx_size * sizeof(ImDrawIdx));
SDL_memcpy(vtx_dest, ImDrawList_GetVertexPtr(cmd_list, 0), (size_t)vtx_size * sizeof(ImDrawVtx));
idx_dest += idx_size;
vtx_dest += vtx_size;
}
unsigned input[4] = {0};
input[0] = 0;
input[1] = vtx_f32_tex_id;
input[2] = vtx_u32_tex_id;
input[3] = idx_tex_id;
int idx_offset = 0;
int vtx_offset = 0;
for (ptrdiff_t i = 0, c = draw_data->CmdListsCount; i < c; i += 1) {
struct ImDrawList * cmd_list = draw_data->CmdLists[i];
for (ptrdiff_t j = 0, c = ImDrawList_GetCmdSize(cmd_list); j < c; j += 1) {
struct ImDrawCmd * pcmd = ImDrawList_GetCmdPtr(cmd_list, (int)j);
if (pcmd->UserCallback) {
pcmd->UserCallback(cmd_list, pcmd);
} else {
glScissor((int)(pcmd->ClipRect.x),
(int)(h - pcmd->ClipRect.w),
(int)(pcmd->ClipRect.z - pcmd->ClipRect.x),
(int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
glProgramUniform1iv(g_vert, 2, 1, &vtx_offset);
input[0] = *(unsigned *)pcmd->TextureId;
glBindTextures(0, 4, input);
glDrawArraysInstanced(0x0004, idx_offset, pcmd->ElemCount, 1); // GL_TRIANGLES
}
idx_offset += pcmd->ElemCount;
}
vtx_offset += ImDrawList_GetVertexBufferSize(cmd_list);
}
glDeleteBuffers(1, &idx_mem_id);
glDeleteBuffers(1, &vtx_mem_id);
glDeleteTextures(1, &idx_tex_id);
glDeleteTextures(1, &vtx_f32_tex_id);
glDeleteTextures(1, &vtx_u32_tex_id);
glEnable(0x8DB9); // GL_FRAMEBUFFER_SRGB
glDisable(0x0C11); // GL_SCISSOR_TEST
glEnable(0x0B71); // GL_DEPTH_TEST
glEnable(0x0B44); // GL_CULL_FACE
}
static char * imgui_get_clipboard_text() {
return SDL_GetClipboardText();
}
static void imgui_set_clipboard_text(char * text) {
SDL_SetClipboardText(text);
}
bool imgui_process_event(SDL_Event * event) {
struct ImGuiIO * io = igGetIO();
switch (event->type) {
break; case (SDL_MOUSEWHEEL): {
if (event->wheel.y > 0) g_mouse_wheel = 1;
if (event->wheel.y < 0) g_mouse_wheel = -1;
return true;
}
break; case (SDL_MOUSEBUTTONDOWN): {
if (event->button.button == SDL_BUTTON_LEFT) g_is_mouse_pressed[0] = true;
if (event->button.button == SDL_BUTTON_RIGHT) g_is_mouse_pressed[1] = true;
if (event->button.button == SDL_BUTTON_MIDDLE) g_is_mouse_pressed[2] = true;
return true;
}
break; case (SDL_TEXTINPUT): {
ImGuiIO_AddInputCharactersUTF8(event->text.text);
return true;
}
break; case (SDL_KEYDOWN): {
int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK;
io->KeysDown[key] = true;
io->KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
io->KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
io->KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
io->KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
return true;
}
break; case (SDL_KEYUP): {
int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK;
io->KeysDown[key] = false;
io->KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
io->KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
io->KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
io->KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
return true;
}
}
return false;
}
void imgui_create_font_texture() {
struct ImGuiIO * io = igGetIO();
unsigned char * pixels = NULL;
int width = 0, height = 0, bpp = 0;
ImFontAtlas_GetTexDataAsRGBA32(io->Fonts, &pixels, &width, &height, &bpp);
glCreateTextures(35866, 1, &g_font_texture);
glTextureStorage3D(g_font_texture, 1, 0x8814, width, height, 1); // GL_RGBA32F
glTextureSubImage3D(g_font_texture, 0, 0, 0, 0, width, height, 1, 0x1908, 0x1401, pixels); // GL_RGBA, GL_UNSIGNED_BYTE
ImFontAtlas_SetTexID(io->Fonts, &g_font_texture);
}
void imgui_create_device_objects() {
char * vert_string =
"#version 330 \n"
"#extension GL_ARB_gpu_shader5 : enable \n"
"#extension GL_ARB_gpu_shader_fp64 : enable \n"
"#extension GL_ARB_shader_precision : enable \n"
"#extension GL_ARB_texture_cube_map_array : enable \n"
"#extension GL_ARB_separate_shader_objects : enable \n"
"#extension GL_ARB_shading_language_420pack : enable \n"
"#extension GL_ARB_shading_language_packing : enable \n"
"#extension GL_ARB_explicit_uniform_location : enable \n"
"out gl_PerVertex { vec4 gl_Position; }; \n"
" \n"
" layout(location = 0) uniform vec2 scale; \n"
" layout(location = 1) uniform vec2 translate; \n"
" layout(location = 2) uniform int vtx_offset; \n"
" \n"
" layout(binding = 1) uniform samplerBuffer s_vtx_f32; \n"
" layout(binding = 2) uniform usamplerBuffer s_vtx_u32; \n"
" layout(binding = 3) uniform isamplerBuffer s_idx; \n"
" \n"
" layout(location = 0) out vec2 fs_uv; \n"
" layout(location = 1) out vec4 fs_col; \n"
" \n"
" void main() { \n"
" int i = texelFetch(s_idx, gl_VertexID).x; \n"
" float posx = texelFetch(s_vtx_f32, (vtx_offset + i) * 5 + 0).x; \n"
" float posy = texelFetch(s_vtx_f32, (vtx_offset + i) * 5 + 1).x; \n"
" float uvx = texelFetch(s_vtx_f32, (vtx_offset + i) * 5 + 2).x; \n"
" float uvy = texelFetch(s_vtx_f32, (vtx_offset + i) * 5 + 3).x; \n"
" uint col = texelFetch(s_vtx_u32, (vtx_offset + i) * 5 + 4).x; \n"
" fs_uv = vec2(uvx, uvy); \n"
" fs_col = unpackUnorm4x8(col); \n"
" gl_Position = vec4(fma(vec2(posx, posy), scale, translate), 0, 1); \n"
" } \n";
char * frag_string =
"#version 330 \n"
"#extension GL_ARB_gpu_shader5 : enable \n"
"#extension GL_ARB_gpu_shader_fp64 : enable \n"
"#extension GL_ARB_shader_precision : enable \n"
"#extension GL_ARB_texture_cube_map_array : enable \n"
"#extension GL_ARB_separate_shader_objects : enable \n"
"#extension GL_ARB_shading_language_420pack : enable \n"
"#extension GL_ARB_shading_language_packing : enable \n"
"#extension GL_ARB_explicit_uniform_location : enable \n"
" \n"
" layout(binding = 0) uniform sampler2DArray s_texture; \n"
" \n"
" layout(location = 0) in vec2 fs_uv; \n"
" layout(location = 1) in vec4 fs_col; \n"
" \n"
" layout(location = 0) out vec4 color; \n"
" \n"
" void main() { \n"
" color = fs_col * texture(s_texture, vec3(fs_uv.st, 0)); \n"
" } \n";
unsigned vert_shader_id = glCreateShader(0x8B31); // GL_VERTEX_SHADER
unsigned frag_shader_id = glCreateShader(0x8B30); // GL_FRAGMENT_SHADER
glShaderSource(vert_shader_id, 1, (char **)&vert_string, NULL);
glShaderSource(frag_shader_id, 1, (char **)&frag_string, NULL);
glCompileShader(vert_shader_id);
glCompileShader(frag_shader_id);
g_vert = glCreateProgram();
g_frag = glCreateProgram();
glProgramParameteri(g_vert, 0x8258, 1); // GL_PROGRAM_SEPARABLE
glProgramParameteri(g_frag, 0x8258, 1); // GL_PROGRAM_SEPARABLE
glAttachShader(g_vert, vert_shader_id);
glAttachShader(g_frag, frag_shader_id);
glLinkProgram(g_vert);
glLinkProgram(g_frag);
glDetachShader(g_vert, vert_shader_id);
glDetachShader(g_frag, frag_shader_id);
glDeleteShader(vert_shader_id);
glDeleteShader(frag_shader_id);
glCreateProgramPipelines(1, &g_ppo);
glUseProgramStages(g_ppo, 0x00000001, g_vert); // GL_VERTEX_SHADER_BIT
glUseProgramStages(g_ppo, 0x00000002, g_frag); // GL_FRAGMENT_SHADER_BIT
imgui_create_font_texture();
}
void imgui_new_frame(SDL_Window * sdl_window, bool process_inputs) {
struct ImGuiIO * io = igGetIO();
if (!g_font_texture)
imgui_create_device_objects();
int w = 0, h = 0, dp_w = 0, dp_h = 0;
SDL_GetWindowSize(sdl_window, &w, &h);
SDL_GL_GetDrawableSize(sdl_window, &dp_w, &dp_h);
io->DisplaySize = (struct ImVec2){(float)w,(float)h};
io->DisplayFramebufferScale = (struct ImVec2){
w > 0 ? ((float)dp_w / w) : 0,
h > 0 ? ((float)dp_h / h) : 0
};
unsigned time = SDL_GetTicks();
double current_time = time / 1000.0;
io->DeltaTime = g_time > 0 ? (float)(current_time - g_time) : 1 / 60.0;
g_time = current_time;
if (process_inputs) {
int mx = 0, my = 0;
unsigned mousemask = SDL_GetMouseState(&mx, &my);
if (SDL_GetWindowFlags(sdl_window) & SDL_WINDOW_MOUSE_FOCUS)
io->MousePos = (struct ImVec2){(float)mx, (float)my};
else
io->MousePos = (struct ImVec2){-1, -1};
io->MouseDown[0] = g_is_mouse_pressed[0] || (mousemask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
io->MouseDown[1] = g_is_mouse_pressed[1] || (mousemask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
io->MouseDown[2] = g_is_mouse_pressed[2] || (mousemask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
io->MouseWheel = g_mouse_wheel;
}
g_is_mouse_pressed[0] = false;
g_is_mouse_pressed[1] = false;
g_is_mouse_pressed[2] = false;
g_mouse_wheel = 0;
SDL_ShowCursor(io->MouseDrawCursor ? 0 : 1);
igNewFrame();
}
static void imgui_invalidate_device_objects() {
struct ImGuiIO * io = igGetIO();
glDeleteProgram(g_vert);
glDeleteProgram(g_frag);
glDeleteProgramPipelines(1, &g_ppo);
g_vert = 0, g_frag = 0, g_ppo = 0;
if (g_font_texture) {
glDeleteTextures(1, &g_font_texture);
ImFontAtlas_SetTexID(io->Fonts, 0);
g_font_texture = 0;
}
}
static void imgui_deinit() {
imgui_invalidate_device_objects();
igShutdown();
}
static void imgui_init() {
struct ImGuiIO * io = igGetIO();
io->KeyMap[ImGuiKey_Tab] = SDLK_TAB;
io->KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
io->KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
io->KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
io->KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN;
io->KeyMap[ImGuiKey_PageUp] = SDL_SCANCODE_PAGEUP;
io->KeyMap[ImGuiKey_PageDown] = SDL_SCANCODE_PAGEDOWN;
io->KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME;
io->KeyMap[ImGuiKey_End] = SDL_SCANCODE_END;
io->KeyMap[ImGuiKey_Delete] = SDLK_DELETE;
io->KeyMap[ImGuiKey_Backspace] = SDLK_BACKSPACE;
io->KeyMap[ImGuiKey_Enter] = SDLK_RETURN;
io->KeyMap[ImGuiKey_Escape] = SDLK_ESCAPE;
io->KeyMap[ImGuiKey_A] = SDLK_a;
io->KeyMap[ImGuiKey_C] = SDLK_c;
io->KeyMap[ImGuiKey_V] = SDLK_v;
io->KeyMap[ImGuiKey_X] = SDLK_x;
io->KeyMap[ImGuiKey_Y] = SDLK_y;
io->KeyMap[ImGuiKey_Z] = SDLK_z;
io->RenderDrawListsFn = imgui_render_draw_list;
io->GetClipboardTextFn = imgui_get_clipboard_text;
io->SetClipboardTextFn = imgui_set_clipboard_text;
}
static void imgui_easy_theming(
struct ImVec3 color_for_text,
struct ImVec3 color_for_head,
struct ImVec3 color_for_area,
struct ImVec3 color_for_body,
struct ImVec3 color_for_pops)
{
struct ImGuiStyle * style = igGetStyle();
style->Colors[ImGuiCol_Text] = (struct ImVec4){color_for_text.x, color_for_text.y, color_for_text.z, 1.00};
style->Colors[ImGuiCol_TextDisabled] = (struct ImVec4){color_for_text.x, color_for_text.y, color_for_text.z, 0.58};
style->Colors[ImGuiCol_WindowBg] = (struct ImVec4){color_for_body.x, color_for_body.y, color_for_body.z, 1.00};
style->Colors[ImGuiCol_ChildWindowBg] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 0.58};
style->Colors[ImGuiCol_Border] = (struct ImVec4){color_for_body.x, color_for_body.y, color_for_body.z, 0.00};
style->Colors[ImGuiCol_BorderShadow] = (struct ImVec4){color_for_body.x, color_for_body.y, color_for_body.z, 0.00};
style->Colors[ImGuiCol_FrameBg] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 1.00};
style->Colors[ImGuiCol_FrameBgHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.78};
style->Colors[ImGuiCol_FrameBgActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_TitleBg] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 1.00};
style->Colors[ImGuiCol_TitleBgCollapsed] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 0.75};
style->Colors[ImGuiCol_TitleBgActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_MenuBarBg] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 1.00};
style->Colors[ImGuiCol_ScrollbarBg] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 1.00};
style->Colors[ImGuiCol_ScrollbarGrab] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.50};
style->Colors[ImGuiCol_ScrollbarGrabHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.78};
style->Colors[ImGuiCol_ScrollbarGrabActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_ComboBg] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 1.00};
style->Colors[ImGuiCol_CheckMark] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.80};
style->Colors[ImGuiCol_SliderGrab] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.50};
style->Colors[ImGuiCol_SliderGrabActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_Button] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.50};
style->Colors[ImGuiCol_ButtonHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.86};
style->Colors[ImGuiCol_ButtonActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_Header] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.76};
style->Colors[ImGuiCol_HeaderHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.86};
style->Colors[ImGuiCol_HeaderActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_Column] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.32};
style->Colors[ImGuiCol_ColumnHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.78};
style->Colors[ImGuiCol_ColumnActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_ResizeGrip] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.15};
style->Colors[ImGuiCol_ResizeGripHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.78};
style->Colors[ImGuiCol_ResizeGripActive] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_CloseButton] = (struct ImVec4){color_for_text.x, color_for_text.y, color_for_text.z, 0.16};
style->Colors[ImGuiCol_CloseButtonHovered] = (struct ImVec4){color_for_text.x, color_for_text.y, color_for_text.z, 0.39};
style->Colors[ImGuiCol_CloseButtonActive] = (struct ImVec4){color_for_text.x, color_for_text.y, color_for_text.z, 1.00};
style->Colors[ImGuiCol_PlotLines] = (struct ImVec4){color_for_text.x, color_for_text.y, color_for_text.z, 0.63};
style->Colors[ImGuiCol_PlotLinesHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_PlotHistogram] = (struct ImVec4){color_for_text.x, color_for_text.y, color_for_text.z, 0.63};
style->Colors[ImGuiCol_PlotHistogramHovered] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 1.00};
style->Colors[ImGuiCol_TextSelectedBg] = (struct ImVec4){color_for_head.x, color_for_head.y, color_for_head.z, 0.43};
style->Colors[ImGuiCol_PopupBg] = (struct ImVec4){color_for_pops.x, color_for_pops.y, color_for_pops.z, 0.92};
style->Colors[ImGuiCol_ModalWindowDarkening] = (struct ImVec4){color_for_area.x, color_for_area.y, color_for_area.z, 0.73};
}