Permalink
Browse files

Enabled the dummy joystick so Frogatto does not crash.

Added multi-touch via multiple mice. This method bypasses TouchControlOverlay and
is disabled by default. It is used as a fall-back if no valid sdl-controls.xml
file is found.
  • Loading branch information...
Artem Simonov
Artem Simonov committed Feb 27, 2012
1 parent baaf155 commit 27d1dd07f12bd71f84600bfd2476811e1ed6ed55
@@ -108,7 +108,7 @@
#define SDL_CDROM_QNX 1
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
-#define SDL_JOYSTICK_DISABLED 1
+#define SDL_JOYSTICK_DISABLED 0
/* Enable the dlopen shared object loader (src/loadso/dlopen/\*.c) */
#define SDL_LOADSO_DLOPEN 1
View
@@ -55,6 +55,7 @@ typedef struct SDL_Cursor {
* current mouse cursor position. You can pass NULL for either x or y.
*/
extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
+extern DECLSPEC Uint8 SDLCALL SDL_GetMultiMouseState(int which, int *x, int *y);
/**
* Retrieve the current state of the mouse.
@@ -63,6 +64,7 @@ extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
* mouse deltas since the last call to SDL_GetRelativeMouseState().
*/
extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
+extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMultiMouseState(int which, int *x, int *y);
/**
* Set the position of the mouse cursor (generates a mouse motion event)
@@ -134,6 +136,9 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
/*@}*/
+/** Defines the maximum number of mice */
+#define SDL_MAXMOUSE 4
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
@@ -57,7 +57,11 @@ extern Uint8 SDL_ProcessEvents[SDL_NUMEVENTS];
extern int SDL_PrivateAppActive(Uint8 gain, Uint8 state);
extern int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative,
Sint16 x, Sint16 y);
+extern int SDL_PrivateMultiMouseMotion(int which, Uint8 buttonstate,
+ int relative, Sint16 x, Sint16 y);
extern int SDL_PrivateMouseButton(Uint8 state, Uint8 button,Sint16 x,Sint16 y);
+extern int SDL_PrivateMultiMouseButton(int which, Uint8 state, Uint8 button,
+ Sint16 x, Sint16 y);
extern int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *key);
extern int SDL_PrivateResize(int w, int h);
extern int SDL_PrivateExpose(void);
@@ -69,6 +73,7 @@ extern void SDL_SetMouseRange(int maxX, int maxY);
/* Used by the activity event handler to remove mouse focus */
extern void SDL_ResetMouse(void);
+extern void SDL_ResetMultiMouse(int which);
/* Used by the activity event handler to remove keyboard focus */
extern void SDL_ResetKeyboard(void);
View
@@ -30,26 +30,29 @@
/* These are static for our mouse handling code */
-static Sint16 SDL_MouseX = 0;
-static Sint16 SDL_MouseY = 0;
-static Sint16 SDL_DeltaX = 0;
-static Sint16 SDL_DeltaY = 0;
+static Sint16 SDL_MouseX[SDL_MAXMOUSE];
+static Sint16 SDL_MouseY[SDL_MAXMOUSE];
+static Sint16 SDL_DeltaX[SDL_MAXMOUSE];
+static Sint16 SDL_DeltaY[SDL_MAXMOUSE];
+static Uint8 SDL_ButtonState[SDL_MAXMOUSE];
static Sint16 SDL_MouseMaxX = 0;
static Sint16 SDL_MouseMaxY = 0;
-static Uint8 SDL_ButtonState = 0;
/* Public functions */
int SDL_MouseInit(void)
{
/* The mouse is at (0,0) */
- SDL_MouseX = 0;
- SDL_MouseY = 0;
- SDL_DeltaX = 0;
- SDL_DeltaY = 0;
+ Uint8 i;
+ for (i = 0; i < SDL_MAXMOUSE; i++) {
+ SDL_MouseX[i] = 0;
+ SDL_MouseY[i] = 0;
+ SDL_DeltaX[i] = 0;
+ SDL_DeltaY[i] = 0;
+ SDL_ButtonState[i] = 0;
+ }
SDL_MouseMaxX = 0;
SDL_MouseMaxY = 0;
- SDL_ButtonState = 0;
/* That's it! */
return(0);
@@ -59,36 +62,57 @@ void SDL_MouseQuit(void)
}
/* We lost the mouse, so post button up messages for all pressed buttons */
-void SDL_ResetMouse(void)
+void SDL_ResetMultiMouse(int which)
{
Uint8 i;
- for ( i = 0; i < sizeof(SDL_ButtonState)*8; ++i ) {
- if ( SDL_ButtonState & SDL_BUTTON(i) ) {
- SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);
+ if ( !SDL_ButtonState[which] ) return;
+
+ for ( i = 0; i < sizeof(SDL_ButtonState[which])*8; ++i ) {
+ if ( SDL_ButtonState[which] & SDL_BUTTON(i) ) {
+ SDL_PrivateMultiMouseButton(which, SDL_RELEASED, i, 0, 0);
}
}
}
-Uint8 SDL_GetMouseState (int *x, int *y)
+void SDL_ResetMouse(void)
+{
+ Uint8 i;
+ for (i = 0; i < SDL_MAXMOUSE; i++) {
+ SDL_ResetMultiMouse(i);
+ }
+}
+
+Uint8 SDL_GetMultiMouseState (int which, int *x, int *y)
{
if ( x ) {
- *x = SDL_MouseX;
+ *x = SDL_MouseX[which];
}
if ( y ) {
- *y = SDL_MouseY;
+ *y = SDL_MouseY[which];
}
- return(SDL_ButtonState);
+
+ return(SDL_ButtonState[which]);
}
-Uint8 SDL_GetRelativeMouseState (int *x, int *y)
+Uint8 SDL_GetMouseState (int *x, int *y)
+{
+ return SDL_GetMultiMouseState(0, x, y);
+}
+
+Uint8 SDL_GetRelativeMultiMouseState (int which, int *x, int *y)
{
if ( x )
- *x = SDL_DeltaX;
+ *x = SDL_DeltaX[which];
if ( y )
- *y = SDL_DeltaY;
- SDL_DeltaX = 0;
- SDL_DeltaY = 0;
- return(SDL_ButtonState);
+ *y = SDL_DeltaY[which];
+ SDL_DeltaX[which] = 0;
+ SDL_DeltaY[which] = 0;
+ return(SDL_ButtonState[which]);
+}
+
+Uint8 SDL_GetRelativeMouseState (int *x, int *y)
+{
+ return SDL_GetRelativeMultiMouseState(0, x, y);
}
static void ClipOffset(Sint16 *x, Sint16 *y)
@@ -110,7 +134,7 @@ void SDL_SetMouseRange(int maxX, int maxY)
}
/* These are global for SDL_eventloop.c */
-int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
+int SDL_PrivateMultiMouseMotion(int which, Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
{
int posted;
Uint16 X, Y;
@@ -119,15 +143,15 @@ int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
/* Default buttonstate is the current one */
if ( ! buttonstate ) {
- buttonstate = SDL_ButtonState;
+ buttonstate = SDL_ButtonState[which];
}
Xrel = x;
Yrel = y;
if ( relative ) {
/* Push the cursor around */
- x = (SDL_MouseX+x);
- y = (SDL_MouseY+y);
+ x = (SDL_MouseX[which]+x);
+ y = (SDL_MouseY[which]+y);
} else {
/* Do we need to clip {x,y} ? */
ClipOffset(&x, &y);
@@ -155,8 +179,8 @@ int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
the screen is windowed mode and the mouse is outside the window.
*/
if ( ! relative ) {
- Xrel = X-SDL_MouseX;
- Yrel = Y-SDL_MouseY;
+ Xrel = X-SDL_MouseX[which];
+ Yrel = Y-SDL_MouseY[which];
}
/* Drop events that don't change state */
@@ -168,19 +192,23 @@ printf("Mouse event didn't change state - dropped!\n");
}
/* Update internal mouse state */
- SDL_ButtonState = buttonstate;
- SDL_MouseX = X;
- SDL_MouseY = Y;
- SDL_DeltaX += Xrel;
- SDL_DeltaY += Yrel;
- SDL_MoveCursor(SDL_MouseX, SDL_MouseY);
+ SDL_ButtonState[which] = buttonstate;
+ SDL_MouseX[which] = X;
+ SDL_MouseY[which] = Y;
+ SDL_DeltaX[which] += Xrel;
+ SDL_DeltaY[which] += Yrel;
+ if (which == 0) {
+ /* Redraw main pointer */
+ SDL_MoveCursor(X, Y);
+ }
/* Post the event, if desired */
posted = 0;
if ( SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE ) {
SDL_Event event;
SDL_memset(&event, 0, sizeof(event));
event.type = SDL_MOUSEMOTION;
+ event.motion.which = which;
event.motion.state = buttonstate;
event.motion.x = X;
event.motion.y = Y;
@@ -194,7 +222,12 @@ printf("Mouse event didn't change state - dropped!\n");
return(posted);
}
-int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y)
+int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
+{
+ return SDL_PrivateMultiMouseMotion(0, buttonstate, relative, x, y);
+}
+
+int SDL_PrivateMultiMouseButton(int which, Uint8 state, Uint8 button, Sint16 x, Sint16 y)
{
SDL_Event event;
int posted;
@@ -223,12 +256,12 @@ int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y)
move_mouse = 0;
}
if ( ! x )
- x = SDL_MouseX;
+ x = SDL_MouseX[which];
if ( ! y )
- y = SDL_MouseY;
+ y = SDL_MouseY[which];
/* Figure out which event to perform */
- buttonstate = SDL_ButtonState;
+ buttonstate = SDL_ButtonState[which];
switch ( state ) {
case SDL_PRESSED:
event.type = SDL_MOUSEBUTTONDOWN;
@@ -244,16 +277,19 @@ int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y)
}
/* Update internal mouse state */
- SDL_ButtonState = buttonstate;
+ SDL_ButtonState[which] = buttonstate;
if ( move_mouse ) {
- SDL_MouseX = x;
- SDL_MouseY = y;
- SDL_MoveCursor(SDL_MouseX, SDL_MouseY);
+ SDL_MouseX[which] = x;
+ SDL_MouseY[which] = y;
+ if (which == 0) {
+ SDL_MoveCursor(x, y);
+ }
}
/* Post the event, if desired */
posted = 0;
if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) {
+ event.button.which = which;
event.button.state = state;
event.button.button = button;
event.button.x = x;
@@ -266,3 +302,7 @@ int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y)
return(posted);
}
+int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y)
+{
+ return SDL_PrivateMultiMouseButton(0, state, button, x, y);
+}
@@ -698,31 +698,12 @@ static void handleMtouchEvent(screen_event_t event, screen_window_t window, int
fprintf(stderr, "Detected swipe event: %d,%d\n", pos[0], pos[1]);
return;
}
- static int touching = 0;
if (type == SCREEN_EVENT_MTOUCH_TOUCH) {
- if (touching) {
- SDL_PrivateMouseMotion(SDL_BUTTON_LEFT, 0, pos[0], pos[1]);
- } else {
- SDL_PrivateMouseMotion(0, 0, pos[0], pos[1]);
- SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, pos[0], pos[1]);
- }
- moveEvent.pending = 0;
- touching = 1;
+ SDL_PrivateMultiMouseButton(contactId, SDL_PRESSED, SDL_BUTTON_LEFT, pos[0], pos[1]);
} else if (type == SCREEN_EVENT_MTOUCH_RELEASE) {
- if (touching) {
- SDL_PrivateMouseMotion(SDL_BUTTON_LEFT, 0, pos[0], pos[1]);
- SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, pos[0], pos[1]);
- } else {
- SDL_PrivateMouseMotion(0, 0, pos[0], pos[1]);
- }
- moveEvent.pending = 0;
- touching = 0;
+ SDL_PrivateMultiMouseButton(contactId, SDL_RELEASED, SDL_BUTTON_LEFT, pos[0], pos[1]);
} else if (type == SCREEN_EVENT_MTOUCH_MOVE) {
- moveEvent.pending = 1;
- moveEvent.touching = touching;
- moveEvent.pos[0] = pos[0];
- moveEvent.pos[1] = pos[1];
- //SDL_PrivateMouseMotion((touching?SDL_BUTTON_LEFT:0), 0, pos[0], pos[1]);
+ SDL_PrivateMultiMouseMotion(contactId, SDL_BUTTON_LEFT, 0, pos[0], pos[1]);
}
// TODO: Possibly need more complicated touch handling
@@ -759,7 +740,9 @@ void handleNavigatorEvent(_THIS, bps_event_t *event)
}
break;
case NAVIGATOR_SWIPE_DOWN:
- tco_swipedown(_priv->emu_context, _priv->screenWindow);
+ if (_priv->tcoControlsDir) {
+ tco_swipedown(_priv->emu_context, _priv->screenWindow);
+ }
break;
case NAVIGATOR_SWIPE_START:
//fprintf(stderr, "Swipe start\n");
@@ -823,7 +806,11 @@ void handleScreenEvent(_THIS, bps_event_t *event)
case SCREEN_EVENT_MTOUCH_TOUCH:
case SCREEN_EVENT_MTOUCH_MOVE:
case SCREEN_EVENT_MTOUCH_RELEASE:
- tco_touch(this->hidden->emu_context, se);
+ if (_priv->tcoControlsDir) {
+ tco_touch(this->hidden->emu_context, se);
+ } else {
+ handleMtouchEvent(se, window, type);
+ }
break;
}
}
@@ -899,11 +886,6 @@ PLAYBOOK_PumpEvents(_THIS)
state.pending[1] = 0;
}
#endif
- if (moveEvent.pending) {
- SDL_PrivateMouseMotion((moveEvent.touching?SDL_BUTTON_LEFT:0), 0, moveEvent.pos[0], moveEvent.pos[1]);
- moveEvent.pending = 0;
- }
-
}
void PLAYBOOK_InitOSKeymap(_THIS)
Oops, something went wrong.

0 comments on commit 27d1dd0

Please sign in to comment.