test/testgesture.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 12 Dec 2014 21:02:46 +0100
changeset 9274 f95cc158ed4f
parent 9273 9f1c18388f2c
child 9275 a40415296b77
permissions -rw-r--r--
Replaced sqrt() with SDL_sqrt() in test program.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     1
/*
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 7900
diff changeset
     2
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     4
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     6
  arising from the use of this software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5460
diff changeset
    11
*/
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    12
/*  Usage:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    13
 *  Spacebar to begin recording a gesture on all touches.
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    14
 *  s to save all touches into "./gestureSave"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    15
 *  l to load all touches from "./gestureSave"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    16
 */
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    17
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    18
#include <stdio.h>
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    19
#include <math.h>
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    20
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    21
#include "SDL.h"
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    22
#include "SDL_touch.h"
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    23
#include "SDL_gesture.h"
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    24
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    25
#define WIDTH 640
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    26
#define HEIGHT 480
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    27
#define BPP 4
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    28
#define DEPTH 32
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    29
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    30
/* MUST BE A POWER OF 2! */
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    31
#define EVENT_BUF_SIZE 256
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    32
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    33
5458
a96fcc853bef Use SDL_Log() so the messages show up on iPhone and Android
Sam Lantinga <slouken@libsdl.org>
parents: 5457
diff changeset
    34
#define VERBOSE 0
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    35
5457
e4ee8761f5cd Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents: 5456
diff changeset
    36
static SDL_Event events[EVENT_BUF_SIZE];
e4ee8761f5cd Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents: 5456
diff changeset
    37
static int eventWrite;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    38
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    39
5457
e4ee8761f5cd Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents: 5456
diff changeset
    40
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    41
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    42
typedef struct {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    43
  float x,y;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    44
} Point;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    45
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    46
typedef struct {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    47
  float ang,r;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    48
  Point p;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    49
} Knob;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    50
5457
e4ee8761f5cd Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents: 5456
diff changeset
    51
