Skip to content

Commit 2b59e74

Browse files
authored
Implement Android-specific functions (#4769)
`GetWindowScaleDPI` and monitor physical dimensions
1 parent c647d33 commit 2b59e74

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/platforms/rcore_android.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,21 @@ int GetMonitorHeight(int monitor)
460460
}
461461

462462
// Get selected monitor physical width in millimetres
463+
// NOTE: It seems to return a slightly underestimated value on some devices
463464
int GetMonitorPhysicalWidth(int monitor)
464465
{
465-
TRACELOG(LOG_WARNING, "GetMonitorPhysicalWidth() not implemented on target platform");
466-
return 0;
466+
int widthPixels = ANativeWindow_getWidth(platform.app->window);
467+
float dpi = AConfiguration_getDensity(platform.app->config);
468+
return (widthPixels/dpi)*25.4f;
467469
}
468470

469471
// Get selected monitor physical height in millimetres
472+
// NOTE: It seems to return a slightly underestimated value on some devices
470473
int GetMonitorPhysicalHeight(int monitor)
471474
{
472-
TRACELOG(LOG_WARNING, "GetMonitorPhysicalHeight() not implemented on target platform");
473-
return 0;
475+
int heightPixels = ANativeWindow_getHeight(platform.app->window);
476+
float dpi = AConfiguration_getDensity(platform.app->config);
477+
return (heightPixels/dpi)*25.4f;
474478
}
475479

476480
// Get selected monitor refresh rate
@@ -497,8 +501,9 @@ Vector2 GetWindowPosition(void)
497501
// Get window scale DPI factor for current monitor
498502
Vector2 GetWindowScaleDPI(void)
499503
{
500-
TRACELOG(LOG_WARNING, "GetWindowScaleDPI() not implemented on target platform");
501-
return (Vector2){ 1.0f, 1.0f };
504+
int density = AConfiguration_getDensity(platform.app->config);
505+
float scale = (float)density/160;
506+
return (Vector2){ scale, scale };
502507
}
503508

504509
// Set clipboard text content

0 commit comments

Comments
 (0)