2012-04-10 11:59:57 +02:00
|
|
|
#include "base/display.h"
|
2019-10-13 19:56:25 +02:00
|
|
|
#include "math/math_util.h"
|
2012-04-10 11:59:57 +02:00
|
|
|
|
2012-07-15 17:04:27 +02:00
|
|
|
int dp_xres;
|
|
|
|
int dp_yres;
|
2012-08-08 00:10:34 +02:00
|
|
|
|
2012-07-06 22:32:32 +02:00
|
|
|
int pixel_xres;
|
|
|
|
int pixel_yres;
|
2012-07-09 00:43:04 +02:00
|
|
|
|
2017-08-07 12:16:08 +02:00
|
|
|
float g_dpi = 1.0f; // will be overwritten with a value that makes sense.
|
2017-08-07 13:18:19 +02:00
|
|
|
float g_dpi_scale_x = 1.0f;
|
|
|
|
float g_dpi_scale_y = 1.0f;
|
|
|
|
float g_dpi_scale_real_x = 1.0f;
|
|
|
|
float g_dpi_scale_real_y = 1.0f;
|
|
|
|
float pixel_in_dps_x = 1.0f;
|
|
|
|
float pixel_in_dps_y = 1.0f;
|
2017-03-05 01:39:26 +01:00
|
|
|
float display_hz = 60.0f;
|
|
|
|
|
|
|
|
DisplayRotation g_display_rotation;
|
2019-10-24 01:29:24 +02:00
|
|
|
Lin::Matrix4x4 g_display_rot_matrix = Lin::Matrix4x4::identity();
|
2019-09-03 23:26:05 +02:00
|
|
|
|
2019-10-13 19:56:25 +02:00
|
|
|
template<class T>
|
2019-10-13 21:23:49 +02:00
|
|
|
void RotateRectToDisplayImpl(DisplayRect<T> &rect, T curRTWidth, T curRTHeight) {
|
2019-09-03 23:26:05 +02:00
|
|
|
switch (g_display_rotation) {
|
|
|
|
case DisplayRotation::ROTATE_180:
|
|
|
|
rect.x = curRTWidth - rect.w - rect.x;
|
|
|
|
rect.y = curRTHeight - rect.h - rect.y;
|
|
|
|
break;
|
|
|
|
case DisplayRotation::ROTATE_90: {
|
|
|
|
// Note that curRTWidth_ and curRTHeight_ are "swapped"!
|
2019-10-13 19:56:25 +02:00
|
|
|
T origX = rect.x;
|
|
|
|
T origY = rect.y;
|
|
|
|
T rth = curRTWidth;
|
|
|
|
rect.x = clamp_value(rth - rect.h - origY, T{}, curRTHeight);
|
2019-09-03 23:26:05 +02:00
|
|
|
rect.y = origX;
|
2019-10-13 19:56:25 +02:00
|
|
|
T temp = rect.w;
|
|
|
|
rect.w = rect.h;
|
|
|
|
rect.h = temp;
|
2019-09-03 23:26:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DisplayRotation::ROTATE_270: {
|
2019-10-13 19:56:25 +02:00
|
|
|
T origX = rect.x;
|
|
|
|
T origY = rect.y;
|
|
|
|
T rtw = curRTHeight;
|
2019-09-03 23:26:05 +02:00
|
|
|
rect.x = origY;
|
2019-10-13 19:56:25 +02:00
|
|
|
rect.y = clamp_value(rtw - rect.w - origX, T{}, curRTWidth);
|
|
|
|
T temp = rect.w;
|
|
|
|
rect.w = rect.h;
|
|
|
|
rect.h = temp;
|
2019-09-03 23:26:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DisplayRotation::ROTATE_0:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-10-13 19:56:25 +02:00
|
|
|
|
2019-10-13 21:23:49 +02:00
|
|
|
void RotateRectToDisplay(DisplayRect<int> &rect, int curRTWidth, int curRTHeight) {
|
2019-10-13 19:56:25 +02:00
|
|
|
RotateRectToDisplayImpl<int>(rect, curRTWidth, curRTHeight);
|
|
|
|
}
|
|
|
|
|
2019-10-13 21:23:49 +02:00
|
|
|
void RotateRectToDisplay(DisplayRect<float> &rect, float curRTWidth, float curRTHeight) {
|
2019-10-13 19:56:25 +02:00
|
|
|
RotateRectToDisplayImpl<float>(rect, curRTWidth, curRTHeight);
|
|
|
|
}
|