Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 27d1dd07f12bd71f84600bfd2476811e1ed6ed55 1 parent baaf155
Artem Simonov authored
View
2  include/SDL_config_playbook.h
@@ -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
5 include/SDL_mouse.h
@@ -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
}
View
5 src/events/SDL_events_c.h
@@ -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
128 src/events/SDL_mouse.c
@@ -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,12 +192,15 @@ 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;
@@ -181,6 +208,7 @@ printf("Mouse event didn't change state - dropped!\n");
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);
+}
View
40 src/video/playbook/SDL_playbookevents.c
@@ -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)
View
67 src/video/playbook/SDL_playbooktouch.c
@@ -210,41 +210,62 @@ int handleTouchScreen(int x, int y, int tap, int hold)
return TCO_SUCCESS;
}
+void locateTCOControlFile(_THIS)
+{
+ const char *filename = "sdl-controls.xml";
+ char *homeDir = SDL_getenv("HOME");
+ char fullPath[512];
+ sprintf(fullPath, "%s/../%s", homeDir, filename);
+ int fd = fopen(fullPath, "r");
+ if (fd) {
+ _priv->tcoControlsDir = SDL_malloc(strlen(fullPath) - strlen(filename) + 1);
+ strncpy(_priv->tcoControlsDir, fullPath, strlen(fullPath) - strlen(filename));
+ fclose(fd);
+ } else {
+ sprintf(fullPath, "%s/../app/native/%s", homeDir, filename);
+ fd = fopen(fullPath, "r");
+ if (fd) {
+ _priv->tcoControlsDir = SDL_malloc(strlen(fullPath) - strlen(filename) + 1);
+ strncpy(_priv->tcoControlsDir, fullPath, strlen(fullPath) - strlen(filename));
+ fclose(fd);
+ } else {
+ _priv->tcoControlsDir = 0; // Use SDL multi-mouse controls.
+ }
+ }
+}
+
void initializeOverlay(_THIS, screen_window_t screenWindow)
{
int loaded = 0;
- FILE *file = 0;
const char *filename = "sdl-controls.xml";
struct tco_callbacks callbacks = {
handleKey, handleDPad, handleTouch, handleMouseButton, handleTap, handleTouchScreen
};
- tco_initialize(&_priv->emu_context, _priv->screenContext, callbacks);
- // Load controls from current working directory
- file = fopen(filename, "r");
- if (file) {
- fclose(file);
- if (tco_loadcontrols(_priv->emu_context, filename) == TCO_SUCCESS)
- loaded = 1;
+ if(!_priv->tcoControlsDir) {
+ // Immediately fall back to SDL multi-mouse controls
+ fprintf(stderr, "Unable to initialize TCO with a NULL tcoControlsDir");
+ return;
}
- // Load controls from app/native
- if (!loaded) {
- char cwd[256];
- if ((getcwd(cwd, 256) != NULL) && (chdir("app/native") == 0)) {
- file = fopen(filename, "r");
- if (file) {
- fclose(file);
- if (tco_loadcontrols(_priv->emu_context, filename) == TCO_SUCCESS)
- loaded = 1;
- }
- chdir(cwd);
+ tco_initialize(&_priv->emu_context, _priv->screenContext, callbacks);
+
+ // Load controls from file
+ char cwd[256];
+ if ((getcwd(cwd, 256) != NULL) && (chdir(_priv->tcoControlsDir) == 0)) {
+ if (tco_loadcontrols(_priv->emu_context, filename) == TCO_SUCCESS) {
+ loaded = 1;
}
+ chdir(cwd);
}
- // Set up default controls
- if (!loaded) {
- tco_loadcontrols_default(_priv->emu_context);
+ // Clean up and set flags
+ SDL_free(_priv->tcoControlsDir);
+ if (loaded) {
+ _priv->tcoControlsDir = 1;
+ tco_showlabels(_priv->emu_context, screenWindow);
+ } else {
+ tco_shutdown(&_priv->emu_context);
+ _priv->tcoControlsDir = 0;
}
- tco_showlabels(_priv->emu_context, screenWindow);
}
View
1  src/video/playbook/SDL_playbooktouch_c.h
@@ -19,6 +19,7 @@ extern int handleTouch(int dx, int dy);
extern int handleMouseButton(int button, int mask, int event);
extern int handleTap();
extern int handleTouchScreen(int x, int y, int tap, int hold);
+extern void locateTCOControlFile(_THIS);
extern void initializeOverlay(_THIS, screen_window_t screenWindow);
#endif /* SDL_PLAYBOOKTOUCH_C_H_ */
View
13 src/video/playbook/SDL_playbookvideo.c
@@ -300,7 +300,9 @@ screen_window_t PLAYBOOK_CreateWindow(_THIS, SDL_Surface *current,
} else {
if (current->hwdata)
SDL_free(current->hwdata);
- tco_shutdown(_priv->emu_context);
+ if (_priv->tcoControlsDir) {
+ tco_shutdown(_priv->emu_context);
+ }
screen_destroy_window_buffers(_priv->screenWindow);
screenWindow = _priv->screenWindow;
}
@@ -458,7 +460,10 @@ SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
return NULL;
}
- initializeOverlay(this, screenWindow);
+ locateTCOControlFile(this);
+ if (_priv->tcoControlsDir) {
+ initializeOverlay(this, screenWindow);
+ }
_priv->frontBuffer = windowBuffer[0];
_priv->screenWindow = screenWindow;
@@ -532,6 +537,8 @@ void PLAYBOOK_VideoQuit(_THIS)
screen_destroy_event(_priv->screenEvent);
screen_destroy_context(_priv->screenContext);
bps_shutdown();
- tco_shutdown(_priv->emu_context);
+ if (_priv->tcoControlsDir) {
+ tco_shutdown(_priv->emu_context);
+ }
this->screen = 0;
}
View
1  src/video/playbook/SDL_playbookvideo.h
@@ -39,6 +39,7 @@ struct SDL_PrivateVideoData {
int w, h;
void *buffer;
void *emu_context;
+ char *tcoControlsDir;
screen_context_t screenContext;
screen_event_t screenEvent;
screen_window_t screenWindow;
View
4 src/video/playbook/SDL_playbookvideo_8bit.c
@@ -553,7 +553,9 @@ void PLAYBOOK_8Bit_VideoQuit(_THIS)
screen_destroy_event(_priv->screenEvent);
screen_destroy_context(_priv->screenContext);
bps_shutdown();
- tco_shutdown(_priv->emu_context);
+ if (_priv->tcoControlsDir) {
+ tco_shutdown(_priv->emu_context);
+ }
this->screen = 0;
}
View
6 src/video/playbook/SDL_playbookvideo_gl.c
@@ -167,8 +167,10 @@ SDL_Surface *PLAYBOOK_SetVideoMode_GL(_THIS, SDL_Surface *current,
goto error5;
}
-
- initializeOverlay(this, screenWindow);
+ locateTCOControlFile(this);
+ if (_priv->tcoControlsDir) {
+ initializeOverlay(this, screenWindow);
+ }
_priv->screenWindow = screenWindow;
Please sign in to comment.
Something went wrong with that request. Please try again.