EventThread: Track touch state (maximum 4 fingers)

This commit is contained in:
Jonas Kulla 2015-01-03 19:18:52 +01:00
parent 146e0294b4
commit 7003039e56
2 changed files with 55 additions and 16 deletions

View File

@ -26,6 +26,7 @@
#include <SDL_messagebox.h> #include <SDL_messagebox.h>
#include <SDL_timer.h> #include <SDL_timer.h>
#include <SDL_thread.h> #include <SDL_thread.h>
#include <SDL_touch.h>
#include "sharedstate.h" #include "sharedstate.h"
#include "graphics.h" #include "graphics.h"
@ -34,17 +35,10 @@
#include <string.h> #include <string.h>
uint8_t EventThread::keyStates[] = { false }; uint8_t EventThread::keyStates[];
EventThread::JoyState EventThread::joyState;
EventThread::JoyState EventThread::joyState = EventThread::MouseState EventThread::mouseState;
{ EventThread::TouchState EventThread::touchState;
{ 0 }, { 0 }, { false }
};
EventThread::MouseState EventThread::mouseState =
{
0, 0, false, { false }
};
/* User event codes */ /* User event codes */
enum enum
@ -111,6 +105,11 @@ void EventThread::process(RGSSThreadData &rtData)
bool resetting = false; bool resetting = false;
int winW, winH;
int i;
SDL_GetWindowSize(win, &winW, &winH);
SettingsMenu *sMenu = 0; SettingsMenu *sMenu = 0;
while (true) while (true)
@ -140,7 +139,11 @@ void EventThread::process(RGSSThreadData &rtData)
switch (event.window.event) switch (event.window.event)
{ {
case SDL_WINDOWEVENT_SIZE_CHANGED : 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; break;
case SDL_WINDOWEVENT_ENTER : case SDL_WINDOWEVENT_ENTER :
@ -318,7 +321,30 @@ void EventThread::process(RGSSThreadData &rtData)
mouseState.x = event.motion.x; mouseState.x = event.motion.x;
mouseState.y = event.motion.y; 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; break;
default : default :
@ -395,6 +421,7 @@ void EventThread::resetInputStates()
memset(&keyStates, 0, sizeof(keyStates)); memset(&keyStates, 0, sizeof(keyStates));
memset(&joyState, 0, sizeof(joyState)); memset(&joyState, 0, sizeof(joyState));
memset(&mouseState.buttons, 0, sizeof(mouseState.buttons)); memset(&mouseState.buttons, 0, sizeof(mouseState.buttons));
memset(&touchState, 0, sizeof(touchState));
} }
void EventThread::setFullscreen(SDL_Window *win, bool mode) void EventThread::setFullscreen(SDL_Window *win, bool mode)

View File

@ -40,11 +40,11 @@ struct RGSSThreadData;
typedef struct ALCdevice_struct ALCdevice; typedef struct ALCdevice_struct ALCdevice;
struct SDL_Window; struct SDL_Window;
#define MAX_FINGERS 4
class EventThread class EventThread
{ {
public: public:
static uint8_t keyStates[SDL_NUM_SCANCODES];
struct JoyState struct JoyState
{ {
int axes[256]; int axes[256];
@ -52,8 +52,6 @@ public:
bool buttons[256]; bool buttons[256];
}; };
static JoyState joyState;
struct MouseState struct MouseState
{ {
int x, y; int x, y;
@ -61,7 +59,21 @@ public:
bool buttons[32]; 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 MouseState mouseState;
static TouchState touchState;
static bool allocUserEvents(); static bool allocUserEvents();