Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added a mouse ID to the mouse events, which set to the special value …

…SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
  • Loading branch information
slouken committed Mar 3, 2013
1 parent 6e2423a commit 9707138ff7ba19217d00fb03d7e9c1d9ac77dcf0
@@ -151,8 +151,8 @@ typedef struct SDL_WindowEvent
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
int data1; /**< event dependent data */
int data2; /**< event dependent data */
Sint32 data1; /**< event dependent data */
Sint32 data2; /**< event dependent data */
} SDL_WindowEvent;

/**
@@ -180,8 +180,8 @@ typedef struct SDL_TextEditingEvent
Uint32 timestamp;
Uint32 windowID; /**< The window with keyboard focus, if any */
char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */
int start; /**< The start cursor of selected editing text */
int length; /**< The length of selected editing text */
Sint32 start; /**< The start cursor of selected editing text */
Sint32 length; /**< The length of selected editing text */
} SDL_TextEditingEvent;


@@ -205,14 +205,15 @@ typedef struct SDL_MouseMotionEvent
Uint32 type; /**< ::SDL_MOUSEMOTION */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Uint8 state; /**< The current button state */
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
int x; /**< X coordinate, relative to window */
int y; /**< Y coordinate, relative to window */
int xrel; /**< The relative motion in the X direction */
int yrel; /**< The relative motion in the Y direction */
Sint32 x; /**< X coordinate, relative to window */
Sint32 y; /**< Y coordinate, relative to window */
Sint32 xrel; /**< The relative motion in the X direction */
Sint32 yrel; /**< The relative motion in the Y direction */
} SDL_MouseMotionEvent;

/**
@@ -223,12 +224,13 @@ typedef struct SDL_MouseButtonEvent
Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Uint8 button; /**< The mouse button index */
Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
Uint8 padding1;
Uint8 padding2;
int x; /**< X coordinate, relative to window */
int y; /**< Y coordinate, relative to window */
Sint32 x; /**< X coordinate, relative to window */
Sint32 y; /**< Y coordinate, relative to window */
} SDL_MouseButtonEvent;

/**
@@ -239,8 +241,9 @@ typedef struct SDL_MouseWheelEvent
Uint32 type; /**< ::SDL_MOUSEWHEEL */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */
int x; /**< The amount scrolled horizontally */
int y; /**< The amount scrolled vertically */
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Sint32 x; /**< The amount scrolled horizontally */
Sint32 y; /**< The amount scrolled vertically */
} SDL_MouseWheelEvent;

/**
@@ -467,7 +470,7 @@ typedef struct SDL_UserEvent
Uint32 type; /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */
Uint32 timestamp;
Uint32 windowID; /**< The associated window if any */
int code; /**< User defined event code */
Sint32 code; /**< User defined event code */
void *data1; /**< User defined data pointer */
void *data2; /**< User defined data pointer */
} SDL_UserEvent;
@@ -40,30 +40,25 @@ extern "C" {
/* *INDENT-ON* */
#endif


typedef Sint64 SDL_TouchID;
typedef Sint64 SDL_FingerID;


struct SDL_Finger {
SDL_FingerID id;
Uint16 x;
Uint16 y;
Uint16 pressure;
Uint16 xdelta;
Uint16 ydelta;
Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */
SDL_bool down;
};

typedef struct SDL_Touch SDL_Touch;
typedef struct SDL_Finger SDL_Finger;


struct SDL_Touch {

typedef struct SDL_Finger
{
SDL_FingerID id;
Uint16 x;
Uint16 y;
Uint16 pressure;
Uint16 xdelta;
Uint16 ydelta;
Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */
SDL_bool down;
} SDL_Finger;

typedef struct SDL_Touch
{
/* Free the touch when it's time */
void (*FreeTouch) (SDL_Touch * touch);
void (*FreeTouch) (struct SDL_Touch * touch);

/* data common for tablets */
float pressure_max, pressure_min;
@@ -89,28 +84,23 @@ struct SDL_Touch {
SDL_Finger** fingers;

void *driverdata;
};
} SDL_Touch;

/* Used as the device ID for mouse events simulated with touch input */
#define SDL_TOUCH_MOUSEID ((Uint32)-1)


/* Function prototypes */

/**
* \brief Get the touch object at the given id.
*
*
* \brief Get the touch object with the given id.
*/
extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id);


extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id);

/**
* \brief Get the finger object of the given touch, at the given id.
*
*
* \brief Get the finger object of the given touch, with the given id.
*/
extern
DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id);
extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
@@ -81,7 +81,7 @@ SDL_ResetMouse(void)
#endif
for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) {
if (mouse->buttonstate & SDL_BUTTON(i)) {
SDL_SendMouseButton(mouse->focus, SDL_RELEASED, i);
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i);
}
}
SDL_assert(mouse->buttonstate == 0);
@@ -174,7 +174,7 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
}

int
SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y)
SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
@@ -252,6 +252,7 @@ SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y)
SDL_Event event;
event.motion.type = SDL_MOUSEMOTION;
event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
event.motion.which = mouseID;
event.motion.state = mouse->buttonstate;
event.motion.x = mouse->x;
event.motion.y = mouse->y;
@@ -266,7 +267,7 @@ SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y)
}

