mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Fixes Bugzilla #3223.
This commit is contained in:
parent
1d1ba58f28
commit
416d046663
@ -37,6 +37,7 @@ extern void Cocoa_InitModes(_THIS);
|
||||
extern int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
|
||||
extern int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
|
||||
extern void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
|
||||
extern int Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hpdi, float * vdpi);
|
||||
extern int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
extern void Cocoa_QuitModes(_THIS);
|
||||
|
||||
|
@ -374,6 +374,24 @@ Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
|
||||
{
|
||||
const float MM_IN_INCH = 25.4f;
|
||||
|
||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||
|
||||
CGSize displaySize = CGDisplayScreenSize(data->display);
|
||||
size_t pixelWidth = CGDisplayPixelsWide(data->display);
|
||||
size_t pixelHeight = CGDisplayPixelsHigh(data->display);
|
||||
|
||||
*ddpi = SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH);
|
||||
*hdpi = pixelWidth * MM_IN_INCH / displaySize.width;
|
||||
*vdpi = pixelHeight * MM_IN_INCH / displaySize.height;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||
{
|
||||
|
@ -74,6 +74,7 @@ Cocoa_CreateDevice(int devindex)
|
||||
device->VideoQuit = Cocoa_VideoQuit;
|
||||
device->GetDisplayBounds = Cocoa_GetDisplayBounds;
|
||||
device->GetDisplayUsableBounds = Cocoa_GetDisplayUsableBounds;
|
||||
device->GetDisplayDPI = Cocoa_GetDisplayDPI;
|
||||
device->GetDisplayModes = Cocoa_GetDisplayModes;
|
||||
device->SetDisplayMode = Cocoa_SetDisplayMode;
|
||||
device->PumpEvents = Cocoa_PumpEvents;
|
||||
|
@ -51,11 +51,18 @@ main(int argc, char *argv[])
|
||||
for (dpy = 0; dpy < num_displays; dpy++) {
|
||||
const int num_modes = SDL_GetNumDisplayModes(dpy);
|
||||
SDL_Rect rect = { 0, 0, 0, 0 };
|
||||
float ddpi, hdpi, vdpi;
|
||||
int m;
|
||||
|
||||
SDL_GetDisplayBounds(dpy, &rect);
|
||||
SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
|
||||
|
||||
if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
|
||||
} else {
|
||||
SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
|
||||
}
|
||||
|
||||
if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user