Added reading of event* for touch events.
authorJim Grandpre <jim.tla@gmail.com>
Fri, 28 May 2010 01:26:52 -0400
changeset 4642057e8762d2a1
parent 4641 49a97daea6ec
child 4643 8806b78988f7
Added reading of event* for touch events.
include/SDL_events.h
src/events/SDL_events.c
src/events/SDL_touch.c
src/events/SDL_touch_c.h
src/video/x11/SDL_eventtouch.h
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11video.h
touchTest/makefile
touchTest/touchPong
touchTest/touchSimp
touchTest/touchSimp.c
touchTest/touchTest.c
     1.1 --- a/include/SDL_events.h	Thu May 27 01:21:37 2010 -0400
     1.2 +++ b/include/SDL_events.h	Fri May 28 01:26:52 2010 -0400
     1.3 @@ -310,6 +310,8 @@
     1.4      Uint8 state;        /**< The current button state */
     1.5      Uint8 fingerId;
     1.6      Uint8 padding1;
     1.7 +    int x;
     1.8 +    int y;
     1.9  } SDL_TouchFingerEvent;
    1.10  
    1.11  
     2.1 --- a/src/events/SDL_events.c	Thu May 27 01:21:37 2010 -0400
     2.2 +++ b/src/events/SDL_events.c	Fri May 28 01:26:52 2010 -0400
     2.3 @@ -254,6 +254,7 @@
     2.4      retcode = 0;
     2.5      retcode += SDL_KeyboardInit();
     2.6      retcode += SDL_MouseInit();
     2.7 +    retcode += SDL_TouchInit();
     2.8      retcode += SDL_QuitInit();
     2.9      if (retcode < 0) {
    2.10          /* We don't expect them to fail, but... */
     3.1 --- a/src/events/SDL_touch.c	Thu May 27 01:21:37 2010 -0400
     3.2 +++ b/src/events/SDL_touch.c	Fri May 28 01:26:52 2010 -0400
     3.3 @@ -36,8 +36,15 @@
     3.4  int
     3.5  SDL_TouchInit(void)
     3.6  {
     3.7 +    SDL_Touch touch;
     3.8 +    touch.pressure_max = 0;
     3.9 +    touch.pressure_min = 0;
    3.10 +    touch.id = 0; //Should be function? 
    3.11 +    
    3.12 +    SDL_AddTouch(&touch, "Touch1");
    3.13      return (0);
    3.14  }
    3.15 +
    3.16  SDL_Touch *
    3.17  SDL_GetTouch(int id)
    3.18  {
    3.19 @@ -48,13 +55,13 @@
    3.20      return SDL_touchPads[index];
    3.21  }
    3.22  
    3.23 -SDL_Finger *
    3.24 -SDL_GetFinger(SDL_Touch* touch,int id)
    3.25 +SDL_Touch *
    3.26 +SDL_GetTouchIndex(int index)
    3.27  {
    3.28 -    int index = SDL_GetFingerIndexId(touch,id);
    3.29 -    if(index < 0 || index >= touch->num_fingers)
    3.30 -	return NULL;
    3.31 -    return touch->fingers[index];
    3.32 +    if (index < 0 || index >= SDL_num_touch) {
    3.33 +        return NULL;
    3.34 +    }
    3.35 +    return SDL_touchPads[index];
    3.36  }
    3.37  
    3.38  int
    3.39 @@ -67,6 +74,17 @@
    3.40      return -1;
    3.41  }
    3.42  
    3.43 +
    3.44 +SDL_Finger *
    3.45 +SDL_GetFinger(SDL_Touch* touch,int id)
    3.46 +{
    3.47 +    int index = SDL_GetFingerIndexId(touch,id);
    3.48 +    if(index < 0 || index >= touch->num_fingers)
    3.49 +	return NULL;
    3.50 +    return touch->fingers[index];
    3.51 +}
    3.52 +
    3.53 +
    3.54  int
    3.55  SDL_GetTouchIndexId(int id)
    3.56  {
    3.57 @@ -83,8 +101,7 @@
    3.58  }
    3.59  
    3.60  int
    3.61 -SDL_AddTouch(const SDL_Touch * touch, char *name, int pressure_max,
    3.62 -             int pressure_min, int ends)
    3.63 +SDL_AddTouch(const SDL_Touch * touch, char *name)
    3.64  {
    3.65      SDL_Touch **touchPads;
    3.66      int selected_touch;
    3.67 @@ -118,11 +135,13 @@
    3.68      length = SDL_strlen(name);
    3.69      SDL_touchPads[index]->focus = 0;
    3.70      SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
    3.71 -    SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);
    3.72 -    SDL_touchPads[index]->pressure_max = pressure_max;
    3.73 -    SDL_touchPads[index]->pressure_min = pressure_min;
    3.74 +    SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);   
    3.75 +
    3.76 +    SDL_touchPads[index]->num_fingers = 0;
    3.77 +    SDL_touchPads[index]->buttonstate = 0;
    3.78 +    SDL_touchPads[index]->relative_mode = SDL_FALSE;
    3.79 +    SDL_touchPads[index]->flush_motion = SDL_FALSE;
    3.80      
    3.81 -
    3.82      return index;
    3.83  }
    3.84  
    3.85 @@ -239,7 +258,7 @@
    3.86      
    3.87      if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
    3.88          SDL_SetError("Finger ID already in use");
    3.89 -    }
    3.90 +	}
    3.91  
    3.92      /* Add the touch to the list of touch */
    3.93      fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
    3.94 @@ -250,7 +269,7 @@
    3.95      }
    3.96  
    3.97      touch->fingers = fingers;
    3.98 -    index = SDL_num_touch++;
    3.99 +    index = touch->num_fingers++;
   3.100  
   3.101      touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(*(touch->fingers[index])));
   3.102      if (!touch->fingers[index]) {
   3.103 @@ -265,7 +284,7 @@
   3.104  int
   3.105  SDL_DelFinger(SDL_Touch* touch,int fingerid)
   3.106  {
   3.107 -    int index = SLD_GetFingerIndexId(touch,fingerid);
   3.108 +    int index = SDL_GetFingerIndexId(touch,fingerid);
   3.109      SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
   3.110  
   3.111      if (!finger) {
   3.112 @@ -282,6 +301,7 @@
   3.113  int
   3.114  SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
   3.115  {
   3.116 +  int posted;
   3.117      SDL_Touch* touch = SDL_GetTouch(id);
   3.118      if(down) {
   3.119  	SDL_Finger nf;
   3.120 @@ -300,9 +320,11 @@
   3.121  	    SDL_Event event;
   3.122  	    event.tfinger.type = SDL_FINGERDOWN;
   3.123  	    event.tfinger.touchId = (Uint8) id;
   3.124 +	    event.tfinger.x = x;
   3.125 +	    event.tfinger.y = y;
   3.126  	    event.tfinger.state = touch->buttonstate;
   3.127  	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   3.128 -	    event.fingerId = id;
   3.129 +	    event.tfinger.fingerId = id;
   3.130  	    posted = (SDL_PushEvent(&event) > 0);
   3.131  	}
   3.132  	return posted;
   3.133 @@ -316,7 +338,7 @@
   3.134  	    event.tfinger.touchId = (Uint8) id;
   3.135  	    event.tfinger.state = touch->buttonstate;
   3.136  	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   3.137 -	    event.fingerId = id;
   3.138 +	    event.tfinger.fingerId = id;
   3.139  	    posted = (SDL_PushEvent(&event) > 0);
   3.140  	}
   3.141  	return posted;
   3.142 @@ -339,69 +361,76 @@
   3.143          return 0;
   3.144      }
   3.145  
   3.146 -    /* the relative motion is calculated regarding the system cursor last position */
   3.147 -    if (relative) {
   3.148 -        xrel = x;
   3.149 -        yrel = y;
   3.150 -        x = (finger->last_x + x);
   3.151 -        y = (finger->last_y + y);
   3.152 -    } else {
   3.153 -        xrel = x - finger->last_x;
   3.154 -        yrel = y - finger->last_y;
   3.155 +    if(finger == NULL)
   3.156 +	SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure);
   3.157 +    else {
   3.158 +	/* the relative motion is calculated regarding the last position */
   3.159 +	if (relative) {
   3.160 +	    xrel = x;
   3.161 +	    yrel = y;
   3.162 +	    x = (finger->last_x + x);
   3.163 +	    y = (finger->last_y + y);
   3.164 +	} else {
   3.165 +	    if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
   3.166 +	    if(y < 0) y = finger->last_y; /*The other is marked as -1*/
   3.167 +	    xrel = x - finger->last_x;
   3.168 +	    yrel = y - finger->last_y;
   3.169 +	}
   3.170 +	
   3.171 +	/* Drop events that don't change state */
   3.172 +	if (!xrel && !yrel) {
   3.173 +#if 0
   3.174 +	    printf("Touch event didn't change state - dropped!\n");
   3.175 +#endif
   3.176 +	    return 0;
   3.177 +	}
   3.178 +	
   3.179 +	/* Update internal touch coordinates */
   3.180 +	
   3.181 +	finger->x = x;
   3.182 +	finger->y = y;
   3.183 +	
   3.184 +	/*Should scale to window? Normalize? Maintain Aspect?*/
   3.185 +	//SDL_GetWindowSize(touch->focus, &x_max, &y_max);
   3.186 +	
   3.187 +	/* make sure that the pointers find themselves inside the windows */
   3.188 +	/* only check if touch->xmax is set ! */
   3.189 +	/*
   3.190 +	  if (x_max && touch->x > x_max) {
   3.191 +	  touch->x = x_max;
   3.192 +	  } else if (touch->x < 0) {
   3.193 +	  touch->x = 0;
   3.194 +	  }
   3.195 +	  
   3.196 +	  if (y_max && touch->y > y_max) {
   3.197 +	  touch->y = y_max;
   3.198 +	  } else if (touch->y < 0) {
   3.199 +	  touch->y = 0;
   3.200 +	  }
   3.201 +	*/
   3.202 +	finger->xdelta += xrel;
   3.203 +	finger->ydelta += yrel;
   3.204 +	finger->pressure = pressure;
   3.205 +	
   3.206 +	
   3.207 +	
   3.208 +	/* Post the event, if desired */
   3.209 +	posted = 0;
   3.210 +	if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
   3.211 +	    SDL_Event event;
   3.212 +	    event.tfinger.type = SDL_FINGERMOTION;
   3.213 +	    event.tfinger.touchId = (Uint8) index;
   3.214 +	    event.tfinger.x = x;
   3.215 +	    event.tfinger.y = y;
   3.216 +	    event.tfinger.state = touch->buttonstate;
   3.217 +	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   3.218 +	    posted = (SDL_PushEvent(&event) > 0);
   3.219 +	}
   3.220 +	finger->last_x = finger->x;
   3.221 +	finger->last_y = finger->y;
   3.222 +	return posted;
   3.223      }
   3.224 -
   3.225 -    /* Drop events that don't change state */
   3.226 -    if (!xrel && !yrel) {
   3.227 -#if 0
   3.228 -        printf("Touch event didn't change state - dropped!\n");
   3.229 -#endif
   3.230 -        return 0;
   3.231 -    }
   3.232 -
   3.233 -    /* Update internal touch coordinates */
   3.234 -
   3.235 -    finger->x = x;
   3.236 -    finger->y = y;
   3.237 -
   3.238 -    /*Should scale to window? Normalize? Maintain Aspect?*/
   3.239 -    //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
   3.240 -
   3.241 -    /* make sure that the pointers find themselves inside the windows */
   3.242 -    /* only check if touch->xmax is set ! */
   3.243 -    /*
   3.244 -    if (x_max && touch->x > x_max) {
   3.245 -        touch->x = x_max;
   3.246 -    } else if (touch->x < 0) {
   3.247 -        touch->x = 0;
   3.248 -    }
   3.249 -
   3.250 -    if (y_max && touch->y > y_max) {
   3.251 -        touch->y = y_max;
   3.252 -    } else if (touch->y < 0) {
   3.253 -        touch->y = 0;
   3.254 -    }
   3.255 -    */
   3.256 -    finger->xdelta += xrel;
   3.257 -    finger->ydelta += yrel;
   3.258 -    finger->pressure = pressure;
   3.259 -
   3.260 -
   3.261 -
   3.262 -    /* Post the event, if desired */
   3.263 -    posted = 0;
   3.264 -    if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
   3.265 -        SDL_Event event;
   3.266 -        event.tfinger.type = SDL_FINGERMOTION;
   3.267 -        event.tfinger.which = (Uint8) index;
   3.268 -        event.tfinger.state = touch->buttonstate;
   3.269 -        event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   3.270 -        posted = (SDL_PushEvent(&event) > 0);
   3.271 -    }
   3.272 -    finger->last_x = finger->x;
   3.273 -    finger->last_y = finger->y;
   3.274 -    return posted;
   3.275  }
   3.276 -
   3.277  int
   3.278  SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
   3.279  {
   3.280 @@ -441,7 +470,7 @@
   3.281      if (SDL_GetEventState(type) == SDL_ENABLE) {
   3.282          SDL_Event event;
   3.283          event.type = type;
   3.284 -        event.tbutton.which = (Uint8) index;
   3.285 +        event.tbutton.touchId = (Uint8) index;
   3.286          event.tbutton.state = state;
   3.287          event.tbutton.button = button;
   3.288          event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
     4.1 --- a/src/events/SDL_touch_c.h	Thu May 27 01:21:37 2010 -0400
     4.2 +++ b/src/events/SDL_touch_c.h	Fri May 28 01:26:52 2010 -0400
     4.3 @@ -51,9 +51,6 @@
     4.4    int tilt;                   /* for future use */
     4.5    int rotation;               /* for future use */
     4.6    
     4.7 -  int total_ends;
     4.8 -  int current_end;
     4.9 -  
    4.10    /* Data common to all touch */
    4.11    int id;
    4.12    SDL_Window *focus;
    4.13 @@ -73,14 +70,23 @@
    4.14  /* Initialize the touch subsystem */
    4.15  extern int SDL_TouchInit(void);
    4.16  
    4.17 -/* Get the touch at an index */
    4.18 -extern SDL_Touch *SDL_GetTouch(int index);
    4.19 +/*Get the touch at an index */
    4.20 +extern SDL_Touch *SDL_GetTouchIndex(int index);
    4.21 +
    4.22 +/* Get the touch with id = id */
    4.23 +extern SDL_Touch *SDL_GetTouch(int id);
    4.24 +
    4.25 +/*Get the finger at an index */
    4.26 +extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index);
    4.27 +
    4.28 +/* Get the finger with id = id */
    4.29 +extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,int id);
    4.30 +
    4.31  
    4.32  /* Add a touch, possibly reattaching at a particular index (or -1),
    4.33 -   returning the index of the touch, or -1 if there was an error.
    4.34 - */
    4.35 -extern int SDL_AddTouch(const SDL_Touch * touch, char *name,
    4.36 -                        int pressure_max, int pressure_min, int ends);
    4.37 +   returning the index of the touch, or -1 if there was an error. */
    4.38 +extern int SDL_AddTouch(const SDL_Touch * touch, char *name);
    4.39 +                     
    4.40  
    4.41  /* Remove a touch at an index, clearing the slot for later */
    4.42  extern void SDL_DelTouch(int index);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/video/x11/SDL_eventtouch.h	Fri May 28 01:26:52 2010 -0400
     5.3 @@ -0,0 +1,42 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2010 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#ifndef _SDL_eventtouch_h
    5.28 +#define _SDL_eventtouch_h
    5.29 +
    5.30 +
    5.31 +//What should this be?
    5.32 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    5.33 +typedef struct EventTouchData
    5.34 +{
    5.35 +    int x,y,pressure,finger; //Temporary Variables until sync
    5.36 +    int eventStream;
    5.37 +} EventTouchData;
    5.38 +#endif
    5.39 +
    5.40 +//extern void X11_InitMouse(_THIS);
    5.41 +//extern void X11_QuitMouse(_THIS);
    5.42 +
    5.43 +#endif /* _SDL_eventtouch_h */
    5.44 +
    5.45 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/x11/SDL_x11events.c	Thu May 27 01:21:37 2010 -0400
     6.2 +++ b/src/video/x11/SDL_x11events.c	Fri May 28 01:26:52 2010 -0400
     6.3 @@ -28,9 +28,16 @@
     6.4  #include "SDL_x11video.h"
     6.5  #include "../../events/SDL_events_c.h"
     6.6  #include "../../events/SDL_mouse_c.h"
     6.7 +#include "../../events/SDL_touch_c.h"
     6.8  
     6.9  #include "SDL_syswm.h"
    6.10  
    6.11 +#include <stdio.h>
    6.12 +
    6.13 +//Touch Input/event* includes
    6.14 +#include <linux/input.h>
    6.15 +#include <fcntl.h>
    6.16 +
    6.17  static void
    6.18  X11_DispatchEvent(_THIS)
    6.19  {
    6.20 @@ -410,8 +417,65 @@
    6.21      }
    6.22  
    6.23  
    6.24 -    /* Process Touch events - TODO When X gets touch support, REMOVE THIS*/
    6.25 -    
    6.26 +    /* Process Touch events - TODO When X gets touch support, use that instead*/
    6.27 +    int i = 0,rd;
    6.28 +    char * name[256];
    6.29 +    struct input_event ev[64];
    6.30 +    int size = sizeof (struct input_event);
    6.31 +    static int initd = 0; //TODO - HACK!
    6.32 +    for(i = 0;i < SDL_GetNumTouch();++i) {
    6.33 +	SDL_Touch* touch = SDL_GetTouchIndex(i);
    6.34 +	if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
    6.35 +	EventTouchData* data;
    6.36 +	if(!initd){//data->eventStream <= 0) {
    6.37 +	    touch->driverdata = SDL_malloc(sizeof(EventTouchData));
    6.38 +	    data = (EventTouchData*)(touch->driverdata);
    6.39 +	    printf("Openning device...\n");
    6.40 +	    data->eventStream = open("/dev/input/wacom-touch", 
    6.41 +				     O_RDONLY | O_NONBLOCK);
    6.42 +	    ioctl (data->eventStream, EVIOCGNAME (sizeof (name)), name);
    6.43 +	    printf ("Reading From : %s\n", name);
    6.44 +	    initd = 1;
    6.45 +	}
    6.46 +	else
    6.47 +	 data = (EventTouchData*)(touch->driverdata);
    6.48 +	if(data->eventStream <= 0) 
    6.49 +	    printf("Error: Couldn't open stream\n");
    6.50 +	rd = read(data->eventStream, ev, size * 64);
    6.51 +	//printf("Got %i/%i bytes\n",rd,size);
    6.52 +	if(rd >= size) {
    6.53 +	    for (i = 0; i < rd / sizeof(struct input_event); i++) {
    6.54 +		switch (ev[i].type) {
    6.55 +		case EV_ABS:
    6.56 +		    //printf("Got position x: %i!\n",data->x);
    6.57 +		    if(ev[i].code == ABS_X)
    6.58 +			data->x = ev[i].value;
    6.59 +		    else if (ev[i].code == ABS_Y)
    6.60 +			data->y = ev[i].value;
    6.61 +		    break;
    6.62 +		case EV_MSC:
    6.63 +		    if(ev[i].code == MSC_SERIAL)
    6.64 +			data->finger = ev[i].value;
    6.65 +		    break;
    6.66 +		case EV_SYN:
    6.67 +		    data->finger -= 1; /*Wacom indexes fingers from 1, 
    6.68 +					 I index from 0*/		  
    6.69 +		    if(data->x >= 0 || data->y >= 0)
    6.70 +			SDL_SendTouchMotion(touch->id,data->finger, 
    6.71 +					    SDL_FALSE,data->x,data->y,
    6.72 +					    data->pressure);
    6.73 +		    
    6.74 +		    //printf("Synched: %i tx: %i, ty: %i\n",
    6.75 +		    //	   data->finger,data->x,data->y);
    6.76 +		    data->x = -1;
    6.77 +		    data->y = -1;
    6.78 +		    data->pressure = -1;
    6.79 +		    
    6.80 +		    break;		
    6.81 +		}
    6.82 +	    }
    6.83 +	}
    6.84 +    }
    6.85  }
    6.86  
    6.87  /* This is so wrong it hurts */
     7.1 --- a/src/video/x11/SDL_x11video.h	Thu May 27 01:21:37 2010 -0400
     7.2 +++ b/src/video/x11/SDL_x11video.h	Fri May 28 01:26:52 2010 -0400
     7.3 @@ -53,6 +53,7 @@
     7.4  #include "SDL_x11keyboard.h"
     7.5  #include "SDL_x11modes.h"
     7.6  #include "SDL_x11mouse.h"
     7.7 +#include "SDL_eventtouch.h"
     7.8  #include "SDL_x11opengl.h"
     7.9  #include "SDL_x11window.h"
    7.10  
     8.1 --- a/touchTest/makefile	Thu May 27 01:21:37 2010 -0400
     8.2 +++ b/touchTest/makefile	Fri May 28 01:26:52 2010 -0400
     8.3 @@ -1,3 +1,5 @@
     8.4  SDLTest : touchSimp.c touchPong.c
     8.5 +	gcc touchTest.c -o touchTest `sdl-config --cflags --libs` -g		
     8.6  	gcc touchSimp.c -o touchSimp `sdl-config --cflags --libs` -g
     8.7  	gcc touchPong.c -o touchPong `sdl-config --cflags --libs` -g
     8.8 +
     9.1 Binary file touchTest/touchPong has changed
    10.1 Binary file touchTest/touchSimp has changed
    11.1 --- a/touchTest/touchSimp.c	Thu May 27 01:21:37 2010 -0400
    11.2 +++ b/touchTest/touchSimp.c	Fri May 28 01:26:52 2010 -0400
    11.3 @@ -186,6 +186,10 @@
    11.4  	    case SDL_MOUSEBUTTONUP:
    11.5  	      bstatus &= ~(1<<(event.button.button-1));
    11.6  	      break;
    11.7 +	    case SDL_FINGERMOTION:
    11.8 +	      printf("Holy SH!T\n");
    11.9 +	      break;
   11.10 +		     
   11.11  	    }
   11.12  	}
   11.13  
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/touchTest/touchTest.c	Fri May 28 01:26:52 2010 -0400
    12.3 @@ -0,0 +1,168 @@
    12.4 +#include <stdio.h>
    12.5 +#include <SDL.h>
    12.6 +#include <math.h>
    12.7 +#include "../src/events/SDL_touch_c.h" //BAD!!!
    12.8 +
    12.9 +#define PI 3.1415926535897
   12.10 +#define WIDTH 640
   12.11 +#define HEIGHT 480
   12.12 +#define BPP 4
   12.13 +#define DEPTH 32
   12.14 +
   12.15 +int mousx,mousy;
   12.16 +int keystat[512];
   12.17 +int bstatus;
   12.18 +
   12.19 +
   12.20 +
   12.21 +
   12.22 +typedef struct {
   12.23 +  int x,y;
   12.24 +} Point;
   12.25 +
   12.26 +void handler (int sig)
   12.27 +{
   12.28 +  printf ("\nexiting...(%d)\n", sig);
   12.29 +  exit (0);
   12.30 +}
   12.31 +
   12.32 +void perror_exit (char *error)
   12.33 +{
   12.34 +  perror (error);
   12.35 +  handler (9);
   12.36 +}
   12.37 +
   12.38 +
   12.39 +void setpix(SDL_Surface *screen, int x, int y, int col)
   12.40 +{
   12.41 +  Uint32 *pixmem32;
   12.42 +  Uint32 colour;
   12.43 +  
   12.44 +  if((unsigned)x > screen->w) return;
   12.45 +  if((unsigned)y > screen->h) return;
   12.46 +
   12.47 +  colour = SDL_MapRGB( screen->format, (col>>16)&0xFF, (col>>8)&0xFF, col&0xFF);
   12.48 +  
   12.49 +  pixmem32 = (Uint32*) screen->pixels  + y*screen->pitch/BPP + x;
   12.50 +  *pixmem32 = colour;
   12.51 +}
   12.52 +
   12.53 +void drawCircle(SDL_Surface* screen,int x,int y,int r,int c)
   12.54 +{
   12.55 +
   12.56 +  float a;
   12.57 +  for(a=0;a<2*PI;a+=1.f/(float)r)
   12.58 +  {
   12.59 +    setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c);
   12.60 +  }
   12.61 +}
   12.62 +
   12.63 +void DrawScreen(SDL_Surface* screen, int h)
   12.64 +{
   12.65 +  int x, y, xm,ym,c;
   12.66 +  if(SDL_MUSTLOCK(screen))
   12.67 +    {                                              
   12.68 +      if(SDL_LockSurface(screen) < 0) return;
   12.69 +    }
   12.70 +  for(y = 0; y < screen->h; y++ )
   12.71 +    {
   12.72 +      for( x = 0; x < screen->w; x++ )
   12.73 +        {
   12.74 +	  //setpixel(screen, x, y, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
   12.75 +	  //xm = (x+h)%screen->w;
   12.76 +	  //ym = (y+h)%screen->w;
   12.77 +	  //c = sin(h/256*2*PI)*x*y/screen->w/screen->h;
   12.78 +	  //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c);
   12.79 +	  setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
   12.80 +        }
   12.81 +    }
   12.82 +  drawCircle(screen,mousx,mousy,30,0xFFFFFF);
   12.83 +  
   12.84 +  
   12.85 +  if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
   12.86 +  
   12.87 +  SDL_Flip(screen);
   12.88 +}
   12.89 +
   12.90 +SDL_Surface* initScreen(int width,int height)
   12.91 +{
   12.92 +  return SDL_SetVideoMode(width, height, DEPTH,
   12.93 +			  SDL_HWSURFACE | SDL_RESIZABLE);
   12.94 +}
   12.95 +
   12.96 +int main(int argc, char* argv[])
   12.97 +{  
   12.98 +  SDL_Surface *screen;
   12.99 +  SDL_Event event;
  12.100 +  
  12.101 +  int keypress = 0;
  12.102 +  int h=0,s=1,i,j;
  12.103 +
  12.104 +  memset(keystat,0,512*sizeof(keystat[0]));
  12.105 +  if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
  12.106 +  
  12.107 +  if (!(screen = initScreen(WIDTH,HEIGHT)))
  12.108 +    {
  12.109 +      SDL_Quit();
  12.110 +      return 1;
  12.111 +    }
  12.112 +
  12.113 +  while(!keystat[27]) {
  12.114 +    //Poll SDL
  12.115 +    while(SDL_PollEvent(&event)) 
  12.116 +      {
  12.117 +	switch (event.type) 
  12.118 +	  {
  12.119 +	  case SDL_QUIT:
  12.120 +	    keystat[27] = 1;
  12.121 +	    break;
  12.122 +	  case SDL_KEYDOWN:
  12.123 +	    //printf("%i\n",event.key.keysym.sym);
  12.124 +	    keystat[event.key.keysym.sym] = 1;
  12.125 +	    //keypress = 1;
  12.126 +	    break;
  12.127 +	  case SDL_KEYUP:
  12.128 +	      //printf("%i\n",event.key.keysym.sym);
  12.129 +	    keystat[event.key.keysym.sym] = 0;
  12.130 +	    //keypress = 1;
  12.131 +	    break;
  12.132 +	  case SDL_VIDEORESIZE:
  12.133 +	    if (!(screen = initScreen(event.resize.w,
  12.134 +				      event.resize.h)))
  12.135 +	      {
  12.136 +		SDL_Quit();
  12.137 +		return 1;
  12.138 +	      }
  12.139 +	    break;
  12.140 +	  case SDL_MOUSEMOTION:
  12.141 +	    mousx = event.motion.x;
  12.142 +	    mousy = event.motion.y; 
  12.143 +	    break;
  12.144 +	  case SDL_MOUSEBUTTONDOWN:
  12.145 +	    bstatus |=  (1<<(event.button.button-1));
  12.146 +	    break;
  12.147 +	  case SDL_MOUSEBUTTONUP:
  12.148 +	    bstatus &= ~(1<<(event.button.button-1));
  12.149 +	    break;
  12.150 +	  case SDL_FINGERMOTION:
  12.151 +	    i = 1;
  12.152 +	    
  12.153 +	    
  12.154 +	    printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
  12.155 +		   event.tfinger.x,event.tfinger.y);
  12.156 +		
  12.157 +	    break;	    
  12.158 +	  }
  12.159 +      }
  12.160 +    //And draw
  12.161 +    DrawScreen(screen,h);
  12.162 +    /*
  12.163 +      for(i=0;i<512;i++) 
  12.164 +      if(keystat[i]) printf("%i\n",i);
  12.165 +      printf("Buttons:%i\n",bstatus);
  12.166 +    */
  12.167 +  }  
  12.168 +  SDL_Quit();
  12.169 +      
  12.170 +  return 0;
  12.171 +}