int
SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button)
SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
@@ -304,11 +305,12 @@ SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button)
if (SDL_GetEventState(type) == SDL_ENABLE) {
SDL_Event event;
event.type = type;
event.button.windowID = mouse->focus ? mouse->focus->id : 0;
event.button.which = mouseID;
event.button.state = state;
event.button.button = button;
event.button.x = mouse->x;
event.button.y = mouse->y;
event.button.windowID = mouse->focus ? mouse->focus->id : 0;
posted = (SDL_PushEvent(&event) > 0);
}

@@ -321,7 +323,7 @@ SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button)
}

int
SDL_SendMouseWheel(SDL_Window * window, int x, int y)
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
@@ -340,6 +342,7 @@ SDL_SendMouseWheel(SDL_Window * window, int x, int y)
SDL_Event event;
event.type = SDL_MOUSEWHEEL;
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
event.wheel.which = mouseID;
event.wheel.x = x;
event.wheel.y = y;
posted = (SDL_PushEvent(&event) > 0);
@@ -396,7 +399,7 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
if (mouse->WarpMouse) {
mouse->WarpMouse(window, x, y);
} else {
SDL_SendMouseMotion(window, 0, x, y);
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
}
}

@@ -25,6 +25,8 @@

#include "SDL_mouse.h"

typedef Uint32 SDL_MouseID;

struct SDL_Cursor
{
struct SDL_Cursor *next;
@@ -55,6 +57,7 @@ typedef struct
int (*SetRelativeMouseMode) (SDL_bool enabled);

/* Data common to all mice */
SDL_MouseID mouseID;
SDL_Window *focus;
int x;
int y;
@@ -86,13 +89,13 @@ extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
extern void SDL_SetMouseFocus(SDL_Window * window);

/* Send a mouse motion event */
extern int SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y);
extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);

/* Send a mouse button event */
extern int SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button);
extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);

/* Send a mouse wheel event */
extern int SDL_SendMouseWheel(SDL_Window * window, int x, int y);
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y);

/* Shutdown the mouse subsystem */
extern void SDL_MouseQuit(void);
@@ -221,7 +221,7 @@ class SDL_BApp : public BApplication {
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseMotion(win, 0, x, y);
SDL_SendMouseMotion(win, 0, 0, x, y);

/* Tell the application that the mouse passed over, redraw needed */
BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
@@ -239,7 +239,7 @@ class SDL_BApp : public BApplication {
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseButton(win, state, button);
SDL_SendMouseButton(win, 0, state, button);
}

void _HandleMouseWheel(BMessage *msg) {
@@ -254,7 +254,7 @@ class SDL_BApp : public BApplication {
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseWheel(win, xTicks, yTicks);
SDL_SendMouseWheel(win, 0, xTicks, yTicks);
}

void _HandleKey(BMessage *msg) {
@@ -89,10 +89,10 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio
Android_GetWindowCoordinates(x, y, &window_x, &window_y);

/* send moved event */
SDL_SendMouseMotion(NULL, 0, window_x, window_y);
SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);

/* send mouse down event */
SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);

leftFingerDown = fingerId;
}
@@ -103,15 +103,15 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio
Android_GetWindowCoordinates(x, y, &window_x, &window_y);

/* send moved event */
SDL_SendMouseMotion(NULL, 0, window_x, window_y);
SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
}
SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
break;
case ACTION_UP:
case ACTION_POINTER_1_UP:
if (fingerId == leftFingerDown) {
/* send mouse up */
SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
leftFingerDown = 0;
}
SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
@@ -223,13 +223,15 @@
[event type] == NSOtherMouseDragged)) {
float x = [event deltaX];
float y = [event deltaY];
SDL_SendMouseMotion(mouse->focus, 1, (int)x, (int)y);
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y);
}
}

void
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
{
SDL_Mouse *mouse = SDL_GetMouse();

float x = [event deltaX];
float y = [event deltaY];

@@ -243,7 +245,7 @@
} else if (y < 0) {
y -= 0.9f;
}
SDL_SendMouseWheel(window, (int)x, (int)y);
SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y);
}

void
@@ -200,7 +200,7 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification
y = (int)(window->h - point.y);

if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
SDL_SendMouseMotion(window, 0, x, y);
SDL_SendMouseMotion(window, 0, 0, x, y);
SDL_SetCursor(NULL);
}
}
@@ -263,7 +263,7 @@ - (void)mouseDown:(NSEvent *)theEvent
button = [theEvent buttonNumber] + 1;
break;
}
SDL_SendMouseButton(_data->window, SDL_PRESSED, button);
SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
}

- (void)rightMouseDown:(NSEvent *)theEvent
@@ -294,7 +294,7 @@ - (void)mouseUp:(NSEvent *)theEvent
button = [theEvent buttonNumber] + 1;
break;
}
SDL_SendMouseButton(_data->window, SDL_RELEASED, button);
SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
}

- (void)rightMouseUp:(NSEvent *)theEvent
@@ -342,7 +342,7 @@ - (void)mouseMoved:(NSEvent *)theEvent
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
}
}
SDL_SendMouseMotion(window, 0, x, y);
SDL_SendMouseMotion(window, 0, 0, x, y);
}

- (void)mouseDragged:(NSEvent *)theEvent

0 comments on commit 9707138

Please sign in to comment.