# HG changeset patch # User Szymon Wilczek # Date 1215122638 0 # Node ID 2970fcfbdd5445155d25527419a14cadb1b1741f # Parent 81ea7d9a66240ebc9026c7549f92884f4450aee1 Relative mode for tablets. Info on wiki. diff -r 81ea7d9a6624 -r 2970fcfbdd54 include/SDL_mouse.h --- a/include/SDL_mouse.h Wed Jul 02 20:29:29 2008 +0000 +++ b/include/SDL_mouse.h Thu Jul 03 22:03:58 2008 +0000 @@ -92,7 +92,7 @@ * * \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() diff -r 81ea7d9a6624 -r 2970fcfbdd54 src/events/SDL_mouse.c --- a/src/events/SDL_mouse.c Wed Jul 02 20:29:29 2008 +0000 +++ b/src/events/SDL_mouse.c Thu Jul 03 22:03:58 2008 +0000 @@ -33,8 +33,8 @@ 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_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 @@ } 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 @@ 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 @@ 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 @@ } /* 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 @@ /* 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 @@ event.motion.windowID = mouse->focus; posted = (SDL_PushEvent(&event) > 0); } + last_x=x; + last_y=y; return posted; } @@ -724,5 +768,9 @@ return mouse->name; } - +void SDL_UpdateCoordinates(int x, int y) +{ + x_max=x; + y_max=y; +} /* vi: set ts=4 sw=4 expandtab: */ diff -r 81ea7d9a6624 -r 2970fcfbdd54 src/events/SDL_mouse_c.h --- a/src/events/SDL_mouse_c.h Wed Jul 02 20:29:29 2008 +0000 +++ b/src/events/SDL_mouse_c.h Thu Jul 03 22:03:58 2008 +0000 @@ -67,6 +67,7 @@ char* name; Uint8 buttonstate; SDL_bool relative_mode; + SDL_bool proximity; SDL_bool flush_motion; SDL_Cursor *cursors; @@ -118,7 +119,7 @@ extern char* SDL_GetMouseName(int index); - +extern void SDL_UpdateCoordinates(int x, int y); #endif /* _SDL_mouse_c_h */ diff -r 81ea7d9a6624 -r 2970fcfbdd54 src/video/x11/SDL_x11events.c --- a/src/video/x11/SDL_x11events.c Wed Jul 02 20:29:29 2008 +0000 +++ b/src/video/x11/SDL_x11events.c Thu Jul 03 22:03:58 2008 +0000 @@ -37,6 +37,7 @@ extern int button_released; extern int proximity_in; extern int proximity_out; +extern int x_max,y_max; static void @@ -126,8 +127,8 @@ (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 @@ #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]); diff -r 81ea7d9a6624 -r 2970fcfbdd54 src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c Wed Jul 02 20:29:29 2008 +0000 +++ b/src/video/x11/SDL_x11video.c Thu Jul 03 22:03:58 2008 +0000 @@ -362,4 +362,9 @@ free(SDL_XDevices); } +/*void X11_ForwardWindowCoordinates(int x, int y) +{ + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; +}*/ + /* vim: set ts=4 sw=4 expandtab: */