Files
ppsspp/Common/System/Display.cpp
T
Henrik Rydgård 8b431b39ba Wrap the display globals in a struct (#16998)
* Wrap the display globals in a struct

Makes it easier to search/replace these, for future refactorings.

* Some renaming

* Qt buildfix, also fix the Qt build on Mac (got broken with battery changes)

* Attempt at buildfixing ios

* UWP buildfix
2023-02-25 13:09:44 +01:00

49 lines
1.2 KiB
C++

#include "Common/System/Display.h"
#include "Common/Math/math_util.h"
DisplayProperties g_display;
template<class T>
void RotateRectToDisplayImpl(DisplayRect<T> &rect, T curRTWidth, T curRTHeight) {
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"!
T origX = rect.x;
T origY = rect.y;
T rth = curRTWidth;
rect.x = clamp_value(rth - rect.h - origY, T{}, curRTHeight);
rect.y = origX;
T temp = rect.w;
rect.w = rect.h;
rect.h = temp;
break;
}
case DisplayRotation::ROTATE_270: {
T origX = rect.x;
T origY = rect.y;
T rtw = curRTHeight;
rect.x = origY;
rect.y = clamp_value(rtw - rect.w - origX, T{}, curRTWidth);
T temp = rect.w;
rect.w = rect.h;
rect.h = temp;
break;
}
case DisplayRotation::ROTATE_0:
default:
break;
}
}
void RotateRectToDisplay(DisplayRect<int> &rect, int curRTWidth, int curRTHeight) {
RotateRectToDisplayImpl<int>(rect, curRTWidth, curRTHeight);
}
void RotateRectToDisplay(DisplayRect<float> &rect, float curRTWidth, float curRTHeight) {
RotateRectToDisplayImpl<float>(rect, curRTWidth, curRTHeight);
}