GUI: detect UI scale factor when moving window
This commit is contained in:
parent
9caa2f38f4
commit
a882d7bcf2
6 changed files with 107 additions and 25 deletions
|
|
@ -42,14 +42,23 @@ typedef int (*XDS)(void*);
|
|||
typedef int (*XDW)(void*,int);
|
||||
#endif
|
||||
|
||||
double getScaleFactor(const char* driverHint) {
|
||||
double getScaleFactor(const char* driverHint, void* windowHint) {
|
||||
double ret=1.0;
|
||||
|
||||
// Windows
|
||||
#ifdef _WIN32
|
||||
POINT nullPoint;
|
||||
nullPoint.x=-1;
|
||||
nullPoint.y=-1;
|
||||
if (windowHint!=NULL) {
|
||||
int px=0;
|
||||
int py=0;
|
||||
|
||||
SDL_GetWindowPosition((SDL_Window*)windowHint,&px,&py);
|
||||
nullPoint.x=px;
|
||||
nullPoint.y=py;
|
||||
} else {
|
||||
nullPoint.x=-1;
|
||||
nullPoint.y=-1;
|
||||
}
|
||||
HMONITOR disp=MonitorFromPoint(nullPoint,MONITOR_DEFAULTTOPRIMARY);
|
||||
|
||||
if (disp==NULL) {
|
||||
|
|
@ -93,12 +102,30 @@ double getScaleFactor(const char* driverHint) {
|
|||
return ret;
|
||||
#endif
|
||||
|
||||
// macOS - backingScaleFactor
|
||||
// macOS
|
||||
#ifdef __APPLE__
|
||||
if (driverHint==NULL) {
|
||||
return getMacDPIScale();
|
||||
} else if (strcmp(driverHint,"cocoa")==0 || strcmp(driverHint,"uikit")==0) {
|
||||
return getMacDPIScale();
|
||||
return getMacDPIScale(NULL,false);
|
||||
} else if (strcmp(driverHint,"cocoa")==0) {
|
||||
void* nsWindow=NULL;
|
||||
SDL_SysWMinfo wmInfo;
|
||||
if (windowHint!=NULL) {
|
||||
SDL_VERSION(&info.version)
|
||||
if (SDL_GetWindowWMInfo((SDL_Window*)windowHint,&wmInfo)==SDL_TRUE) {
|
||||
nsWindow=wmInfo.cocoa.window;
|
||||
}
|
||||
}
|
||||
return getMacDPIScale(nsWindow,false);
|
||||
} else if (strcmp(driverHint,"uikit")==0) {
|
||||
void* uiWindow=NULL;
|
||||
SDL_SysWMinfo wmInfo;
|
||||
if (windowHint!=NULL) {
|
||||
SDL_VERSION(&info.version)
|
||||
if (SDL_GetWindowWMInfo((SDL_Window*)windowHint,&wmInfo)==SDL_TRUE) {
|
||||
uiWindow=wmInfo.cocoa.window;
|
||||
}
|
||||
}
|
||||
return getMacDPIScale(uiWindow,true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue