Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Relative mode for tablets. Info on wiki.
  • Loading branch information
Szymon Wilczek committed Jul 3, 2008
1 parent b97ca87 commit 629e37b7ed07a616733214c3df603664c48480d2
Showing with 81 additions and 21 deletions.
  1. +1 −1 include/SDL_mouse.h
  2. +65 −17 src/events/SDL_mouse.c
  3. +2 −1 src/events/SDL_mouse_c.h
  4. +8 −2 src/video/x11/SDL_x11events.c
  5. +5 −0 src/video/x11/SDL_x11video.c
@@ -92,7 +92,7 @@ extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(void);
*
* \sa SDL_GetRelativeMouseMode()
*/
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled, int index);

/**
* \fn SDL_bool SDL_GetRelativeMouseMode()
@@ -33,8 +33,8 @@ static int SDL_current_mouse;
static SDL_Mouse **SDL_mice;
int *SDL_IdIndex;
int SDL_highestId;


int last_x, last_y;
int x_max, y_max;
/* Public functions */
int
SDL_MouseInit(void)
@@ -85,6 +85,8 @@ SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name)
SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
SDL_SetCursor(SDL_mice[index]->def_cursor);
SDL_mice[index]->proximity=SDL_TRUE;
SDL_mice[index]->relative_mode=SDL_FALSE;
SDL_SelectMouse(selected_mouse);

return index;
@@ -180,9 +182,9 @@ FlushMouseMotion(void *param, SDL_Event * event)
}

int
SDL_SetRelativeMouseMode(SDL_bool enabled)
SDL_SetRelativeMouseMode(SDL_bool enabled, int index)
{
SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
SDL_Mouse *mouse = SDL_GetMouse(index);

if (!mouse) {
return -1;
@@ -326,12 +328,20 @@ SDL_SendProximity(int id, int x, int y, int type)
if(SDL_ProcessEvents[type]==SDL_ENABLE)
{
SDL_Event event;
event.proximity.which=index;
event.proximity.which=(Uint8)index;
event.proximity.x=x;
event.proximity.y=y;
event.type=type;
event.proximity.type=type;
posted = (SDL_PushEvent(&event) > 0);
if(type==SDL_PROXIMITYIN)
{
SDL_mice[index]->proximity=SDL_TRUE;
}
else
{
SDL_mice[index]->proximity=SDL_FALSE;
}
}
return posted;
}
@@ -348,16 +358,21 @@ SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
if (!mouse || mouse->flush_motion) {
return 0;
}

if (relative) {
if(mouse->proximity==SDL_FALSE)
{
last_x=x;
last_y=y;
return 0;
}
if (mouse->relative_mode==SDL_TRUE && mouse->proximity==SDL_TRUE) {
/* Push the cursor around */
xrel = x;
yrel = y;
x = (mouse->x + xrel);
y = (mouse->y + yrel);
xrel = x - last_x;
yrel = y - last_y;
//x = (mouse->x + xrel);
//y = (mouse->y + yrel);
} else {
xrel = x - mouse->x;
yrel = y - mouse->y;
xrel = x - last_x;
yrel = y - last_y;
}

/* Drop events that don't change state */
@@ -369,10 +384,37 @@ SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
}

/* Update internal mouse state */
if (!mouse->relative_mode) {
if (mouse->relative_mode==SDL_FALSE) {
mouse->x = x;
mouse->y = y;
}
else
{
if(mouse->x+xrel>x_max)
{
mouse->x=x_max;
}
else if(mouse->x+xrel<0)
{
mouse->x=0;
}
else
{
mouse->x+=xrel;
}
if(mouse->y+yrel>y_max)
{
mouse->y=y_max;
}
else if(mouse->y+yrel<0)
{
mouse->y=0;
}
else
{
mouse->y+=yrel;
}
}
mouse->xdelta += xrel;
mouse->ydelta += yrel;
mouse->z=z;
@@ -385,10 +427,10 @@ SDL_SendMouseMotion(int id, int relative, int x, int y,int z)

/* Post the event, if desired */
posted = 0;
if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) {
if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && SDL_mice[index]->proximity==SDL_TRUE) {
SDL_Event event;
event.motion.type = SDL_MOUSEMOTION;
event.motion.which = (Uint8) index;
event.motion.which = (Uint8) index;
event.motion.state = mouse->buttonstate;
event.motion.x = mouse->x;
event.motion.y = mouse->y;
@@ -398,6 +440,8 @@ SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
event.motion.windowID = mouse->focus;
posted = (SDL_PushEvent(&event) > 0);
}
last_x=x;
last_y=y;
return posted;
}

@@ -724,5 +768,9 @@ char* SDL_GetMouseName(int index)
return mouse->name;
}


void SDL_UpdateCoordinates(int x, int y)
{
x_max=x;
y_max=y;
}
/* vi: set ts=4 sw=4 expandtab: */
@@ -67,6 +67,7 @@ struct SDL_Mouse
char* name;
Uint8 buttonstate;
SDL_bool relative_mode;
SDL_bool proximity;
SDL_bool flush_motion;

SDL_Cursor *cursors;
@@ -118,7 +119,7 @@ extern int SDL_GetNumOfMice(void);

extern char* SDL_GetMouseName(int index);


extern void SDL_UpdateCoordinates(int x, int y);

#endif /* _SDL_mouse_c_h */

@@ -37,6 +37,7 @@ extern int button_pressed;
extern int button_released;
extern int proximity_in;
extern int proximity_out;
extern int x_max,y_max;


static void
@@ -126,8 +127,8 @@ X11_DispatchEvent(_THIS)
(xevent.xcrossing.mode != NotifyUngrab) &&
(xevent.xcrossing.detail != NotifyInferior)) {
XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
SDL_SendMouseMotion(move->deviceid, 0,
move->x, move->y,move->axis_data[2]);
//SDL_SendMouseMotion(move->deviceid, 0,
// move->x, move->y,move->axis_data[2]);
SDL_SetMouseFocus(move->deviceid, 0);
}
}
@@ -297,6 +298,11 @@ X11_DispatchEvent(_THIS)
#ifdef DEBUG_MOTION
printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
#endif
XWindowAttributes attrib;
XGetWindowAttributes(videodata->display, ((XAnyEvent*)&xevent)->window, &attrib);
/*x_max=attrib.width;
y_max=attrib.height;*/
SDL_UpdateCoordinates(attrib.width, attrib.height);
XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
SDL_SendMouseMotion(move->deviceid, 0, move->x,
move->y,move->axis_data[2]);
@@ -362,4 +362,9 @@ X11_VideoQuit(_THIS)
free(SDL_XDevices);
}

/*void X11_ForwardWindowCoordinates(int x, int y)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
}*/

/* vim: set ts=4 sw=4 expandtab: */

0 comments on commit 629e37b

Please sign in to comment.