# HG changeset patch # User Darren Alton # Date 1214775151 0 # Node ID 5e4274591163ef91cd2cc140ce538ef254bff342 # Parent f1d07ba2e275a071e4248200b3e49b21f356ea3e Started minor changes to the coordinate system used by the touchscreen API as discussed on the mailing list. Also beginning to separate the 'Pressed' and 'Moved' event handling on the private level. diff -r f1d07ba2e275 -r 5e4274591163 include/SDL_touchscreen.h --- a/include/SDL_touchscreen.h Mon Jun 23 11:55:26 2008 +0000 +++ b/include/SDL_touchscreen.h Sun Jun 29 21:32:31 2008 +0000 @@ -107,11 +107,12 @@ /* * Get the current X,Y position of the indicated point on the touchscreen. * - * If not NULL, *x is set to an integer in the range [-32768,32767] - * where -32768 is the left edge, 0 is center, 32767 is right edge. + * If not NULL, *x is set to an unsigned integer in the range [1,65535] + * where 1 is the left edge, 32768 is roughly center, 65535 is right edge. * Similarly with *y, for the top, center, and bottom, respectively. - * The returned value is an unsigned integer in the range [1,32767] - * that represents the pressure of the touch. + * The returned value is an unsigned integer in the range [1,65535], + * which represents the pressure of the touch. This should be 32767 in + * non-pressure-sensitive driver implementations. * If not being touched, 0 is returned and *x and *y are unmodified. * * The touch point indices start at index 0. @@ -123,8 +124,8 @@ * * On error, -1 is returned. */ -extern DECLSPEC int SDLCALL SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, - int point, int *x, int *y); +extern DECLSPEC Uint16 SDLCALL SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, + int point, Uint16 *x, Uint16 *y); /* * Get the number of currently touched points on a touchscreen. diff -r f1d07ba2e275 -r 5e4274591163 src/touchscreen/SDL_systouchscreen.h --- a/src/touchscreen/SDL_systouchscreen.h Mon Jun 23 11:55:26 2008 +0000 +++ b/src/touchscreen/SDL_systouchscreen.h Sun Jun 29 21:32:31 2008 +0000 @@ -35,9 +35,9 @@ int npoints; /* Number of points currently touched */ struct touchpoint { - int x; - int y; - int pressure; + Uint16 x; + Uint16 y; + Uint16 pressure; } *points; /* Current ball motion deltas */ struct touchscreen_hwdata *hwdata; /* Driver dependent information */ diff -r f1d07ba2e275 -r 5e4274591163 src/touchscreen/SDL_touchscreen.c --- a/src/touchscreen/SDL_touchscreen.c Mon Jun 23 11:55:26 2008 +0000 +++ b/src/touchscreen/SDL_touchscreen.c Sun Jun 29 21:32:31 2008 +0000 @@ -210,8 +210,8 @@ /* * Get the current X,Y position of the indicated point on the touchscreen */ -int -SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, int point, int *x, int *y) +Uint16 +SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, int point, Uint16 *x, Uint16 *y) { int retval; @@ -328,10 +328,8 @@ /* These are global for SDL_systouchscreen.c and SDL_events.c */ int -SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point, - int x, int y, int pressure) { +SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point, Uint16 x, Uint16 y, Uint16 pressure) { int posted; - int ev = SDL_TOUCHMOTION; if (!ValidTouchscreen(&touchscreen)) { return -1; @@ -353,12 +351,72 @@ /* new touch point! that means a TOUCHPRESSED event is due. */ if(point >= touchscreen->npoints) { - ev = SDL_TOUCHPRESSED; point = touchscreen->npoints; ++touchscreen->npoints; } /* no motion, no change, don't report an event. */ + if(touchscreen->points[point].pressure > 0) { + SDL_SetError("Warning: touch point %d was already pressed", point); + return -1; + } + + /* Update internal touchscreen point state */ + touchscreen->points[point].x = x; + touchscreen->points[point].y = y; + touchscreen->points[point].pressure = pressure; + + /* Post the event, if desired */ + posted = 0; +#if !SDL_EVENTS_DISABLED + if (SDL_ProcessEvents[SDL_TOUCHPRESSED] == SDL_ENABLE) { + SDL_Event event; + event.touch.type = SDL_TOUCHPRESSED; + event.touch.which = touchscreen->index; + event.touch.point = point; + event.touch.xpos = x; + event.touch.ypos = y; + event.touch.pressure = pressure; + if ((SDL_EventOK == NULL) + || (*SDL_EventOK) (SDL_EventOKParam, &event)) { + posted = 1; + SDL_PushEvent(&event); + } + } +#endif /* !SDL_EVENTS_DISABLED */ + return (posted); +} + +int +SDL_PrivateTouchMove(SDL_Touchscreen * touchscreen, int point, + Uint16 x, Uint16 y, Uint16 pressure) { + int posted; + + if (!ValidTouchscreen(&touchscreen)) { + return -1; + } + + if(point >= touchscreen->maxpoints) { + SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints); + return -1; + } + + /* on neg. point, set the given args as the *only* point. + so set the struct to have no points pressed, then continue as normal. */ + if(point < 0) { + point = 0; + touchscreen->npoints = 0; + SDL_memset(touchscreen->points, 0, + touchscreen->maxpoints * sizeof(touchscreen->points[0])); + } + + /* new touch point! that means a TOUCHPRESSED event is due. */ + if(point >= touchscreen->npoints || touchscreen->points[point].pressure == 0) { + SDL_SetError("Touch point %d shouldn't move before it's pressed.", point); + return -1; + } + + /* no motion, no change, don't report an event. */ if(touchscreen->points[point].x == x && touchscreen->points[point].y == y && touchscreen->points[point].pressure == pressure) { @@ -373,9 +431,9 @@ /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_ProcessEvents[ev] == SDL_ENABLE) { + if (SDL_ProcessEvents[SDL_TOUCHMOTION] == SDL_ENABLE) { SDL_Event event; - event.touch.type = ev; + event.touch.type = SDL_TOUCHMOTION; event.touch.which = touchscreen->index; event.touch.point = point; event.touch.xpos = x; @@ -394,6 +452,7 @@ int SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point) { int posted; + int i; if (!ValidTouchscreen(&touchscreen)) { return -1; @@ -418,7 +477,12 @@ /* Update internal touchscreen point state */ touchscreen->points[point].pressure = 0; + touchscreen->points[point].x = 0; + touchscreen->points[point].y = 0; if(touchscreen->npoints >= 0) --touchscreen->npoints; + for(i = point; i < touchscreen->npoints; ++i) { + touchscreen->points[i] = touchscreen->points[i+1]; + } /* Post the event, if desired */ posted = 0; diff -r f1d07ba2e275 -r 5e4274591163 src/touchscreen/SDL_touchscreen_c.h --- a/src/touchscreen/SDL_touchscreen_c.h Mon Jun 23 11:55:26 2008 +0000 +++ b/src/touchscreen/SDL_touchscreen_c.h Sun Jun 29 21:32:31 2008 +0000 @@ -32,11 +32,22 @@ /* the point index starts at 0 * if point < 0, release all points and set this to be the first (only) point. * if point >= touchscreen->maxpoints, error. - * otherwise, set or update the coordinates for the given point. - * return -1 if fatal error, 0 on success + * otherwise, add a point with the given coordinates. + * return < 0 if fatal error, >= 0 on success */ extern int SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point, - int x, int y, int pressure); -/* if point < 0, release all points. */ + Uint16 x, Uint16 y, Uint16 pressure); +/* if point < 0, release all points and set this to be the first (only) point. + * if point >= touchscreen->maxpoints, error. + * otherwise, update the coordinates for the given point. + * return < 0 if fatal error, >= 0 on success + */ +extern int SDL_PrivateTouchMove(SDL_Touchscreen * touchscreen, int point, + Uint16 x, Uint16 y, Uint16 pressure); +/* if point < 0, release all points. + * if point >= touchscreen->npoints, error. + * otherwise, remove the given point. + * return < 0 if fatal error, >= 0 on success + */ extern int SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point); /* vi: set ts=4 sw=4 expandtab: */ diff -r f1d07ba2e275 -r 5e4274591163 src/touchscreen/nds/SDL_systouchscreen.c --- a/src/touchscreen/nds/SDL_systouchscreen.c Mon Jun 23 11:55:26 2008 +0000 +++ b/src/touchscreen/nds/SDL_systouchscreen.c Sun Jun 29 21:32:31 2008 +0000 @@ -82,7 +82,7 @@ SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen) { u32 keysd, keysu, keysh; - int xpos, ypos, pressure = 16384; + Uint16 xpos=0, ypos=0, pressure = 32767; touchPosition touch; scanKeys(); @@ -90,12 +90,18 @@ keysh = keysHeld(); keysu = keysUp(); touch=touchReadXY(); - xpos = (touch.px-128)*256; - ypos = (touch.py-96)*(65536/192); + xpos = (touch.px << 8) + 1; + ypos = (touch.py << 16) / 192 + 1; + /* TODO uses touch.x and touch.y for something. + we discussed in the mailing list having both "hardware x/y" and + "screen x/y" coordinates. */ - if (((keysd|keysh) & KEY_TOUCH)) { + if ((keysd & KEY_TOUCH)) { SDL_PrivateTouchPress(touchscreen, 0, xpos, ypos, pressure); } + if ((keysh & KEY_TOUCH)) { + SDL_PrivateTouchMove(touchscreen, 0, xpos, ypos, pressure); + } if ((keysu & KEY_TOUCH)) { SDL_PrivateTouchRelease(touchscreen, 0); } }