25
25
#ifdef _WIN32
26
26
# include < windows.h>
27
27
# include < SDL_syswm.h>
28
+ # include < dwmapi.h>
28
29
#elif defined(__ANDROID__)
29
30
# include < jni.h>
30
31
# include < SDL_system.h>
@@ -118,6 +119,19 @@ static uint32_t SelectFormat(const SDL_RendererInfo& rinfo, bool print_all) {
118
119
return current_fmt;
119
120
}
120
121
122
+ #ifdef _WIN32
123
+ HWND GetWindowHandle (SDL_Window* window) {
124
+ SDL_SysWMinfo wminfo;
125
+ SDL_VERSION (&wminfo.version )
126
+ SDL_bool success = SDL_GetWindowWMInfo (window, &wminfo);
127
+
128
+ if (success < 0 )
129
+ Output::Error (" Wrong SDL version" );
130
+
131
+ return wminfo.info .win .window ;
132
+ }
133
+ #endif
134
+
121
135
static int FilterUntilFocus (const SDL_Event* evnt);
122
136
123
137
#if defined(USE_KEYBOARD) && defined(SUPPORT_KEYBOARD)
@@ -354,8 +368,8 @@ bool Sdl2Ui::RefreshDisplayMode() {
354
368
window.size_changed = true ;
355
369
356
370
auto window_sg = lcf::makeScopeGuard ([&]() {
357
- SDL_DestroyWindow (sdl_window);
358
- sdl_window = nullptr ;
371
+ SDL_DestroyWindow (sdl_window);
372
+ sdl_window = nullptr ;
359
373
});
360
374
361
375
SetAppIcon ();
@@ -415,6 +429,13 @@ bool Sdl2Ui::RefreshDisplayMode() {
415
429
return false ;
416
430
}
417
431
432
+ #ifdef _WIN32
433
+ HWND window = GetWindowHandle (sdl_window);
434
+ // Not using the enum names because this will fail to build when not using a recent Windows 11 SDK
435
+ int window_rounding = 1 ; // DWMWCP_DONOTROUND
436
+ DwmSetWindowAttribute (window, 33 /* DWMWA_WINDOW_CORNER_PREFERENCE */ , &window_rounding, sizeof (window_rounding));
437
+ #endif
438
+
418
439
renderer_sg.Dismiss ();
419
440
window_sg.Dismiss ();
420
441
} else {
@@ -647,15 +668,10 @@ void Sdl2Ui::SetTitle(const std::string &title) {
647
668
}
648
669
649
670
bool Sdl2Ui::ShowCursor (bool flag) {
650
- #ifdef __WINRT__
651
- // Prevent cursor hide in WinRT because it is hidden everywhere while the app runs...
652
- return flag;
653
- #else
654
671
bool temp_flag = cursor_visible;
655
672
cursor_visible = flag;
656
673
SDL_ShowCursor (flag ? SDL_ENABLE : SDL_DISABLE);
657
674
return temp_flag;
658
- #endif
659
675
}
660
676
661
677
void Sdl2Ui::ProcessEvent (SDL_Event &evnt) {
@@ -940,29 +956,33 @@ void Sdl2Ui::ProcessFingerEvent(SDL_Event& evnt) {
940
956
// We currently ignore swipe gestures
941
957
// A finger touch is detected when the fingers go up a brief delay after going down
942
958
if (evnt.type == SDL_FINGERDOWN) {
943
- int finger = evnt.tfinger .fingerId ;
944
- if (finger < static_cast <int >(finger_input.size ())) {
945
- auto & fi = touch_input[finger];
946
- fi.position .x = (evnt.tfinger .x - viewport.x ) * main_surface->width () / xw;
947
- fi.position .y = (evnt.tfinger .y - viewport.y ) * main_surface->height () / yh;
959
+ auto fi = std::find_if (touch_input.begin (), touch_input.end (), [&](const auto & input) {
960
+ return input.id == -1 ;
961
+ });
962
+ if (fi == touch_input.end ()) {
963
+ // already tracking 5 fingers
964
+ return ;
965
+ }
948
966
949
967
#ifdef EMSCRIPTEN
950
- double display_ratio = emscripten_get_device_pixel_ratio ();
951
- fi. position . x = (evnt.tfinger .x * display_ratio - viewport.x ) * main_surface->width () / xw;
952
- fi. position . y = (evnt.tfinger .y * display_ratio - viewport.y ) * main_surface->height () / yh;
968
+ double display_ratio = emscripten_get_device_pixel_ratio ();
969
+ int x = (evnt.tfinger .x * display_ratio - viewport.x ) * main_surface->width () / xw;
970
+ int y = (evnt.tfinger .y * display_ratio - viewport.y ) * main_surface->height () / yh;
953
971
#else
954
- fi. position . x = (evnt.tfinger .x - viewport.x ) * main_surface->width () / xw;
955
- fi. position . y = (evnt.tfinger .y - viewport.y ) * main_surface->height () / yh;
972
+ int x = (evnt.tfinger .x - viewport.x ) * main_surface->width () / xw;
973
+ int y = (evnt.tfinger .y - viewport.y ) * main_surface->height () / yh;
956
974
#endif
957
975
958
- fi.pressed = true ;
959
- }
976
+ fi->Down (evnt.tfinger .fingerId , x, y);
960
977
} else if (evnt.type == SDL_FINGERUP) {
961
- int finger = evnt.tfinger .fingerId ;
962
- if (finger < static_cast <int >(finger_input.size ())) {
963
- auto & fi = touch_input[finger];
964
- fi.pressed = false ;
978
+ auto fi = std::find_if (touch_input.begin (), touch_input.end (), [&](const auto & input) {
979
+ return input.id == evnt.tfinger .fingerId ;
980
+ });
981
+ if (fi == touch_input.end ()) {
982
+ // Finger is not tracked
983
+ return ;
965
984
}
985
+ fi->Up ();
966
986
}
967
987
#else
968
988
/* unused */
@@ -971,17 +991,9 @@ void Sdl2Ui::ProcessFingerEvent(SDL_Event& evnt) {
971
991
}
972
992
973
993
void Sdl2Ui::SetAppIcon () {
974
- #if defined(__WINRT__) || defined( __MORPHOS__)
994
+ #if defined(__MORPHOS__)
975
995
// do nothing
976
996
#elif defined(_WIN32)
977
- SDL_SysWMinfo wminfo;
978
- SDL_VERSION (&wminfo.version )
979
- SDL_bool success = SDL_GetWindowWMInfo (sdl_window, &wminfo);
980
-
981
- if (success < 0 )
982
- Output::Error (" Wrong SDL version" );
983
-
984
- HWND window;
985
997
HINSTANCE handle = GetModuleHandle (NULL );
986
998
HICON icon = LoadIcon (handle, MAKEINTRESOURCE (23456 ));
987
999
HICON icon_small = (HICON) LoadImage (handle, MAKEINTRESOURCE (23456 ), IMAGE_ICON,
@@ -990,7 +1002,7 @@ void Sdl2Ui::SetAppIcon() {
990
1002
if (icon == NULL || icon_small == NULL )
991
1003
Output::Warning (" Could not load window icon." );
992
1004
993
- window = wminfo. info . win . window ;
1005
+ HWND window = GetWindowHandle (sdl_window) ;
994
1006
SetClassLongPtr (window, GCLP_HICON, (LONG_PTR) icon);
995
1007
SetClassLongPtr (window, GCLP_HICONSM, (LONG_PTR) icon_small);
996
1008
#else
0 commit comments