From 7003039e56598fee96a49218d1d4fa167ac97a0b Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sat, 3 Jan 2015 19:18:52 +0100 Subject: [PATCH] EventThread: Track touch state (maximum 4 fingers) --- src/eventthread.cpp | 51 ++++++++++++++++++++++++++++++++++----------- src/eventthread.h | 20 ++++++++++++++---- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 0ae1acf..724f4ba 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "sharedstate.h" #include "graphics.h" @@ -34,17 +35,10 @@ #include -uint8_t EventThread::keyStates[] = { false }; - -EventThread::JoyState EventThread::joyState = -{ - { 0 }, { 0 }, { false } -}; - -EventThread::MouseState EventThread::mouseState = -{ - 0, 0, false, { false } -}; +uint8_t EventThread::keyStates[]; +EventThread::JoyState EventThread::joyState; +EventThread::MouseState EventThread::mouseState; +EventThread::TouchState EventThread::touchState; /* User event codes */ enum @@ -111,6 +105,11 @@ void EventThread::process(RGSSThreadData &rtData) bool resetting = false; + int winW, winH; + int i; + + SDL_GetWindowSize(win, &winW, &winH); + SettingsMenu *sMenu = 0; while (true) @@ -140,7 +139,11 @@ void EventThread::process(RGSSThreadData &rtData) switch (event.window.event) { case SDL_WINDOWEVENT_SIZE_CHANGED : - windowSizeMsg.post(Vec2i(event.window.data1, event.window.data2)); + winW = event.window.data1; + winH = event.window.data2; + + windowSizeMsg.post(Vec2i(winW, winH)); + resetInputStates(); break; case SDL_WINDOWEVENT_ENTER : @@ -318,7 +321,30 @@ void EventThread::process(RGSSThreadData &rtData) mouseState.x = event.motion.x; mouseState.y = event.motion.y; + break; + case SDL_FINGERDOWN : + if (event.tfinger.fingerId >= MAX_FINGERS) + break; + + i = event.tfinger.fingerId; + touchState.fingers[i].down = true; + + case SDL_FINGERMOTION : + if (event.tfinger.fingerId >= MAX_FINGERS) + break; + + i = event.tfinger.fingerId; + touchState.fingers[i].x = event.tfinger.x * winW; + touchState.fingers[i].y = event.tfinger.y * winH; + break; + + case SDL_FINGERUP : + if (event.tfinger.fingerId >= MAX_FINGERS) + break; + + i = event.tfinger.fingerId; + memset(&touchState.fingers[i], 0, sizeof(touchState.fingers[0])); break; default : @@ -395,6 +421,7 @@ void EventThread::resetInputStates() memset(&keyStates, 0, sizeof(keyStates)); memset(&joyState, 0, sizeof(joyState)); memset(&mouseState.buttons, 0, sizeof(mouseState.buttons)); + memset(&touchState, 0, sizeof(touchState)); } void EventThread::setFullscreen(SDL_Window *win, bool mode) diff --git a/src/eventthread.h b/src/eventthread.h index 1414f37..9dcc21f 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -40,11 +40,11 @@ struct RGSSThreadData; typedef struct ALCdevice_struct ALCdevice; struct SDL_Window; +#define MAX_FINGERS 4 + class EventThread { public: - static uint8_t keyStates[SDL_NUM_SCANCODES]; - struct JoyState { int axes[256]; @@ -52,8 +52,6 @@ public: bool buttons[256]; }; - static JoyState joyState; - struct MouseState { int x, y; @@ -61,7 +59,21 @@ public: bool buttons[32]; }; + struct FingerState + { + bool down; + int x, y; + }; + + struct TouchState + { + FingerState fingers[MAX_FINGERS]; + }; + + static uint8_t keyStates[SDL_NUM_SCANCODES]; + static JoyState joyState; static MouseState mouseState; + static TouchState touchState; static bool allocUserEvents();