diff options
-rw-r--r-- | src/frontend/Util_Video.cpp | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/src/frontend/Util_Video.cpp b/src/frontend/Util_Video.cpp index 73f1b05..33f0183 100644 --- a/src/frontend/Util_Video.cpp +++ b/src/frontend/Util_Video.cpp @@ -37,6 +37,7 @@ bool TopEnable; bool BotEnable; bool HybEnable; int HybScreen; +int HybPrevTouchScreen; // 0:unknown, 1:buttom screen, 2:hybrid screen void M23_Identity(float* m) { @@ -138,6 +139,7 @@ void SetupScreenLayout(int screenWidth, int screenHeight, HybScreen = swapScreens ? 1 : 0; swapScreens = false; topAspect = botAspect = 1; + HybPrevTouchScreen = 0; } float refpoints[6][2] = @@ -469,31 +471,79 @@ int GetScreenTransforms(float* out, int* kind) bool GetTouchCoords(int& x, int& y, bool clamp) { - float vx = x; - float vy = y; - - if (BotEnable) + if (HybEnable && HybScreen == 1) { + float vx = x; + float vy = y; + float hvx = x; + float hvy = y; + M23_Transform(TouchMtx, vx, vy); - } - else if (HybEnable && HybScreen == 1) - { - M23_Transform(HybTouchMtx, vx, vy); - } + M23_Transform(HybTouchMtx, hvx, hvy); - x = (int)vx; - y = (int)vy; + if (clamp) + { + if (HybPrevTouchScreen == 1) + { + x = std::clamp((int)vx, 0, 255); + y = std::clamp((int)vy, 0, 191); + + return true; + } + if (HybPrevTouchScreen == 2) + { + x = std::clamp((int)hvx, 0, 255); + y = std::clamp((int)hvy, 0, 191); - if (clamp) - { - x = std::clamp(x, 0, 255); - y = std::clamp(y, 0, 191); - return true; + return true; + } + } + else + { + if (vx >= 0 && vx < 256 && vy >= 0 && vy < 192) + { + HybPrevTouchScreen = 1; + + x = (int)vx; + y = (int)vy; + + return true; + } + if (hvx >= 0 && hvx < 256 && hvy >= 0 && hvy < 192) + { + HybPrevTouchScreen = 2; + + x = (int)hvx; + y = (int)hvy; + + return true; + } + } } - else + else if (BotEnable) { - if (x >= 0 && x < 256 && y >= 0 && y < 192) + float vx = x; + float vy = y; + + M23_Transform(TouchMtx, vx, vy); + + if (clamp) + { + x = std::clamp((int)vx, 0, 255); + y = std::clamp((int)vy, 0, 191); + return true; + } + else + { + if (vx >= 0 && vx < 256 && vy >= 0 && vy < 192) + { + x = (int)vx; + y = (int)vy; + + return true; + } + } } return false; |