Fixed testgesture to work on the iPhone
authorSam Lantinga <slouken@libsdl.org>
Wed, 09 Mar 2011 14:46:09 -0800
changeset 545663258b963fc1
parent 5455 5fbf5fc81aa8
child 5457 e4ee8761f5cd
Fixed testgesture to work on the iPhone
test/testgesture.c
     1.1 --- a/test/testgesture.c	Tue Mar 08 22:48:21 2011 -0800
     1.2 +++ b/test/testgesture.c	Wed Mar 09 14:46:09 2011 -0800
     1.3 @@ -5,10 +5,11 @@
     1.4   */
     1.5  
     1.6  #include <stdio.h>
     1.7 -#include <SDL.h>
     1.8  #include <math.h>
     1.9 -#include <SDL_touch.h>
    1.10 -#include <SDL_gesture.h>
    1.11 +
    1.12 +#include "SDL.h"
    1.13 +#include "SDL_touch.h"
    1.14 +#include "SDL_gesture.h"
    1.15  
    1.16  
    1.17  /* Make sure we have good macros for printing 32 and 64 bit values */
    1.18 @@ -44,9 +45,11 @@
    1.19  
    1.20  #define VERBOSE SDL_FALSE
    1.21  
    1.22 +SDL_Window *window;
    1.23  SDL_Event events[EVENT_BUF_SIZE];
    1.24  int eventWrite;
    1.25  
    1.26 +
    1.27  int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
    1.28  
    1.29  typedef struct {
    1.30 @@ -134,14 +137,15 @@
    1.31  
    1.32  void DrawScreen(SDL_Surface* screen)
    1.33  {
    1.34 -  int x, y, i;
    1.35 -  if(SDL_MUSTLOCK(screen))
    1.36 -    {                                              
    1.37 -      if(SDL_LockSurface(screen) < 0) return;
    1.38 -    }
    1.39 +  int i;
    1.40 +#if 1
    1.41 +  SDL_FillRect(screen, NULL, 0);
    1.42 +#else
    1.43 +  int x, y;
    1.44    for(y = 0;y < screen->h;y++)
    1.45      for(x = 0;x < screen->w;x++)
    1.46  	setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
    1.47 +#endif
    1.48  
    1.49    //draw Touch History
    1.50    for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) {
    1.51 @@ -175,14 +179,20 @@
    1.52    if(knob.p.x > 0)
    1.53      drawKnob(screen,knob);
    1.54    
    1.55 -  if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
    1.56 -  SDL_Flip(screen);
    1.57 +  SDL_UpdateWindowSurface(window);
    1.58  }
    1.59  
    1.60  SDL_Surface* initScreen(int width,int height)
    1.61  {
    1.62 -  return SDL_SetVideoMode(width, height, DEPTH,
    1.63 -			  SDL_HWSURFACE | SDL_RESIZABLE);
    1.64 +  if (!window) {
    1.65 +    window = SDL_CreateWindow("Gesture Test",
    1.66 +                              SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
    1.67 +                              WIDTH, HEIGHT, SDL_WINDOW_RESIZABLE);
    1.68 +  }
    1.69 +  if (!window) {
    1.70 +    return NULL;
    1.71 +  }
    1.72 +  return SDL_GetWindowSurface(window);
    1.73  }
    1.74  
    1.75  int main(int argc, char* argv[])
    1.76 @@ -237,13 +247,14 @@
    1.77  		break;
    1.78  	    }
    1.79  	    break;
    1.80 -	  case SDL_VIDEORESIZE:
    1.81 -	    if (!(screen = initScreen(event.resize.w,
    1.82 -				      event.resize.h)))
    1.83 +	  case SDL_WINDOWEVENT:
    1.84 +            if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
    1.85 +	      if (!(screen = initScreen(0, 0)))
    1.86  	      {
    1.87  		SDL_Quit();
    1.88  		return 1;
    1.89  	      }
    1.90 +            }
    1.91  	    break;
    1.92  	  case SDL_FINGERMOTION:
    1.93  #if VERBOSE