-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpl_main.cpp
More file actions
1104 lines (956 loc) · 38.4 KB
/
pl_main.cpp
File metadata and controls
1104 lines (956 loc) · 38.4 KB
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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
pl_main.c
*/
/*
Index of this file:
// [SECTION] includes
// [SECTION] global data
// [SECTION] forward declarations
// [SECTION] window api
// [SECTION] glfw callbacks
// [SECTION] thread api
// [SECTION] library api
*/
//-----------------------------------------------------------------------------
// [SECTION] includes
//-----------------------------------------------------------------------------
#define PL_EXPERIMENTAL
#ifdef _WIN32
const char* gpcLibraryExtension = "dll";
#elif defined(__APPLE__)
const char* gpcLibraryExtension = "dylib";
#else // linux
const char* gpcLibraryExtension = "so";
#endif
// platform specifics
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#elif defined(__APPLE__)
#import <Cocoa/Cocoa.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
#include <time.h> // clock_gettime_nsec_np
#include <sys/stat.h> // timespec
#include <copyfile.h> // copyfile
#include <dlfcn.h> // dlopen, dlsym, dlclose
#include <unistd.h> // close
#include <fcntl.h> // O_RDONLY, O_WRONLY ,O_CREAT
#include <pthread.h>
#define GLFW_EXPOSE_NATIVE_COCOA
#else // linux
#include <sys/sendfile.h> // sendfile
#include <sys/stat.h> // stat, timespec
#include <dlfcn.h> // dlopen, dlsym, dlclose
#include <fcntl.h> // O_RDONLY, O_WRONLY ,O_CREAT
#include <time.h> // clock_gettime, clock_getres
#include <unistd.h> // usleep()
#include <pthread.h>
#include <X11/Xatom.h>
#define GLFW_EXPOSE_NATIVE_X11
#endif
// imgui
#include "imgui.h"
#include "imgui_internal.h" // ImLerp
#include "imgui_impl_glfw.h"
// glfw
#include <GLFW/glfw3.h>
#include "GLFW/glfw3native.h"
#include "pl_internal.h"
#define PL_SINGLE_UNIT_BUILD
#include "pl.c"
// extern plIO* gptIOCtx;
//-----------------------------------------------------------------------------
// [SECTION] global data
//-----------------------------------------------------------------------------
#ifdef _WIN32
INT64 ilTime = 0;
INT64 ilTicksPerSecond = 0;
#elif defined(__APPLE__)
id<MTLDevice> device;
NSWindow* nswin;
CFTimeInterval gtTime;
CAMetalLayer* layer;
static inline CFTimeInterval pl__get_absolute_time(void) { return (CFTimeInterval)((double)(clock_gettime_nsec_np(CLOCK_UPTIME_RAW)) / 1e9); }
#else // linux
double gdTime = 0.0;
double gdFrequency = 0.0;
static inline double
pl__get_linux_absolute_time(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
{
assert(false && "clock_gettime() failed");
}
uint64_t nsec_count = ts.tv_nsec + ts.tv_sec * 1e9;
return (double)nsec_count / gdFrequency;
}
#endif
// glfw
GLFWwindow* gptGlfwWindow;
GLFWwindow* ptMouseWindow;
GLFWcursor* atMouseCursors[PL_MOUSE_CURSOR_COUNT];
bool bMouseIgnoreButtonUpWaitForFocusLoss;
bool bMouseIgnoreButtonUp;
plVec2 tLastValidMousePos;
GLFWwindow* atKeyOwnerWindows[GLFW_KEY_LAST];
//-----------------------------------------------------------------------------
// [SECTION] forward declarations
//-----------------------------------------------------------------------------
void pl_glfw_error_callback (int error, const char* description);
void pl_glfw_mouse_button_callback (GLFWwindow*, int button, int action, int mods);
void pl_glfw_mouse_pos_callback (GLFWwindow*, double x, double y);
void pl_glfw_cursor_enter_callback (GLFWwindow*, int entered);
void pl_glfw_window_focus_callback (GLFWwindow*, int focused);
void pl_glfw_scroll_callback (GLFWwindow*, double xoffset, double yoffset);
void pl_glfw_char_callback (GLFWwindow*, unsigned int c);
void pl_glfw_key_callback (GLFWwindow*, int keycode, int scancode, int action, int mods);
void pl_glfw_size_callback (GLFWwindow*, int width, int height);
void pl_glfw_window_iconified_callback(GLFWwindow*, int iconified);
void pl_glfw_window_close_callback (GLFWwindow*);
plKey pl_glfw_key_translate (int keycode, int scancode);
//-----------------------------------------------------------------------------
// [SECTION] window api
//-----------------------------------------------------------------------------
void
pl_set_window_size(plWindow* ptWindow, uint32_t uWidth, uint32_t uHeight)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwSetWindowSize(ptGlfwWindow, (int)uWidth, (int)uHeight);
}
void
pl_set_window_pos(plWindow* ptWindow, int iXPos, int iYPos)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwSetWindowPos(ptGlfwWindow, iXPos, iYPos);
}
void
pl_get_window_size(plWindow* ptWindow, uint32_t* uWidth, uint32_t* uHeight)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
int iWidth = 0;
int iHeight = 0;
glfwGetWindowSize(ptGlfwWindow, &iWidth, &iHeight);
*uWidth = (uint32_t)iWidth;
*uHeight = (uint32_t)iHeight;
}
void
pl_get_window_pos(plWindow* ptWindow, int* iXPos, int* iYPos)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwGetWindowPos(ptGlfwWindow, iXPos, iYPos);
}
void
pl_minimize_window(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwIconifyWindow(ptGlfwWindow);
}
void
pl_show_window(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwShowWindow(ptGlfwWindow);
}
void
pl_hide_window(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwHideWindow(ptGlfwWindow);
}
void
pl_maximize_window(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwMaximizeWindow(ptGlfwWindow);
}
void
pl_restore_window(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwRestoreWindow(ptGlfwWindow);
}
void
pl_focus_window(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwFocusWindow(ptGlfwWindow);
}
void
pl_hide_cursor(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
}
void
pl_capture_cursor(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_CAPTURED);
}
void
pl_normal_cursor(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
void
pl_set_raw_mouse_input(plWindow* ptWindow, bool bValue)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwRawMouseMotionSupported())
glfwSetInputMode(ptGlfwWindow, GLFW_RAW_MOUSE_MOTION, bValue ? GLFW_TRUE : GLFW_FALSE);
}
bool
pl_is_window_maximized(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_MAXIMIZED))
{
return true;
}
return false;
}
bool
pl_is_window_minimized(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_ICONIFIED))
{
return true;
}
return false;
}
bool
pl_is_window_focused(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_FOCUSED))
{
return true;
}
return false;
}
bool
pl_is_window_hovered(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_HOVERED))
{
return true;
}
return false;
}
bool
pl_is_window_resizable(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_RESIZABLE))
{
return true;
}
return false;
}
bool
pl_is_window_decorated(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_DECORATED))
{
return true;
}
return false;
}
bool
pl_is_window_top_most(plWindow* ptWindow)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_FLOATING))
{
return true;
}
return false;
}
plWindowResult
pl_create_window(plWindowDesc tDesc, plWindow** pptWindowOut)
{
plWindow* ptWindow = (plWindow*)malloc(sizeof(plWindow));
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, (tDesc.tFlags & PL_WINDOW_FLAG_NOT_RESIZABLE) ? GLFW_FALSE : GLFW_TRUE);
glfwWindowHint(GLFW_DECORATED, (tDesc.tFlags & PL_WINDOW_FLAG_UNDECORATED) ? GLFW_FALSE : GLFW_TRUE);
glfwWindowHint(GLFW_FLOATING, (tDesc.tFlags & PL_WINDOW_FLAG_TOP_MOST) ? GLFW_TRUE : GLFW_FALSE);
glfwWindowHint(GLFW_POSITION_X, tDesc.iXPos);
glfwWindowHint(GLFW_POSITION_Y, tDesc.iXPos);
gptGlfwWindow = glfwCreateWindow((int)tDesc.uWidth, (int)tDesc.uHeight, tDesc.pcTitle, NULL, NULL);
int iMinWidth = tDesc.uMinWidth > 0 ? (int)tDesc.uMinWidth : GLFW_DONT_CARE;
int iMaxWidth = tDesc.uMaxWidth > 0 ? (int)tDesc.uMaxWidth : GLFW_DONT_CARE;
int iMinHeight = tDesc.uMinHeight > 0 ? (int)tDesc.uMinHeight : GLFW_DONT_CARE;
int iMaxHeight = tDesc.uMaxHeight > 0 ? (int)tDesc.uMaxHeight : GLFW_DONT_CARE;
glfwSetWindowSizeLimits(gptGlfwWindow, iMinWidth, iMinHeight, iMaxWidth, iMaxHeight);
ptWindow->_pBackendData2 = gptGlfwWindow;
if(gptMainWindow == NULL)
gptMainWindow = ptWindow;
glfwSetMouseButtonCallback(gptGlfwWindow, pl_glfw_mouse_button_callback);
glfwSetCursorPosCallback(gptGlfwWindow, pl_glfw_mouse_pos_callback);
glfwSetCursorEnterCallback(gptGlfwWindow, pl_glfw_cursor_enter_callback);
glfwSetScrollCallback(gptGlfwWindow, pl_glfw_scroll_callback);
glfwSetCharCallback(gptGlfwWindow, pl_glfw_char_callback);
glfwSetKeyCallback(gptGlfwWindow, pl_glfw_key_callback);
glfwSetWindowFocusCallback(gptGlfwWindow, pl_glfw_window_focus_callback);
glfwSetWindowSizeCallback(gptGlfwWindow, pl_glfw_size_callback);
glfwSetWindowIconifyCallback(gptGlfwWindow, pl_glfw_window_iconified_callback);
glfwSetWindowCloseCallback(gptGlfwWindow, pl_glfw_window_close_callback);
#ifdef PL_METAL_BACKEND
if(pl_sb_size(gsbtWindows) == 0)
ImGui_ImplGlfw_InitForOther(gptGlfwWindow, true);
#else
if(pl_sb_size(gsbtWindows) == 0)
ImGui_ImplGlfw_InitForVulkan(gptGlfwWindow, true);
#endif
#ifdef _WIN32
HWND tHandle = glfwGetWin32Window(gptGlfwWindow);
ptWindow->_pBackendData = tHandle;
#elif defined(__APPLE__)
device = MTLCreateSystemDefaultDevice();
gptIOCtx->pBackendPlatformData = device;
nswin = glfwGetCocoaWindow(gptGlfwWindow);
layer = [CAMetalLayer layer];
layer.device = device;
layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
nswin.contentView.layer = layer;
nswin.contentView.wantsLayer = YES;
typedef struct _plWindowData
{
void* ptWindow;
void* ptViewController;
CAMetalLayer* ptLayer;
} plWindowData;
plWindowData* ptData = (plWindowData*)malloc(sizeof(plWindowData));
ptData->ptLayer = layer;
ptWindow->_pBackendData = ptData;
#else // linux
typedef struct plPlatformData
{
uint32_t header;
Display* dpy;
Window window;
} plPlatformData;
static plPlatformData tPlatformData = {UINT32_MAX};
tPlatformData.dpy = glfwGetX11Display();
tPlatformData.window = glfwGetX11Window(gptGlfwWindow);
ptWindow->_pBackendData = &tPlatformData;
#endif
*pptWindowOut = ptWindow;
pl_sb_push(gsbtWindows, ptWindow);
return PL_WINDOW_RESULT_SUCCESS;
}
void
pl_destroy_window(plWindow* ptWindow)
{
free(ptWindow);
}
//-----------------------------------------------------------------------------
// [SECTION] glfw callbacks
//-----------------------------------------------------------------------------
void
pl_glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
// if(ImGui::GetIO().WantCaptureMouse)
// return;
// update key modifiers
gptIOI->add_key_event(PL_KEY_MOD_CTRL, (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS));
gptIOI->add_key_event(PL_KEY_MOD_SHIFT, (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS));
gptIOI->add_key_event(PL_KEY_MOD_ALT, (glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS));
gptIOI->add_key_event(PL_KEY_MOD_SUPER, (glfwGetKey(window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS));
plIO* ptIO = gptIOI->get_io();
if (button >= 0 && button < PL_MOUSE_BUTTON_COUNT)
gptIOI->add_mouse_button_event(button, action == GLFW_PRESS);
}
void
pl_glfw_mouse_pos_callback(GLFWwindow* window, double x, double y)
{
gptIOI->add_mouse_pos_event((float)x, (float)y);
tLastValidMousePos.x = (float)x;
tLastValidMousePos.y = (float)y;
}
void
pl_glfw_cursor_enter_callback(GLFWwindow* window, int entered)
{
// if(ImGui::GetIO().WantCaptureMouse)
// return;
plIO* ptIO = gptIOI->get_io();
if (entered)
{
ptMouseWindow = window;
gptIOI->add_mouse_pos_event(tLastValidMousePos.x, tLastValidMousePos.y);
}
else if (ptMouseWindow == window)
{
tLastValidMousePos = ptIO->_tMousePos;
ptMouseWindow = NULL;
gptIOI->add_mouse_pos_event(-FLT_MAX, -FLT_MAX);
}
}
void
pl_glfw_window_focus_callback(GLFWwindow* window, int focused)
{
// Workaround for Linux: when losing focus with bMouseIgnoreButtonUpWaitForFocusLoss set, we will temporarily ignore subsequent Mouse Up events
bMouseIgnoreButtonUp = (bMouseIgnoreButtonUpWaitForFocusLoss && focused == 0);
bMouseIgnoreButtonUpWaitForFocusLoss = false;
// gptIOI->add_focus_event(focused != 0);
}
void
pl_glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
// if(ImGui::GetIO().WantCaptureMouse)
// return;
gptIOI->add_mouse_wheel_event((float)xoffset, (float)yoffset);
}
void
pl_glfw_char_callback(GLFWwindow* window, unsigned int c)
{
// if(ImGui::GetIO().WantTextInput)
// return;
gptIOI->add_text_event(c);
}
int
pl_translate_untranslated_key(int key, int scancode)
{
if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL)
return key;
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(NULL);
const char* key_name = glfwGetKeyName(key, scancode);
glfwSetErrorCallback(prev_error_callback);
(void)glfwGetError(NULL);
if (key_name && key_name[0] != 0 && key_name[1] == 0)
{
const char char_names[] = "`-=[]\\,;\'./";
const int char_keys[] = { GLFW_KEY_GRAVE_ACCENT, GLFW_KEY_MINUS, GLFW_KEY_EQUAL, GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_BACKSLASH, GLFW_KEY_COMMA, GLFW_KEY_SEMICOLON, GLFW_KEY_APOSTROPHE, GLFW_KEY_PERIOD, GLFW_KEY_SLASH, 0 };
PL_ASSERT(PL_ARRAYSIZE(char_names) == PL_ARRAYSIZE(char_keys));
if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); }
else if (key_name[0] >= 'A' && key_name[0] <= 'Z') { key = GLFW_KEY_A + (key_name[0] - 'A'); }
else if (key_name[0] >= 'a' && key_name[0] <= 'z') { key = GLFW_KEY_A + (key_name[0] - 'a'); }
else
{
const char* p = strchr(char_names, key_name[0]);
if(p)
{
key = char_keys[p - char_names];
}
}
}
// if (action == GLFW_PRESS) printf("key %d scancode %d name '%s'\n", key, scancode, key_name);
return key;
}
void
pl_glfw_size_callback(GLFWwindow* window, int width, int height)
{
gptIOCtx->bViewportSizeChanged = true;
if(width == 0 || height == 0)
{
gptIOCtx->bViewportMinimized = true;
}
else
{
int fwidth, fheight;
glfwGetFramebufferSize(window, &fwidth, &fheight);
gptIOCtx->tMainFramebufferScale.x = (float)fwidth / (float)width;
gptIOCtx->tMainFramebufferScale.y = (float)fheight / (float)height;
gptIOCtx->bViewportMinimized = false;
gptIOCtx->tMainViewportSize.x = (float)width;
gptIOCtx->tMainViewportSize.y = (float)height;
// gsbtWindows[0]->tDesc.uWidth = (uint32_t)width;
// gsbtWindows[0]->tDesc.uHeight = (uint32_t)height;
// pl__app_resize(gptMainWindow, gpUserData);
}
}
void
pl_glfw_window_iconified_callback(GLFWwindow* window, int iconified)
{
gptIOCtx->bViewportMinimized = iconified;
}
void
pl_glfw_window_close_callback(GLFWwindow* window)
{
gptIOCtx->bRunning = false;
}
void
pl_glfw_key_callback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
{
if (action != GLFW_PRESS && action != GLFW_RELEASE)
return;
// if(ImGui::GetIO().WantCaptureKeyboard)
// return;
// update key modifiers
gptIOI->add_key_event(PL_KEY_MOD_CTRL, (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS));
gptIOI->add_key_event(PL_KEY_MOD_SHIFT, (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS));
gptIOI->add_key_event(PL_KEY_MOD_ALT, (glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS));
gptIOI->add_key_event(PL_KEY_MOD_SUPER, (glfwGetKey(window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS));
if (keycode >= 0 && keycode < PL_ARRAYSIZE(atKeyOwnerWindows))
atKeyOwnerWindows[keycode] = (action == GLFW_PRESS) ? window : NULL;
keycode = pl_translate_untranslated_key(keycode, scancode);
plKey imgui_key = pl_glfw_key_translate(keycode, scancode);
gptIOI->add_key_event(imgui_key, (action == GLFW_PRESS));
}
plKey
pl_glfw_key_translate(int keycode, int scancode)
{
switch (keycode)
{
case GLFW_KEY_TAB: return PL_KEY_TAB;
case GLFW_KEY_LEFT: return PL_KEY_LEFT_ARROW;
case GLFW_KEY_RIGHT: return PL_KEY_RIGHT_ARROW;
case GLFW_KEY_UP: return PL_KEY_UP_ARROW;
case GLFW_KEY_DOWN: return PL_KEY_DOWN_ARROW;
case GLFW_KEY_PAGE_UP: return PL_KEY_PAGE_UP;
case GLFW_KEY_PAGE_DOWN: return PL_KEY_PAGE_DOWN;
case GLFW_KEY_HOME: return PL_KEY_HOME;
case GLFW_KEY_END: return PL_KEY_END;
case GLFW_KEY_INSERT: return PL_KEY_INSERT;
case GLFW_KEY_DELETE: return PL_KEY_DELETE;
case GLFW_KEY_BACKSPACE: return PL_KEY_BACKSPACE;
case GLFW_KEY_SPACE: return PL_KEY_SPACE;
case GLFW_KEY_ENTER: return PL_KEY_ENTER;
case GLFW_KEY_ESCAPE: return PL_KEY_ESCAPE;
case GLFW_KEY_APOSTROPHE: return PL_KEY_APOSTROPHE;
case GLFW_KEY_COMMA: return PL_KEY_COMMA;
case GLFW_KEY_MINUS: return PL_KEY_MINUS;
case GLFW_KEY_PERIOD: return PL_KEY_PERIOD;
case GLFW_KEY_SLASH: return PL_KEY_SLASH;
case GLFW_KEY_SEMICOLON: return PL_KEY_SEMICOLON;
case GLFW_KEY_EQUAL: return PL_KEY_EQUAL;
case GLFW_KEY_LEFT_BRACKET: return PL_KEY_LEFT_BRACKET;
case GLFW_KEY_BACKSLASH: return PL_KEY_BACKSLASH;
// case GLFW_KEY_WORLD_1: return PL_KEY_Oem102;
// case GLFW_KEY_WORLD_2: return PL_KEY_Oem102;
case GLFW_KEY_RIGHT_BRACKET: return PL_KEY_RIGHT_BRACKET;
case GLFW_KEY_GRAVE_ACCENT: return PL_KEY_GRAVE_ACCENT;
case GLFW_KEY_CAPS_LOCK: return PL_KEY_CAPS_LOCK;
case GLFW_KEY_SCROLL_LOCK: return PL_KEY_SCROLL_LOCK;
case GLFW_KEY_NUM_LOCK: return PL_KEY_NUM_LOCK;
case GLFW_KEY_PRINT_SCREEN: return PL_KEY_PRINT_SCREEN;
case GLFW_KEY_PAUSE: return PL_KEY_PAUSE;
case GLFW_KEY_KP_0: return PL_KEY_KEYPAD_0;
case GLFW_KEY_KP_1: return PL_KEY_KEYPAD_1;
case GLFW_KEY_KP_2: return PL_KEY_KEYPAD_2;
case GLFW_KEY_KP_3: return PL_KEY_KEYPAD_3;
case GLFW_KEY_KP_4: return PL_KEY_KEYPAD_4;
case GLFW_KEY_KP_5: return PL_KEY_KEYPAD_5;
case GLFW_KEY_KP_6: return PL_KEY_KEYPAD_6;
case GLFW_KEY_KP_7: return PL_KEY_KEYPAD_7;
case GLFW_KEY_KP_8: return PL_KEY_KEYPAD_8;
case GLFW_KEY_KP_9: return PL_KEY_KEYPAD_9;
case GLFW_KEY_KP_DECIMAL: return PL_KEY_KEYPAD_DECIMAL;
case GLFW_KEY_KP_DIVIDE: return PL_KEY_KEYPAD_DIVIDE;
case GLFW_KEY_KP_MULTIPLY: return PL_KEY_KEYPAD_MULTIPLY;
case GLFW_KEY_KP_SUBTRACT: return PL_KEY_KEYPAD_SUBTRACT;
case GLFW_KEY_KP_ADD: return PL_KEY_KEYPAD_ADD;
case GLFW_KEY_KP_ENTER: return PL_KEY_KEYPAD_ENTER;
case GLFW_KEY_KP_EQUAL: return PL_KEY_KEYPAD_EQUAL;
case GLFW_KEY_LEFT_SHIFT: return PL_KEY_LEFT_SHIFT;
case GLFW_KEY_LEFT_CONTROL: return PL_KEY_LEFT_CTRL;
case GLFW_KEY_LEFT_ALT: return PL_KEY_LEFT_ALT;
case GLFW_KEY_LEFT_SUPER: return PL_KEY_LEFT_SUPER;
case GLFW_KEY_RIGHT_SHIFT: return PL_KEY_RIGHT_SHIFT;
case GLFW_KEY_RIGHT_CONTROL: return PL_KEY_RIGHT_CTRL;
case GLFW_KEY_RIGHT_ALT: return PL_KEY_RIGHT_ALT;
case GLFW_KEY_RIGHT_SUPER: return PL_KEY_RIGHT_SUPER;
case GLFW_KEY_MENU: return PL_KEY_MENU;
case GLFW_KEY_0: return PL_KEY_0;
case GLFW_KEY_1: return PL_KEY_1;
case GLFW_KEY_2: return PL_KEY_2;
case GLFW_KEY_3: return PL_KEY_3;
case GLFW_KEY_4: return PL_KEY_4;
case GLFW_KEY_5: return PL_KEY_5;
case GLFW_KEY_6: return PL_KEY_6;
case GLFW_KEY_7: return PL_KEY_7;
case GLFW_KEY_8: return PL_KEY_8;
case GLFW_KEY_9: return PL_KEY_9;
case GLFW_KEY_A: return PL_KEY_A;
case GLFW_KEY_B: return PL_KEY_B;
case GLFW_KEY_C: return PL_KEY_C;
case GLFW_KEY_D: return PL_KEY_D;
case GLFW_KEY_E: return PL_KEY_E;
case GLFW_KEY_F: return PL_KEY_F;
case GLFW_KEY_G: return PL_KEY_G;
case GLFW_KEY_H: return PL_KEY_H;
case GLFW_KEY_I: return PL_KEY_I;
case GLFW_KEY_J: return PL_KEY_J;
case GLFW_KEY_K: return PL_KEY_K;
case GLFW_KEY_L: return PL_KEY_L;
case GLFW_KEY_M: return PL_KEY_M;
case GLFW_KEY_N: return PL_KEY_N;
case GLFW_KEY_O: return PL_KEY_O;
case GLFW_KEY_P: return PL_KEY_P;
case GLFW_KEY_Q: return PL_KEY_Q;
case GLFW_KEY_R: return PL_KEY_R;
case GLFW_KEY_S: return PL_KEY_S;
case GLFW_KEY_T: return PL_KEY_T;
case GLFW_KEY_U: return PL_KEY_U;
case GLFW_KEY_V: return PL_KEY_V;
case GLFW_KEY_W: return PL_KEY_W;
case GLFW_KEY_X: return PL_KEY_X;
case GLFW_KEY_Y: return PL_KEY_Y;
case GLFW_KEY_Z: return PL_KEY_Z;
case GLFW_KEY_F1: return PL_KEY_F1;
case GLFW_KEY_F2: return PL_KEY_F2;
case GLFW_KEY_F3: return PL_KEY_F3;
case GLFW_KEY_F4: return PL_KEY_F4;
case GLFW_KEY_F5: return PL_KEY_F5;
case GLFW_KEY_F6: return PL_KEY_F6;
case GLFW_KEY_F7: return PL_KEY_F7;
case GLFW_KEY_F8: return PL_KEY_F8;
case GLFW_KEY_F9: return PL_KEY_F9;
case GLFW_KEY_F10: return PL_KEY_F10;
case GLFW_KEY_F11: return PL_KEY_F11;
case GLFW_KEY_F12: return PL_KEY_F12;
case GLFW_KEY_F13: return PL_KEY_F13;
case GLFW_KEY_F14: return PL_KEY_F14;
case GLFW_KEY_F15: return PL_KEY_F15;
case GLFW_KEY_F16: return PL_KEY_F16;
case GLFW_KEY_F17: return PL_KEY_F17;
case GLFW_KEY_F18: return PL_KEY_F18;
case GLFW_KEY_F19: return PL_KEY_F19;
case GLFW_KEY_F20: return PL_KEY_F20;
case GLFW_KEY_F21: return PL_KEY_F21;
case GLFW_KEY_F22: return PL_KEY_F22;
case GLFW_KEY_F23: return PL_KEY_F23;
case GLFW_KEY_F24: return PL_KEY_F24;
default: return PL_KEY_NONE;
}
}
void
pl_glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
}
//-----------------------------------------------------------------------------
// [SECTION] thread api
//-----------------------------------------------------------------------------
#ifdef _WIN32
typedef struct _plMutex
{
HANDLE tHandle;
} plMutex;
void
pl_create_mutex(plMutex** ppMutexOut)
{
HANDLE tHandle = CreateMutex(NULL, FALSE, NULL);
if(tHandle)
{
(*ppMutexOut) = (plMutex*)malloc(sizeof(plMutex));
(*ppMutexOut)->tHandle = tHandle;
}
}
void
pl_destroy_mutex(plMutex** ptMutex)
{
CloseHandle((*ptMutex)->tHandle);
free((*ptMutex));
(*ptMutex) = NULL;
}
void
pl_lock_mutex(plMutex* ptMutex)
{
DWORD dwWaitResult = WaitForSingleObject(ptMutex->tHandle, INFINITE);
PL_ASSERT(dwWaitResult == WAIT_OBJECT_0);
}
void
pl_unlock_mutex(plMutex* ptMutex)
{
if(!ReleaseMutex(ptMutex->tHandle))
{
printf("ReleaseMutex error: %d\n", GetLastError());
PL_ASSERT(false);
}
}
#else // linux
typedef struct _plMutex
{
pthread_mutex_t tHandle;
} plMutex;
void
pl_create_mutex(plMutex** pptMutexOut)
{
*pptMutexOut = (plMutex*)malloc(sizeof(plMutex));
if(pthread_mutex_init(&(*pptMutexOut)->tHandle, NULL)) //-V522
{
PL_ASSERT(false);
}
}
void
pl_lock_mutex(plMutex* ptMutex)
{
pthread_mutex_lock(&ptMutex->tHandle);
}
void
pl_unlock_mutex(plMutex* ptMutex)
{
pthread_mutex_unlock(&ptMutex->tHandle);
}
void
pl_destroy_mutex(plMutex** pptMutex)
{
pthread_mutex_destroy(&(*pptMutex)->tHandle);
free((*pptMutex));
*pptMutex = NULL;
}
#endif
//-----------------------------------------------------------------------------
// [SECTION] library api
//-----------------------------------------------------------------------------
plLibraryResult
pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
{
return 0;
}
void
pl_reload_library(plSharedLibrary* ptLibrary)
{
}
void*
pl_load_library_function(plSharedLibrary* ptLibrary, const char* name)
{
return NULL;
}
bool
pl_has_library_changed(plSharedLibrary* ptLibrary)
{
return false;
}
extern "C" const plWindowI* ptWindows2;
// const plDataRegistryI* gptDataRegistry = nullptr;
extern "C" const plApiRegistryI*
pl__python_load(void)
{
return pl__load_api_registry();
}
extern "C" void
pl__python_setup(void)
{
const plApiRegistryI* ptApiRegistry = pl__load_api_registry();
pl__load_core_apis();
// pl_load_ext((plApiRegistryI*)ptApiRegistry, false);
// pl_load_platform_ext((plApiRegistryI*)ptApiRegistry, false);
ptWindows2 = pl_get_api_latest(ptApiRegistry, plWindowI);
gptDataRegistry = pl_get_api_latest(ptApiRegistry, plDataRegistryI);
// setup timers
#ifdef _WIN32
QueryPerformanceFrequency((LARGE_INTEGER*)&ilTicksPerSecond);
QueryPerformanceCounter((LARGE_INTEGER*)&ilTime);
#elif defined(__APPLE__)
#else // linux
#endif
gptIOCtx = gptIOI->get_io();
gptIOCtx->bHotReloadActive = false;
// command line args
gptIOCtx->iArgc = 0;
gptIOCtx->apArgv = NULL;
glfwSetErrorCallback(pl_glfw_error_callback);
// setup glfw
if (!glfwInit())
return;
atMouseCursors[PL_MOUSE_CURSOR_ARROW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_TEXT_INPUT] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_RESIZE_NS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_RESIZE_EW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_HAND] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_RESIZE_ALL] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_RESIZE_NESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_RESIZE_NWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR);
atMouseCursors[PL_MOUSE_CURSOR_NOT_ALLOWED] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR);
// set clipboard functions (may need to move this to OS api)
gptIOCtx->set_clipboard_text_fn = [](void* pUnused, const char* text) { glfwSetClipboardString(nullptr, text); };
gptIOCtx->get_clipboard_text_fn = [](void* pUnused) { return glfwGetClipboardString(nullptr); };
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGuiContext* ptImGuiCtx = ImGui::CreateContext();
ImGuiMemAllocFunc p_alloc_func = nullptr;
ImGuiMemFreeFunc p_free_func = nullptr;
void* p_user_data = nullptr;
ImGui::GetAllocatorFunctions(&p_alloc_func, &p_free_func, &p_user_data);
gptDataRegistry->set_data("imgui", ptImGuiCtx);
gptDataRegistry->set_data("imgui allocate", (void*)p_alloc_func);
gptDataRegistry->set_data("imgui free", (void*)p_free_func);
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
//io.ConfigViewportsNoAutoMerge = true;
//io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
// setup pilot light style
ImVec4* colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Button] = ImVec4(0.51f, 0.02f, 0.10f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.61f, 0.02f, 0.10f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.87f, 0.02f, 0.10f, 1.00f);
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f);
colors[ImGuiCol_ChildBg] = ImVec4(0.25f, 0.10f, 0.10f, 0.78f);
colors[ImGuiCol_PopupBg] = ImVec4(0.15f, 0.10f, 0.10f, 0.78f);
colors[ImGuiCol_Border] = ImVec4(0.33f, 0.02f, 0.10f, 1.00f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.23f, 0.02f, 0.10f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.33f, 0.02f, 0.10f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.05f, 0.05f, 0.05f, 0.85f);
colors[ImGuiCol_ScrollbarGrab] = colors[ImGuiCol_Button];
colors[ImGuiCol_ScrollbarGrabHovered] = colors[ImGuiCol_ButtonHovered];
colors[ImGuiCol_ScrollbarGrabActive] = colors[ImGuiCol_ButtonActive];
colors[ImGuiCol_CheckMark] = colors[ImGuiCol_ButtonActive];
colors[ImGuiCol_SliderGrab] = colors[ImGuiCol_Button];
colors[ImGuiCol_SliderGrabActive] = colors[ImGuiCol_ButtonActive];
colors[ImGuiCol_Header] = colors[ImGuiCol_Button];
colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_Separator] = colors[ImGuiCol_Border];
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.98f, 0.59f, 0.26f, 0.20f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.98f, 0.59f, 0.26f, 0.67f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.98f, 0.59f, 0.26f, 0.95f);
colors[ImGuiCol_InputTextCursor] = colors[ImGuiCol_Text];
colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered];
colors[ImGuiCol_Tab] = ImLerp(colors[ImGuiCol_Header], colors[ImGuiCol_TitleBgActive], 0.80f);
colors[ImGuiCol_TabSelected] = ImLerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f);
colors[ImGuiCol_TabSelectedOverline] = colors[ImGuiCol_HeaderActive];
colors[ImGuiCol_TabDimmed] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
colors[ImGuiCol_TabDimmedSelected] = ImLerp(colors[ImGuiCol_TabSelected], colors[ImGuiCol_TitleBg], 0.40f);
colors[ImGuiCol_TabDimmedSelectedOverline] = ImVec4(0.50f, 0.50f, 0.50f, 0.00f);
colors[ImGuiCol_DockingPreview] = ImVec4(0.51f, 0.02f, 0.10f, 0.7f);
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
colors[ImGuiCol_TextLink] = colors[ImGuiCol_HeaderActive];
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
colors[ImGuiCol_NavCursor] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
// when viewports are enabled we tweak WindowRounding/WindowBg so
// platform windows can look identical to regular ones.
ImGuiStyle& style = ImGui::GetStyle();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
}
extern "C" void
pl__python_shutdown(void)
{
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
extern "C" int
pl__python_pre_update(void)
{
glfwPollEvents();
pl__garbage_collect_data_reg();
// update time step
#ifdef _WIN32
INT64 ilCurrentTime = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&ilCurrentTime);
gptIOCtx->fDeltaTime = (float)(ilCurrentTime - ilTime) / ilTicksPerSecond;