From d2160c29d139083c8c9ef0ab041c8bfa977d62a9 Mon Sep 17 00:00:00 2001 From: slime Date: Wed, 5 Oct 2022 21:42:26 -0300 Subject: [PATCH] iOS: implement SDL_GetWindowSizeInPixels. --- src/video/uikit/SDL_uikitvideo.m | 1 + src/video/uikit/SDL_uikitwindow.h | 1 + src/video/uikit/SDL_uikitwindow.m | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index 2b014bcca..4e8a57755 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -98,6 +98,7 @@ UIKit_CreateDevice(void) device->GetWindowWMInfo = UIKit_GetWindowWMInfo; device->GetDisplayUsableBounds = UIKit_GetDisplayUsableBounds; device->GetDisplayDPI = UIKit_GetDisplayDPI; + device->GetWindowSizeInPixels = UIKit_GetWindowSizeInPixels; #if SDL_IPHONE_KEYBOARD device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport; diff --git a/src/video/uikit/SDL_uikitwindow.h b/src/video/uikit/SDL_uikitwindow.h index 65dbc875b..7ca9b475e 100644 --- a/src/video/uikit/SDL_uikitwindow.h +++ b/src/video/uikit/SDL_uikitwindow.h @@ -36,6 +36,7 @@ extern void UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDispl extern void UIKit_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed); extern void UIKit_UpdatePointerLock(_THIS, SDL_Window * window); extern void UIKit_DestroyWindow(_THIS, SDL_Window * window); +extern void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h); extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info); diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index 8a923fb78..433c80ee1 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -369,6 +369,25 @@ UIKit_DestroyWindow(_THIS, SDL_Window * window) window->driverdata = NULL; } +void +UIKit_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h) +{ @autoreleasepool +{ + SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata; + UIView *view = windata.viewcontroller.view; + CGSize size = view.bounds.size; + CGFloat scale = 1.0; + + if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { + scale = windata.uiwindow.screen.nativeScale; + } + + /* Integer truncation of fractional values matches SDL_uikitmetalview and + * SDL_uikitopenglview. */ + *w = size.width * scale; + *h = size.height * scale; +}} + SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) {