-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpl_main_glfw.cpp
More file actions
1974 lines (1707 loc) · 71.6 KB
/
Copy pathpl_main_glfw.cpp
File metadata and controls
1974 lines (1707 loc) · 71.6 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_glfw.c
* glfw platform backend
*/
/*
Index of this file:
// [SECTION] includes
// [SECTION] structs
// [SECTION] globals
// [SECTION] forward declarations
// [SECTION] internal enums
// [SECTION] entry point
// [SECTION] helper implementations
// [SECTION] window ext
// [SECTION] library ext
// [SECTION] clipboard api
// [SECTION] threads ext
// [SECTION] unity build
*/
//-----------------------------------------------------------------------------
// [SECTION] includes
//-----------------------------------------------------------------------------
#include <float.h>
#include "pl_internal.h"
#include "pl_ds.h"
#include "pl_string.h"
// 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"
//-----------------------------------------------------------------------------
// [SECTION] structs
//-----------------------------------------------------------------------------
#ifdef _WIN32
typedef struct _plSharedLibrary
{
bool bValid;
uint32_t uTempIndex;
char acFileExtension[16]; // default: "dll"
char acName[PL_MAX_NAME_LENGTH]; // i.e. "app"
char acPath[PL_MAX_PATH_LENGTH]; // i.e. "app.dll" or "../out/app.dll"
char acDirectory[PL_MAX_PATH_LENGTH]; // i.e. "./" or "../out/"
char acTransitionalPath[PL_MAX_PATH_LENGTH];
char acLockFile[PL_MAX_PATH_LENGTH];
plLibraryDesc tDesc;
HMODULE tHandle;
FILETIME tLastWriteTime;
} plSharedLibrary;
const char* gpcLibraryExtension = "dll";
const char* gpcLibraryPrefix = "";
#elif defined(__APPLE__)
typedef struct _plSharedLibrary
{
bool bValid;
uint32_t uTempIndex;
char acFileExtension[16]; // default: "dylib"
char acName[PL_MAX_NAME_LENGTH]; // i.e. "app"
char acPath[PL_MAX_PATH_LENGTH]; // i.e. "app.dylib" or "../out/app.dylib"
char acDirectory[PL_MAX_PATH_LENGTH]; // i.e. "./" or "../out/"
char acTransitionalPath[PL_MAX_PATH_LENGTH];
char acLockFile[PL_MAX_PATH_LENGTH];
plLibraryDesc tDesc;
void* handle;
struct timespec tLastWriteTime;
} plSharedLibrary;
const char* gpcLibraryExtension = "dylib";
const char* gpcLibraryPrefix = "lib";
#else // linux
typedef struct _plSharedLibrary
{
bool bValid;
uint32_t uTempIndex;
char acFileExtension[16]; // default: "so"
char acName[PL_MAX_NAME_LENGTH]; // i.e. "app"
char acPath[PL_MAX_PATH_LENGTH]; // i.e. "app.so" or "../out/app.so"
char acDirectory[PL_MAX_PATH_LENGTH]; // i.e. "./" or "../out/"
char acTransitionalPath[PL_MAX_PATH_LENGTH];
char acLockFile[PL_MAX_PATH_LENGTH];
plLibraryDesc tDesc;
void* handle;
time_t tLastWriteTime;
} plSharedLibrary;
const char* gpcLibraryExtension = "so";
const char* gpcLibraryPrefix = "lib";
#endif
//-----------------------------------------------------------------------------
// [SECTION] globals
//-----------------------------------------------------------------------------
#ifdef _WIN32
bool gbFirstRun = true;
bool gbEnableVirtualTerminalProcessing = true;
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)
{
PL_ASSERT(false && "clock_gettime() failed");
}
uint64_t nsec_count = ts.tv_nsec + ts.tv_sec * 1e9;
return (double)nsec_count / gdFrequency;
}
#endif
// glfw
GLFWwindow* ptGlfwWindow;
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] internal enums
//-----------------------------------------------------------------------------
enum _plWindowInternalFlags
{
PL_WINDOW_INTERNAL_FLAG_NONE = 0,
PL_WINDOW_INTERNAL_FLAG_MAXIMIZE_REQUESTED = 1 << 0,
PL_WINDOW_INTERNAL_FLAG_MINIMIZE_REQUESTED = 1 << 1,
PL_WINDOW_INTERNAL_FLAG_RESIZE_REQUESTED = 1 << 2,
PL_WINDOW_INTERNAL_FLAG_FULL_SCREEN_REQUESTED = 1 << 3,
};
//-----------------------------------------------------------------------------
// [SECTION] entry point
//-----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
const char* pcAppName = "app";
for(int i = 1; i < argc; i++)
{
if(strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--app") == 0)
{
pcAppName = argv[i + 1];
i++;
}
else if(strcmp(argv[i], "-hr") == 0 || strcmp(argv[i], "--hot-reload") == 0)
{
gbHotReloadActive = true;
}
else if(strcmp(argv[i], "--version") == 0)
{
printf("\nPilot Light - light weight game engine\n\n");
printf("Version: %s\n", PILOT_LIGHT_VERSION_STRING);
#ifdef PL_CONFIG_DEBUG
printf("Config: debug (glfw)\n\n");
#endif
#ifdef PL_CONFIG_RELEASE
printf("Config: release (glfw)\n\n");
#endif
return 0;
}
else if(strcmp(argv[i], "--apis") == 0)
{
plVersion tWindowExtVersion = plWindowI_version;
plVersion tLibraryVersion = plLibraryI_version;
plVersion tDataRegistryVersion = plDataRegistryI_version;
plVersion tExtensionRegistryVersion = plExtensionRegistryI_version;
plVersion tIOIVersion = plIOI_version;
plVersion tMemoryIVersion = plMemoryI_version;
printf("\nPilot Light - light weight game engine\n\n");
printf("Version: v%s\n", PILOT_LIGHT_VERSION_STRING);
#ifdef PL_CONFIG_DEBUG
printf("Config: debug experimental\n\n");
#endif
#ifdef PL_CONFIG_RELEASE
printf("Config: release experimental\n\n");
#endif
printf("~~~~~~~~API Versions~~~~~~~~~\n\n");
printf("plWindowI: v%u.%u.%u\n", tWindowExtVersion.uMajor, tWindowExtVersion.uMinor, tWindowExtVersion.uPatch);
printf("plLibraryI: v%u.%u.%u\n", tLibraryVersion.uMajor, tLibraryVersion.uMinor, tLibraryVersion.uPatch);
printf("plDataRegistryI: v%u.%u.%u\n", tDataRegistryVersion.uMajor, tDataRegistryVersion.uMinor, tDataRegistryVersion.uPatch);
printf("plExtensionRegistryI: v%u.%u.%u\n", tExtensionRegistryVersion.uMajor, tExtensionRegistryVersion.uMinor, tExtensionRegistryVersion.uPatch);
printf("plIOI: v%u.%u.%u\n", tIOIVersion.uMajor, tIOIVersion.uMinor, tIOIVersion.uPatch);
printf("plMemoryI: v%u.%u.%u\n", tMemoryIVersion.uMajor, tMemoryIVersion.uMinor, tMemoryIVersion.uPatch);
return 0;
}
else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
printf("\nPilot Light - light weight game engine\n");
printf("Version: %s\n", PILOT_LIGHT_VERSION_STRING);
#ifdef PL_CONFIG_DEBUG
printf("Config: debug\n\n");
#endif
#ifdef PL_CONFIG_RELEASE
printf("Config: release\n\n");
#endif
printf("Usage: pilot_light.exe [options]\n\n");
printf("Options:\n");
printf("-h %s\n", "Displays this information.");
printf("--help %s\n", "Displays this information.");
printf("--version %s\n", "Displays Pilot Light version information.");
printf("--apis %s\n", "Displays embedded apis.");
printf("-a <app> %s\n", "Sets app to load. Default is 'editor'.");
printf("--app <app> %s\n", "Sets app to load. Default is 'editor'.");
printf("-hr %s\n", "Activates hot reloading.");
printf("--hot-reload %s\n", "Activates hot reloading.");
return 0;
}
}
// setup timers
#ifdef _WIN32
QueryPerformanceFrequency((LARGE_INTEGER*)&ilTicksPerSecond);
QueryPerformanceCounter((LARGE_INTEGER*)&ilTime);
#elif defined(__APPLE__)
#else // linux
// setup timers
static struct timespec ts;
if (clock_getres(CLOCK_MONOTONIC, &ts) != 0)
{
PL_ASSERT(false && "clock_getres() failed");
}
gdFrequency = 1e9/((double)ts.tv_nsec + (double)ts.tv_sec * (double)1e9);
gdTime = pl__get_linux_absolute_time();
#endif
// load core apis
pl__load_core_apis();
gptIOCtx = gptIOI->get_io();
gptIOCtx->bHotReloadActive = gbHotReloadActive;
// clipboard
gptIOCtx->set_clipboard_text_fn = [](void* pUnused, const char* text) { glfwSetClipboardString(nullptr, text); };
gptIOCtx->get_clipboard_text_fn = [](void* pUnused) { return glfwGetClipboardString(nullptr); };
// command line args
gptIOCtx->iArgc = argc;
gptIOCtx->apArgv = argv;
// 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;
}
glfwSetErrorCallback(pl_glfw_error_callback);
// setup glfw
if (!glfwInit())
return -1;
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);
// #if GLFW_HAS_NEW_CURSORS
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);
// #else
// atMouseCursors[PL_MOUSE_CURSOR_RESIZE_ALL] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
// atMouseCursors[PL_MOUSE_CURSOR_RESIZE_NESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
// atMouseCursors[PL_MOUSE_CURSOR_RESIZE_NWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
// atMouseCursors[PL_MOUSE_CURSOR_NOT_ALLOWED] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
// #endif
// load app library
const plLibraryI* ptLibraryApi = pl_get_api_latest(gptApiRegistry, plLibraryI);
plLibraryDesc tLibraryDesc = {};
tLibraryDesc.pcName = pcAppName;
tLibraryDesc.tFlags = PL_LIBRARY_FLAGS_RELOADABLE;
if(ptLibraryApi->load(tLibraryDesc, &gptAppLibrary))
{
#ifdef _WIN32
pl_app_load = (void* (__cdecl *)(const plApiRegistryI*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_load");
pl_app_shutdown = (void (__cdecl *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_shutdown");
pl_app_resize = (void (__cdecl *)(plWindow*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_resize");
pl_app_update = (void (__cdecl *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_update");
pl_app_info = (bool (__cdecl *)(const plApiRegistryI*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_info");
#else
pl_app_load = (void* (__attribute__(()) *)(const plApiRegistryI*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_load");
pl_app_shutdown = (void (__attribute__(()) *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_shutdown");
pl_app_resize = (void (__attribute__(()) *)(plWindow*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_resize");
pl_app_update = (void (__attribute__(()) *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_update");
pl_app_info = (bool (__attribute__(()) *)(const plApiRegistryI*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_info");
#endif
if(pl_app_info)
{
if(!pl_app_info(gptApiRegistry))
return 0;
}
gpUserData = pl_app_load(gptApiRegistry, NULL);
bool bApisFound = pl__check_apis();
if(!bApisFound)
return 3;
}
// main event loop
while (gptIOCtx->bRunning)
{
#if defined(__APPLE__)
@autoreleasepool
#endif
{
glfwPollEvents();
// queued window changes so swapchain remains valid for frame requesting changes
uint32_t uWindowCount = pl_sb_size(gsbtWindows);
for(uint32_t i = 0; i < uWindowCount; i++)
{
plWindow* ptWindow = gsbtWindows[i];
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
if(ptWindow->_tInternalFlags & PL_WINDOW_INTERNAL_FLAG_MAXIMIZE_REQUESTED)
{
ptWindow->_tInternalFlags &= ~PL_WINDOW_INTERNAL_FLAG_MAXIMIZE_REQUESTED;
glfwMaximizeWindow(ptGlfwWindow);
}
if(ptWindow->_tInternalFlags & PL_WINDOW_INTERNAL_FLAG_MINIMIZE_REQUESTED)
{
ptWindow->_tInternalFlags &= ~PL_WINDOW_INTERNAL_FLAG_MINIMIZE_REQUESTED;
glfwIconifyWindow(ptGlfwWindow);
}
if(ptWindow->_tInternalFlags & PL_WINDOW_INTERNAL_FLAG_RESIZE_REQUESTED)
{
ptWindow->_tInternalFlags &= ~PL_WINDOW_INTERNAL_FLAG_RESIZE_REQUESTED;
bool bIsFullScreen = glfwGetWindowMonitor(ptGlfwWindow) != NULL;
if(bIsFullScreen)
{
glfwSetWindowMonitor(ptGlfwWindow, NULL, 50, 50, (int)ptWindow->_uRequestedWidth, ptWindow->_uRequestedHeight, GLFW_DONT_CARE);
glfwSetWindowAttrib(ptGlfwWindow, GLFW_RESIZABLE, GLFW_TRUE);
glfwSetWindowAttrib(ptGlfwWindow, GLFW_DECORATED, GLFW_TRUE);
glfwSetWindowAttrib(ptGlfwWindow, GLFW_FLOATING, GLFW_FALSE);
}
else
glfwSetWindowSize(ptGlfwWindow, (int)ptWindow->_uRequestedWidth, ptWindow->_uRequestedHeight);
}
if(ptWindow->_tInternalFlags & PL_WINDOW_INTERNAL_FLAG_FULL_SCREEN_REQUESTED)
{
ptWindow->_tInternalFlags &= ~PL_WINDOW_INTERNAL_FLAG_FULL_SCREEN_REQUESTED;
glfwSetWindowAttrib(ptGlfwWindow, GLFW_DECORATED, GLFW_FALSE);
glfwSetWindowAttrib(ptGlfwWindow, GLFW_FLOATING, GLFW_FALSE);
glfwSetWindowPos(ptGlfwWindow, 0, 0);
int iWidth = 500;
int iHeight = 500;
GLFWmonitor* ptMonitor = NULL;
// When fullscreen mode is active use screen size of the target monitor and
// ignore values present in the window description.
// If target monitor cannot be resolved then fallback to minimum viable size.
int iMonitorCount = 0;
GLFWmonitor **pptMonitors = glfwGetMonitors(&iMonitorCount);
if(ptWindow->_iRequestedMonitor < 0)
ptMonitor = glfwGetPrimaryMonitor();
else if(iMonitorCount > 0 && ptWindow->_iRequestedMonitor < iMonitorCount)
{
ptMonitor = pptMonitors[ptWindow->_iRequestedMonitor];
}
if (ptMonitor)
{
const GLFWvidmode *ptMode = glfwGetVideoMode(ptMonitor);
if (ptMode)
{
iWidth = (int)ptMode->width;
iHeight = (int)ptMode->height;
}
}
glfwSetWindowMonitor(ptGlfwWindow, ptMonitor, 0, 0, iWidth, iHeight, GLFW_DONT_CARE);
glfwSetWindowSize(ptGlfwWindow, iWidth, iHeight);
}
}
// reload library
if(gbHotReloadActive && ptLibraryApi->has_changed(gptAppLibrary))
{
pl_reload_library(gptAppLibrary);
#ifdef _WIN32
pl_app_load = (void* (__cdecl *)(const plApiRegistryI*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_load");
pl_app_shutdown = (void (__cdecl *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_shutdown");
pl_app_resize = (void (__cdecl *)(plWindow*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_resize");
pl_app_update = (void (__cdecl *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_update");
pl_app_info = (bool (__cdecl *)(const plApiRegistryI*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_info");
#else
pl_app_load = (void* (__attribute__(()) *)(const plApiRegistryI*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_load");
pl_app_shutdown = (void (__attribute__(()) *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_shutdown");
pl_app_resize = (void (__attribute__(()) *)(plWindow*, void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_resize");
pl_app_update = (void (__attribute__(()) *)(void*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_update");
pl_app_info = (bool (__attribute__(()) *)(const plApiRegistryI*)) ptLibraryApi->load_function(gptAppLibrary, "pl_app_info");
#endif
pl__handle_extension_reloads();
gpUserData = pl_app_load(gptApiRegistry, gpUserData);
}
pl__garbage_collect_data_reg();
// update time step
#ifdef _WIN32
INT64 ilCurrentTime = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&ilCurrentTime);
gptIOCtx->fDeltaTime = (float)(ilCurrentTime - ilTime) / ilTicksPerSecond;
ilTime = ilCurrentTime;
#elif defined(__APPLE__)
if(gtTime == 0.0)
gtTime = pl__get_absolute_time();
double dCurrentTime = pl__get_absolute_time();
gptIOCtx->fDeltaTime = (float)(dCurrentTime - gtTime);
gtTime = dCurrentTime;
#else // linux
const double dCurrentTime = pl__get_linux_absolute_time();
gptIOCtx->fDeltaTime = (float)(dCurrentTime - gdTime);
gdTime = dCurrentTime;
#endif
// start imgui glfw frame
ImGui_ImplGlfw_NewFrame();
// update mouse cursor
plMouseCursor tCursor0 = gptIOCtx->tNextCursor;
if(tCursor0 != PL_MOUSE_CURSOR_ARROW)
{
glfwSetCursor(ptGlfwWindow, atMouseCursors[tCursor0] ? atMouseCursors[tCursor0] : atMouseCursors[PL_MOUSE_CURSOR_ARROW]);
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
gptIOCtx->tNextCursor = PL_MOUSE_CURSOR_ARROW;
gptIOCtx->bCursorChanged = false;
// handle retina displays
#ifdef __APPLE__
float fCurrentScale = nswin.screen.backingScaleFactor;
layer.contentsScale = fCurrentScale;
int width, height;
glfwGetFramebufferSize(ptGlfwWindow, &width, &height);
layer.drawableSize = CGSizeMake(width, height);
gptIOCtx->pBackendPlatformData = layer;
// Setup display size (every frame to accommodate for window resizing)
int w, h;
glfwGetWindowSize(ptGlfwWindow, &w, &h);
if (w > 0 && h > 0)
{
bool bResize = false;
if(w != gptIOCtx->tMainViewportSize.x || h != gptIOCtx->tMainViewportSize.y)
bResize = true;
else if(fCurrentScale != gptIOCtx->tMainFramebufferScale.x || fCurrentScale != gptIOCtx->tMainFramebufferScale.y )
bResize = true;
if(bResize)
{
gptIOCtx->tMainViewportSize.x = w;
gptIOCtx->tMainViewportSize.y = h;
gptIOCtx->tMainFramebufferScale.x = fCurrentScale;
gptIOCtx->tMainFramebufferScale.y = fCurrentScale;
pl_app_resize(gptMainWindow, gpUserData);
}
}
#else
int width, height;
glfwGetFramebufferSize(ptGlfwWindow, &width, &height);
// Setup display size (every frame to accommodate for window resizing)
int w, h;
glfwGetWindowSize(ptGlfwWindow, &w, &h);
if (w > 0 && h > 0)
{
bool bResize = false;
if((float)w != gptIOCtx->tMainViewportSize.x || (float)h != gptIOCtx->tMainViewportSize.y)
bResize = true;
if(bResize)
{
gptIOCtx->tMainViewportSize.x = (float)w;
gptIOCtx->tMainViewportSize.y = (float)h;
gptIOCtx->tMainFramebufferScale.x = 1.0f;
gptIOCtx->tMainFramebufferScale.y = 1.0f;
pl_app_resize(gptMainWindow, gpUserData);
}
}
#endif
if(!gptIOCtx->bViewportMinimized)
{
pl_app_update(gpUserData);
pl__handle_extension_reloads();
}
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_ICONIFIED) != 0)
{
#ifdef _WIN32
::Sleep(10);
#else
usleep(10 * 1000);
#endif
continue;
}
if(gbApisDirty)
pl__check_apis();
#if defined(__APPLE__)
#endif
}
}
// app cleanup
pl_app_shutdown(gpUserData);
// unload extensions & APIs
pl__unload_all_extensions();
pl__unload_core_apis();
// cleanup app library
if(gptAppLibrary)
{
PL_FREE(gptAppLibrary);
}
// check memory leaks
pl__check_for_leaks();
// shutdown imgui
if(ptGlfwWindow)
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwTerminate();
}
//-----------------------------------------------------------------------------
// [SECTION] window ext
//-----------------------------------------------------------------------------
plWindowResult
pl_create_window(plWindowDesc tDesc, plWindow** pptWindowOut)
{
plWindow* ptWindow = (plWindow*)malloc(sizeof(plWindow));
memset(ptWindow, 0, sizeof(plWindow));
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
int iWidth = (int)tDesc.uWidth;
int iHeight = (int)tDesc.uHeight;
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
glfwWindowHint(GLFW_POSITION_X, tDesc.iXPos);
glfwWindowHint(GLFW_POSITION_Y, tDesc.iYPos);
ptGlfwWindow = glfwCreateWindow(iWidth, iHeight, tDesc.pcTitle, NULL, NULL);
ptWindow->_pBackendData2 = ptGlfwWindow;
if(gptMainWindow == nullptr)
gptMainWindow = ptWindow;
glfwSetMouseButtonCallback(ptGlfwWindow, pl_glfw_mouse_button_callback);
glfwSetCursorPosCallback(ptGlfwWindow, pl_glfw_mouse_pos_callback);
glfwSetCursorEnterCallback(ptGlfwWindow, pl_glfw_cursor_enter_callback);
glfwSetScrollCallback(ptGlfwWindow, pl_glfw_scroll_callback);
glfwSetCharCallback(ptGlfwWindow, pl_glfw_char_callback);
glfwSetKeyCallback(ptGlfwWindow, pl_glfw_key_callback);
glfwSetWindowFocusCallback(ptGlfwWindow, pl_glfw_window_focus_callback);
glfwSetWindowSizeCallback(ptGlfwWindow, pl_glfw_size_callback);
glfwSetWindowIconifyCallback(ptGlfwWindow, pl_glfw_window_iconified_callback);
glfwSetWindowCloseCallback(ptGlfwWindow, pl_glfw_window_close_callback);
#ifdef PL_METAL_BACKEND
if(pl_sb_size(gsbtWindows) == 0)
ImGui_ImplGlfw_InitForOther(ptGlfwWindow, true);
#else
if(pl_sb_size(gsbtWindows) == 0)
ImGui_ImplGlfw_InitForVulkan(ptGlfwWindow, true);
#endif
#ifdef _WIN32
HWND tHandle = glfwGetWin32Window(ptGlfwWindow);
ptWindow->_pBackendData = tHandle;
#elif defined(__APPLE__)
device = MTLCreateSystemDefaultDevice();
gptIOCtx->pBackendPlatformData = device;
nswin = glfwGetCocoaWindow(ptGlfwWindow);
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
struct plPlatformData
{
uint32_t header;
Display* dpy;
Window window;
};
static plPlatformData tPlatformData = {UINT32_MAX};
tPlatformData.dpy = glfwGetX11Display();
tPlatformData.window = glfwGetX11Window(ptGlfwWindow);
ptWindow->_pBackendData = &tPlatformData;
#endif
*pptWindowOut = ptWindow;
pl_sb_push(gsbtWindows, ptWindow);
return PL_WINDOW_RESULT_SUCCESS;
}
void
pl_destroy_window(plWindow* ptWindow)
{
free(ptWindow);
}
bool
pl_set_window_attribute(plWindow* ptWindow, plWindowAttribute tAttribute, const plWindowAttributeValue* ptValue)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
switch (tAttribute)
{
case PL_WINDOW_ATTRIBUTE_SIZE:
{
ptWindow->_tInternalFlags |= PL_WINDOW_INTERNAL_FLAG_RESIZE_REQUESTED;
// ptWindow->_tInternalFlags |= PL_WINDOW_INTERNAL_FLAG_ATTRIBUTE_CHANGE_REQUESTED; // incase full screen
ptWindow->_uRequestedWidth = ptValue->tuVec2.x;
ptWindow->_uRequestedHeight = ptValue->tuVec2.y;
glfwGetWindowPos(ptGlfwWindow, &ptWindow->_iXPos, &ptWindow->_iYPos);
break;
}
case PL_WINDOW_ATTRIBUTE_POSITION:
{
glfwSetWindowPos(ptGlfwWindow, ptValue->tiVec2.x, ptValue->tiVec2.y);
break;
}
case PL_WINDOW_ATTRIBUTE_MAXIMIZED:
ptWindow->_tInternalFlags |= PL_WINDOW_INTERNAL_FLAG_MAXIMIZE_REQUESTED;
break;
case PL_WINDOW_ATTRIBUTE_MINIMIZED:
if(ptValue->bValue)
ptWindow->_tInternalFlags |= PL_WINDOW_INTERNAL_FLAG_MINIMIZE_REQUESTED;
else
{
ptWindow->_tInternalFlags &= ~PL_WINDOW_INTERNAL_FLAG_MINIMIZE_REQUESTED;
glfwRestoreWindow(ptGlfwWindow);
}
break;
case PL_WINDOW_ATTRIBUTE_VISIBLE:
if(ptValue->bValue)
glfwShowWindow(ptGlfwWindow);
else
glfwHideWindow(ptGlfwWindow);
break;
case PL_WINDOW_ATTRIBUTE_FOCUSED:
glfwFocusWindow(ptGlfwWindow);
break;
case PL_WINDOW_ATTRIBUTE_SIZE_LIMITS:
glfwSetWindowSizeLimits(ptGlfwWindow, (int)ptValue->tuVec4.x, (int)ptValue->tuVec4.y, (int)ptValue->tuVec4.z, (int)ptValue->tuVec4.w);
break;
default:
break;
}
return true;
}
bool
pl_get_window_attribute(plWindow* ptWindow, plWindowAttribute tAttribute, plWindowAttributeValue* ptValue)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
switch (tAttribute)
{
case PL_WINDOW_ATTRIBUTE_SIZE:
{
int iWidth = 0;
int iHeight = 0;
glfwGetWindowSize(ptGlfwWindow, &iWidth, &iHeight);
ptValue->tuVec2.x = (uint32_t)iWidth;
ptValue->tuVec2.y = (uint32_t)iHeight;
break;
}
case PL_WINDOW_ATTRIBUTE_POSITION:
{
glfwGetWindowPos(ptGlfwWindow, &ptValue->tiVec2.x, &ptValue->tiVec2.y);
break;
}
case PL_WINDOW_ATTRIBUTE_RESIZABLE:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_RESIZABLE))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_FOCUSED:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_FOCUSED))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_DECORATED:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_DECORATED))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_TOP_MOST:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_FLOATING))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_HOVERED:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_HOVERED))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_MAXIMIZED:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_MAXIMIZED))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_MINIMIZED:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_ICONIFIED))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_VISIBLE:
{
if (glfwGetWindowAttrib(ptGlfwWindow, GLFW_VISIBLE))
ptValue->bValue = true;
else
ptValue->bValue = false;
break;
}
case PL_WINDOW_ATTRIBUTE_SIZE_LIMITS:
return false;
default:
break;
}
return true;
}
bool
pl_set_cursor_mode(plWindow* ptWindow, plCursorMode tMode)
{
GLFWwindow* ptGlfwWindow = (GLFWwindow*)ptWindow->_pBackendData2;
switch(tMode)
{
case PL_CURSOR_MODE_NORMAL:
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
break;
case PL_CURSOR_MODE_HIDDEN:
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
break;
case PL_CURSOR_MODE_CAPTURED:
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_CAPTURED);
break;
case PL_CURSOR_MODE_DISABLED:
glfwSetInputMode(ptGlfwWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
break;
default:
return false;
break;
}
return true;
}