static Knob knob;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    52
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    53
void handler (int sig)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    54
{
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
    55
  SDL_Log ("exiting...(%d)", sig);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    56
  exit (0);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    57
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    58
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    59
void perror_exit (char *error)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    60
{
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    61
  perror (error);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    62
  handler (9);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    63
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    64
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    65
void setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    66
{
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    67
  Uint32 *pixmem32;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    68
  Uint32 colour;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    69
  Uint8 r,g,b;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    70
  int x = (int)_x;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    71
  int y = (int)_y;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    72
  float a;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    73
6790
475f0a544157 Fixed bug 1672 - Found: seg-fault with testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    74
  if(x < 0 || x >= screen->w) return;
475f0a544157 Fixed bug 1672 - Found: seg-fault with testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    75
  if(y < 0 || y >= screen->h) return;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    76
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    77
  pixmem32 = (Uint32*) screen->pixels  + y*screen->pitch/BPP + x;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    78
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    79
  SDL_memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    80
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    81
  SDL_GetRGB(colour,screen->format,&r,&g,&b);
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    82
  /* r = 0;g = 0; b = 0; */
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    83
  a = (float)((col>>24)&0xFF);
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    84
  if(a == 0) a = 0xFF; /* Hack, to make things easier. */
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    85
  a /= 0xFF;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    86
  r = (Uint8)(r*(1-a) + ((col>>16)&0xFF)*(a));
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    87
  g = (Uint8)(g*(1-a) + ((col>> 8)&0xFF)*(a));
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    88
  b = (Uint8)(b*(1-a) + ((col>> 0)&0xFF)*(a));
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    89
  colour = SDL_MapRGB( screen->format,r, g, b);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    90
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    91
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    92
  *pixmem32 = colour;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    93
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    94
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    95
void drawLine(SDL_Surface *screen,float x0,float y0,float x1,float y1,unsigned int col) {
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    96
  float t;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    97
  for(t=0;t<1;t+=(float)(1.f/SDL_max(SDL_fabs(x0-x1),SDL_fabs(y0-y1))))
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    98
    setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    99
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   100
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   101
void drawCircle(SDL_Surface* screen,float x,float y,float r,unsigned int c)
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   102
{
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   103
  float tx,ty;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   104
  float xr;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   105
  for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
9274
f95cc158ed4f Replaced sqrt() with SDL_sqrt() in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9273
diff changeset
   106
    xr = (float)SDL_sqrt(r*r - ty*ty);
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   107
    if(r > 0) { /* r > 0 ==> filled circle */
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   108
      for(tx=-xr+.5f;tx<=xr-.5;tx++) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   109
    setpix(screen,x+tx,y+ty,c);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   110
      }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   111
    }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   112
    else {
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   113
      setpix(screen,x-xr+.5f,y+ty,c);
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   114
      setpix(screen,x+xr-.5f,y+ty,c);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   115
    }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   116
  }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   117
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   118
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   119
void drawKnob(SDL_Surface* screen,Knob k) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   120
  drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
7451
2ce2d2c71156 Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7191
diff changeset
   121
  drawCircle(screen,(k.p.x+k.r/2*SDL_cosf(k.ang))*screen->w,
2ce2d2c71156 Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7191
diff changeset
   122
                (k.p.y+k.r/2*SDL_sinf(k.ang))*screen->h,k.r/4*screen->w,0);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   123
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   124
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   125
void DrawScreen(SDL_Surface* screen, SDL_Window* window)
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   126
{
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   127
  int i;
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   128
#if 1
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   129
  SDL_FillRect(screen, NULL, 0);
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   130
#else
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   131
  int x, y;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   132
  for(y = 0;y < screen->h;y++)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   133
    for(x = 0;x < screen->w;x++)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   134
    setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   135
#endif
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   136
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   137
  /* draw Touch History */
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   138
  for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) {
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   139
    const SDL_Event *event = &events[i&(EVENT_BUF_SIZE-1)];
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   140
    float age = (float)(i - eventWrite) / EVENT_BUF_SIZE;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   141
    float x, y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   142
    unsigned int c, col;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   143
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   144
    if(event->type == SDL_FINGERMOTION ||
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   145
       event->type == SDL_FINGERDOWN ||
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   146
       event->type == SDL_FINGERUP) {
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6790
diff changeset
   147
      x = event->tfinger.x;
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6790
diff changeset
   148
      y = event->tfinger.y;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   149
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   150
      /* draw the touch: */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   151
      c = colors[event->tfinger.fingerId%7];
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   152
      col = ((unsigned int)(c*(.1+.85))) | (unsigned int)(0xFF*age)<<24;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   153
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   154
      if(event->type == SDL_FINGERMOTION)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   155
    drawCircle(screen,x*screen->w,y*screen->h,5,col);
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   156
      else if(event->type == SDL_FINGERDOWN)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   157
    drawCircle(screen,x*screen->w,y*screen->h,-10,col);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   158
    }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   159
  }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   160
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   161
  if(knob.p.x > 0)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   162
    drawKnob(screen,knob);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   163
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   164
  SDL_UpdateWindowSurface(window);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   165
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   166
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   167
/* Returns a new SDL_Window if window is NULL or window if not. */
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   168
SDL_Window* initWindow(SDL_Window *window, int width,int height)
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   169
{
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   170
  if (!window) {
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   171
    window = SDL_CreateWindow("Gesture Test",
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   172
                              SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
6790
475f0a544157 Fixed bug 1672 - Found: seg-fault with testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   173
                              width, height, SDL_WINDOW_RESIZABLE);
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   174
  }
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   175
  if (!window) {
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   176
    return NULL;
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   177
  }
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   178
  return window;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   179
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   180
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   181
int main(int argc, char* argv[])
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   182
{
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   183
  SDL_Window *window = NULL;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   184
  SDL_Surface *screen;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   185
  SDL_Event event;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   186
  SDL_bool quitting = SDL_FALSE;
7900
cc2289c332eb Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7678
diff changeset
   187
  SDL_RWops *stream;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   188
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   189
  /* Enable standard application logging */
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   190
  SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   191
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   192
  /* gesture variables */
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   193
  knob.r = .1f;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   194
  knob.ang = 0;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   195
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   196
  if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   197
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   198
  if (!(window = initWindow(window, WIDTH, HEIGHT)) ||
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   199
      !(screen = SDL_GetWindowSurface(window)))
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   200
    {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   201
      SDL_Quit();
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   202
      return 1;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   203
    }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   204
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   205
  while(!quitting) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   206
    while(SDL_PollEvent(&event))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   207
      {
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   208
    /* Record _all_ events */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   209
    events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   210
    eventWrite++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   211
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   212
    switch (event.type)
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   213
      {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   214
      case SDL_QUIT:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   215
        quitting = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   216
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   217
      case SDL_KEYDOWN:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   218
        switch (event.key.keysym.sym)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   219
          {
9235
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   220
              case SDLK_i:
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   221
              {
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   222
                  int i;
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   223
                  for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   224
                      SDL_TouchID id = SDL_GetTouchDevice(i);
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   225
                      SDL_Log("Fingers Down on device %"SDL_PRIs64": %d", id, SDL_GetNumTouchFingers(id));
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   226
                  }
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   227
                  break;
ba9988f0daec add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents: 8917
diff changeset
   228
              }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   229
          case SDLK_SPACE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   230
        SDL_RecordGesture(-1);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   231
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   232
          case SDLK_s:
7900
cc2289c332eb Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7678
diff changeset
   233
        stream = SDL_RWFromFile("gestureSave", "w");
cc2289c332eb Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7678
diff changeset
   234
        SDL_Log("Wrote %i templates", SDL_SaveAllDollarTemplates(stream));
cc2289c332eb Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7678
diff changeset
   235
        SDL_RWclose(stream);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   236
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   237
          case SDLK_l:
7900
cc2289c332eb Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7678
diff changeset
   238
        stream = SDL_RWFromFile("gestureSave", "r");
cc2289c332eb Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7678
diff changeset
   239
        SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream));
cc2289c332eb Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7678
diff changeset
   240
        SDL_RWclose(stream);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   241
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   242
          case SDLK_ESCAPE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   243
        quitting = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   244
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   245
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   246
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   247
      case SDL_WINDOWEVENT:
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   248
            if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   249
          if (!(window = initWindow(window, event.window.data1, event.window.data2)) ||
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   250
              !(screen = SDL_GetWindowSurface(window)))
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   251
          {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   252
        SDL_Quit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   253
        return 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   254
          }
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   255
            }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   256
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   257
      case SDL_FINGERMOTION:
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   258
#if VERBOSE
8917
23182cf59f1c Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8883
diff changeset
   259
        SDL_Log("Finger: %"SDL_PRIs64",x: %f, y: %f",event.tfinger.fingerId,
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   260
               event.tfinger.x,event.tfinger.y);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   261
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   262
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   263
      case SDL_FINGERDOWN:
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   264
#if VERBOSE
8917
23182cf59f1c Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8883
diff changeset
   265
        SDL_Log("Finger: %"SDL_PRIs64" down - x: %f, y: %f",
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   266
           event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   267
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   268
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   269
      case SDL_FINGERUP:
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   270
#if VERBOSE
8917
23182cf59f1c Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8883
diff changeset
   271
        SDL_Log("Finger: %"SDL_PRIs64" up - x: %f, y: %f",
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   272
               event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   273
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   274
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   275
      case SDL_MULTIGESTURE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   276
#if VERBOSE
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   277
        SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f",
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   278
           event.mgesture.x,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   279
           event.mgesture.y,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   280
           event.mgesture.dTheta,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   281
           event.mgesture.dDist);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   282
        SDL_Log("MG: numDownTouch = %i",event.mgesture.numFingers);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   283
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   284
        knob.p.x = event.mgesture.x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   285
        knob.p.y = event.mgesture.y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   286
        knob.ang += event.mgesture.dTheta;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   287
        knob.r += event.mgesture.dDist;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   288
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   289
      case SDL_DOLLARGESTURE:
8917
23182cf59f1c Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8883
diff changeset
   290
        SDL_Log("Gesture %"SDL_PRIs64" performed, error: %f",
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   291
           event.dgesture.gestureId,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   292
           event.dgesture.error);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   293
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   294
      case SDL_DOLLARRECORD:
8917
23182cf59f1c Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8883
diff changeset
   295
        SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   296
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   297
      }
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   298
      }
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   299
    DrawScreen(screen, window);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   300
  }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   301
  SDL_Quit();
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   302
  return 0;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   303
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   304