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. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Sun, 29 Jun 2008 21:32:31 +0000
branchgsoc2008_nds
changeset 26755e4274591163
parent 2674 f1d07ba2e275
child 2676 082cc3ffd7d8
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.
include/SDL_touchscreen.h
src/touchscreen/SDL_systouchscreen.h
src/touchscreen/SDL_touchscreen.c
src/touchscreen/SDL_touchscreen_c.h
src/touchscreen/nds/SDL_systouchscreen.c
     1.1 --- a/include/SDL_touchscreen.h	Mon Jun 23 11:55:26 2008 +0000
     1.2 +++ b/include/SDL_touchscreen.h	Sun Jun 29 21:32:31 2008 +0000
     1.3 @@ -107,11 +107,12 @@
     1.4  /*
     1.5   * Get the current X,Y position of the indicated point on the touchscreen.
     1.6   *
     1.7 - * If not NULL, *x is set to an integer in the range [-32768,32767]
     1.8 - * where -32768 is the left edge, 0 is center, 32767 is right edge.
     1.9 + * If not NULL, *x is set to an unsigned integer in the range [1,65535]
    1.10 + * where 1 is the left edge, 32768 is roughly center, 65535 is right edge.
    1.11   * Similarly with *y, for the top, center, and bottom, respectively.
    1.12 - * The returned value is an unsigned integer in the range [1,32767]
    1.13 - * that represents the pressure of the touch.
    1.14 + * The returned value is an unsigned integer in the range [1,65535],
    1.15 + * which represents the pressure of the touch.  This should be 32767 in
    1.16 + * non-pressure-sensitive driver implementations.
    1.17   * If not being touched, 0 is returned and *x and *y are unmodified.
    1.18   *
    1.19   * The touch point indices start at index 0.
    1.20 @@ -123,8 +124,8 @@
    1.21   *
    1.22   * On error, -1 is returned.
    1.23   */
    1.24 -extern DECLSPEC int SDLCALL SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen,
    1.25 -                                                    int point, int *x, int *y);
    1.26 +extern DECLSPEC Uint16 SDLCALL SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen,
    1.27 +                                                    int point, Uint16 *x, Uint16 *y);
    1.28  
    1.29  /*
    1.30   * Get the number of currently touched points on a touchscreen.
     2.1 --- a/src/touchscreen/SDL_systouchscreen.h	Mon Jun 23 11:55:26 2008 +0000
     2.2 +++ b/src/touchscreen/SDL_systouchscreen.h	Sun Jun 29 21:32:31 2008 +0000
     2.3 @@ -35,9 +35,9 @@
     2.4      int npoints;                /* Number of points currently touched */
     2.5      struct touchpoint
     2.6      {
     2.7 -        int x;
     2.8 -        int y;
     2.9 -        int pressure;
    2.10 +        Uint16 x;
    2.11 +        Uint16 y;
    2.12 +        Uint16 pressure;
    2.13      } *points;                   /* Current ball motion deltas */
    2.14  
    2.15      struct touchscreen_hwdata *hwdata;     /* Driver dependent information */
     3.1 --- a/src/touchscreen/SDL_touchscreen.c	Mon Jun 23 11:55:26 2008 +0000
     3.2 +++ b/src/touchscreen/SDL_touchscreen.c	Sun Jun 29 21:32:31 2008 +0000
     3.3 @@ -210,8 +210,8 @@
     3.4  /*
     3.5   * Get the current X,Y position of the indicated point on the touchscreen
     3.6   */
     3.7 -int
     3.8 -SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, int point, int *x, int *y)
     3.9 +Uint16
    3.10 +SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, int point, Uint16 *x, Uint16 *y)
    3.11  {
    3.12      int retval;
    3.13  
    3.14 @@ -328,10 +328,8 @@
    3.15  
    3.16  /* These are global for SDL_systouchscreen.c and SDL_events.c */
    3.17  int
    3.18 -SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point,
    3.19 -                                 int x, int y, int pressure) {
    3.20 +SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point, Uint16 x, Uint16 y, Uint16 pressure) {
    3.21      int posted;
    3.22 -    int ev = SDL_TOUCHMOTION;
    3.23  
    3.24      if (!ValidTouchscreen(&touchscreen)) {
    3.25          return -1;
    3.26 @@ -353,12 +351,72 @@
    3.27  
    3.28      /* new touch point!  that means a TOUCHPRESSED event is due. */
    3.29      if(point >= touchscreen->npoints) {
    3.30 -        ev = SDL_TOUCHPRESSED;
    3.31          point = touchscreen->npoints;
    3.32          ++touchscreen->npoints;
    3.33      }
    3.34  
    3.35      /* no motion, no change, don't report an event. */
    3.36 +    if(touchscreen->points[point].pressure > 0) {
    3.37 +        SDL_SetError("Warning: touch point %d was already pressed", point);
    3.38 +        return -1;
    3.39 +    }
    3.40 +
    3.41 +    /* Update internal touchscreen point state */
    3.42 +    touchscreen->points[point].x = x;
    3.43 +    touchscreen->points[point].y = y;
    3.44 +    touchscreen->points[point].pressure = pressure;
    3.45 +
    3.46 +    /* Post the event, if desired */
    3.47 +    posted = 0;
    3.48 +#if !SDL_EVENTS_DISABLED
    3.49 +    if (SDL_ProcessEvents[SDL_TOUCHPRESSED] == SDL_ENABLE) {
    3.50 +        SDL_Event event;
    3.51 +        event.touch.type = SDL_TOUCHPRESSED;
    3.52 +        event.touch.which = touchscreen->index;
    3.53 +        event.touch.point = point;
    3.54 +        event.touch.xpos = x;
    3.55 +        event.touch.ypos = y;
    3.56 +        event.touch.pressure = pressure;
    3.57 +        if ((SDL_EventOK == NULL)
    3.58 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    3.59 +            posted = 1;
    3.60 +            SDL_PushEvent(&event);
    3.61 +        }
    3.62 +    }
    3.63 +#endif /* !SDL_EVENTS_DISABLED */
    3.64 +    return (posted);
    3.65 +}
    3.66 +
    3.67 +int
    3.68 +SDL_PrivateTouchMove(SDL_Touchscreen * touchscreen, int point,
    3.69 +                                 Uint16 x, Uint16 y, Uint16 pressure) {
    3.70 +    int posted;
    3.71 +
    3.72 +    if (!ValidTouchscreen(&touchscreen)) {
    3.73 +        return -1;
    3.74 +    }
    3.75 +
    3.76 +    if(point >= touchscreen->maxpoints) {
    3.77 +        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
    3.78 +        return -1;
    3.79 +    }
    3.80 +
    3.81 +    /* on neg. point, set the given args as the *only* point.
    3.82 +       so set the struct to have no points pressed, then continue as normal. */
    3.83 +    if(point < 0) {
    3.84 +        point = 0;
    3.85 +        touchscreen->npoints = 0;
    3.86 +        SDL_memset(touchscreen->points, 0,
    3.87 +                   touchscreen->maxpoints * sizeof(touchscreen->points[0]));
    3.88 +    }
    3.89 +
    3.90 +    /* new touch point!  that means a TOUCHPRESSED event is due. */
    3.91 +    if(point >= touchscreen->npoints || touchscreen->points[point].pressure == 0) {
    3.92 +        SDL_SetError("Touch point %d shouldn't move before it's pressed.", point);
    3.93 +        return -1;
    3.94 +    }
    3.95 +
    3.96 +    /* no motion, no change, don't report an event. */
    3.97      if(touchscreen->points[point].x == x &&
    3.98         touchscreen->points[point].y == y &&
    3.99         touchscreen->points[point].pressure == pressure) {
   3.100 @@ -373,9 +431,9 @@
   3.101      /* Post the event, if desired */
   3.102      posted = 0;
   3.103  #if !SDL_EVENTS_DISABLED
   3.104 -    if (SDL_ProcessEvents[ev] == SDL_ENABLE) {
   3.105 +    if (SDL_ProcessEvents[SDL_TOUCHMOTION] == SDL_ENABLE) {
   3.106          SDL_Event event;
   3.107 -        event.touch.type = ev;
   3.108 +        event.touch.type = SDL_TOUCHMOTION;
   3.109          event.touch.which = touchscreen->index;
   3.110          event.touch.point = point;
   3.111          event.touch.xpos = x;
   3.112 @@ -394,6 +452,7 @@
   3.113  int
   3.114  SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point) {
   3.115      int posted;
   3.116 +    int i;
   3.117  
   3.118      if (!ValidTouchscreen(&touchscreen)) {
   3.119          return -1;
   3.120 @@ -418,7 +477,12 @@
   3.121  
   3.122      /* Update internal touchscreen point state */
   3.123      touchscreen->points[point].pressure = 0;
   3.124 +    touchscreen->points[point].x = 0;
   3.125 +    touchscreen->points[point].y = 0;
   3.126      if(touchscreen->npoints >= 0) --touchscreen->npoints;
   3.127 +    for(i = point; i < touchscreen->npoints; ++i) {
   3.128 +        touchscreen->points[i] = touchscreen->points[i+1];
   3.129 +    }
   3.130  
   3.131      /* Post the event, if desired */
   3.132      posted = 0;
     4.1 --- a/src/touchscreen/SDL_touchscreen_c.h	Mon Jun 23 11:55:26 2008 +0000
     4.2 +++ b/src/touchscreen/SDL_touchscreen_c.h	Sun Jun 29 21:32:31 2008 +0000
     4.3 @@ -32,11 +32,22 @@
     4.4  /* the point index starts at 0
     4.5   * if point < 0, release all points and set this to be the first (only) point.
     4.6   * if point >= touchscreen->maxpoints, error.
     4.7 - * otherwise, set or update the coordinates for the given point.
     4.8 - * return -1 if fatal error, 0 on success
     4.9 + * otherwise, add a point with the given coordinates.
    4.10 + * return < 0 if fatal error, >= 0 on success
    4.11   */
    4.12  extern int SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point,
    4.13 -                                 int x, int y, int pressure);
    4.14 -/* if point < 0, release all points. */
    4.15 +                                  Uint16 x, Uint16 y, Uint16 pressure);
    4.16 +/* if point < 0, release all points and set this to be the first (only) point.
    4.17 + * if point >= touchscreen->maxpoints, error.
    4.18 + * otherwise, update the coordinates for the given point.
    4.19 + * return < 0 if fatal error, >= 0 on success
    4.20 + */
    4.21 +extern int SDL_PrivateTouchMove(SDL_Touchscreen * touchscreen, int point,
    4.22 +                                 Uint16 x, Uint16 y, Uint16 pressure);
    4.23 +/* if point < 0, release all points.
    4.24 + * if point >= touchscreen->npoints, error.
    4.25 + * otherwise, remove the given point.
    4.26 + * return < 0 if fatal error, >= 0 on success
    4.27 + */
    4.28  extern int SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point);
    4.29  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/touchscreen/nds/SDL_systouchscreen.c	Mon Jun 23 11:55:26 2008 +0000
     5.2 +++ b/src/touchscreen/nds/SDL_systouchscreen.c	Sun Jun 29 21:32:31 2008 +0000
     5.3 @@ -82,7 +82,7 @@
     5.4  SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen)
     5.5  {
     5.6      u32 keysd, keysu, keysh;
     5.7 -    int xpos, ypos, pressure = 16384;
     5.8 +    Uint16 xpos=0, ypos=0, pressure = 32767;
     5.9      touchPosition touch;
    5.10  
    5.11      scanKeys();
    5.12 @@ -90,12 +90,18 @@
    5.13      keysh = keysHeld();
    5.14      keysu = keysUp();
    5.15      touch=touchReadXY();
    5.16 -    xpos = (touch.px-128)*256;
    5.17 -    ypos = (touch.py-96)*(65536/192);
    5.18 +    xpos = (touch.px << 8) + 1;
    5.19 +    ypos = (touch.py << 16) / 192 + 1;
    5.20 +    /* TODO uses touch.x and touch.y for something.
    5.21 +       we discussed in the mailing list having both "hardware x/y" and
    5.22 +       "screen x/y" coordinates. */
    5.23  
    5.24 -    if (((keysd|keysh) & KEY_TOUCH)) {
    5.25 +    if ((keysd & KEY_TOUCH)) {
    5.26          SDL_PrivateTouchPress(touchscreen, 0, xpos, ypos, pressure);
    5.27      }
    5.28 +    if ((keysh & KEY_TOUCH)) {
    5.29 +    	SDL_PrivateTouchMove(touchscreen, 0, xpos, ypos, pressure); 
    5.30 +    }
    5.31      if ((keysu & KEY_TOUCH)) {
    5.32          SDL_PrivateTouchRelease(touchscreen, 0);
    5.33      }
}