diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-11-09 00:15:59 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-11-09 00:15:59 +0100 |
commit | f2a5be6096b72d28104036eb5efc0d0958e131bc (patch) | |
tree | bab139d87210a23172023834529250aa688b9aa3 /src/libui_sdl | |
parent | 34513063ab0d82390bb88f19ff4977d16d805091 (diff) |
make touchscreen code take rotation into account
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/main.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index b0656c2..7268e02 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -344,10 +344,39 @@ void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* ev x -= BottomScreenRect.X; y -= BottomScreenRect.Y; - if (BottomScreenRect.Width != 256) - x = (x * 256) / BottomScreenRect.Width; - if (BottomScreenRect.Height != 192) - y = (y * 192) / BottomScreenRect.Height; + if (ScreenRotation == 0 || ScreenRotation == 2) + { + if (BottomScreenRect.Width != 256) + x = (x * 256) / BottomScreenRect.Width; + if (BottomScreenRect.Height != 192) + y = (y * 192) / BottomScreenRect.Height; + + if (ScreenRotation == 2) + { + x = 255 - x; + y = 191 - y; + } + } + else + { + if (BottomScreenRect.Width != 192) + x = (x * 192) / BottomScreenRect.Width; + if (BottomScreenRect.Height != 256) + y = (y * 256) / BottomScreenRect.Height; + + if (ScreenRotation == 1) + { + int tmp = x; + x = y; + y = 191 - tmp; + } + else + { + int tmp = x; + x = 255 - y; + y = tmp; + } + } // clamp if (x < 0) x = 0; @@ -396,7 +425,7 @@ void SetupScreenRects(int width, int height) { bool horizontal = false; bool sideways = false; -ScreenRotation = 3; // TEST 1=90 CW 2=180 3=270 +ScreenRotation = 1; // TEST 1=90 CW 2=180 3=270 if (ScreenRotation == 1 || ScreenRotation == 3) sideways = true; |