test/testgesture.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 24 Dec 2014 22:22:35 -0500
changeset 9289 5f857c00d25d
parent 9287 644bf5f51d5c
child 9290 fe975b2313fa
permissions -rw-r--r--
Maybe actually patched to compile this time?
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
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    18
#include "SDL.h"
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    19
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
    20
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
    21
#include <emscripten/emscripten.h>
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
    22
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
    23
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    24
#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
    25
#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
    26
#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
    27
#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
    28
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    29
/* 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
    30
#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
    31
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    32
5458
a96fcc853bef Use SDL_Log() so the messages show up on iPhone and Android
Sam Lantinga <slouken@libsdl.org>
parents: 5457
diff changeset
    33
#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
    34
5457
e4ee8761f5cd Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents: 5456
diff changeset
    35
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
    36
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
    37
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    38
5457
e4ee8761f5cd Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents: 5456
diff changeset
    39
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
    40
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
    41
SDL_Surface *screen;
9289
5f857c00d25d Maybe actually patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9287
diff changeset
    42
SDL_Window *window;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
    43
SDL_bool quitting = SDL_FALSE;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
    44
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    45
typedef struct {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    46
  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
    47
} Point;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    48
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    49
typedef struct {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    50
  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
    51
  Point p;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    52
} Knob;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    53
5457
e4ee8761f5cd Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents: 5456
diff changeset
    54
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
    55
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    56
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
    57
{
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    58
  Uint32 *pixmem32;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    59
  Uint32 colour;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    60
  Uint8 r,g,b;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    61
  int x = (int)_x;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    62
  int y = (int)_y;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    63
  float a;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    64
6790
475f0a544157 Fixed bug 1672 - Found: seg-fault with testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    65
  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
    66
  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
    67
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    68
  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
    69
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    70
  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
    71
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    72
  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
    73
  /* r = 0;g = 0; b = 0; */
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    74
  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
    75
  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
    76
  a /= 0xFF;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    77
  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
    78
  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
    79
  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
    80
  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
    81
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    82
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    83
  *pixmem32 = colour;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    84
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    85
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    86
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
    87
  float t;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    88
  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
    89
    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
    90
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    91
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    92
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
    93
{
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    94
  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
    95
  float xr;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
    96
  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
    97
    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
    98
    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
    99
      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
   100
    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
   101
      }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   102
    }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   103
    else {
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   104
      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
   105
      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
   106
    }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   107
  }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   108
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   109
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   110
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
   111
  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
   112
  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
   113
                (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
   114
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   115
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   116
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
   117
{
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   118
  int i;
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   119
#if 1
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   120
  SDL_FillRect(screen, NULL, 0);
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   121
#else
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   122
  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
   123
  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
   124
    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
   125
    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
   126
#endif
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   127
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   128
  /* draw Touch History */
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   129
  for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) {
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   130
    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
   131
    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
   132
    float x, y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   133
    unsigned int c, col;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
   134
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   135
    if(event->type == SDL_FINGERMOTION ||
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   136
       event->type == SDL_FINGERDOWN ||
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   137
       event->type == SDL_FINGERUP) {
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6790
diff changeset
   138
      x = event->tfinger.x;
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6790
diff changeset
   139
      y = event->tfinger.y;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   140
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   141
      /* draw the touch: */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   142
      c = colors[event->tfinger.fingerId%7];
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   143
      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
   144
5460
43582fccdc0d Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents: 5458
diff changeset
   145
      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
   146
    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
   147
      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
   148
    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
   149
    }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   150
  }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   151
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   152
  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
   153
    drawKnob(screen,knob);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   154
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   155
  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
   156
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   157
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   158
/* 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
   159
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
   160
{
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   161
  if (!window) {
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   162
    window = SDL_CreateWindow("Gesture Test",
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   163
                              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
   164
                              width, height, SDL_WINDOW_RESIZABLE);
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   165
  }
9273
9f1c18388f2c Removed global variable from test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9235
diff changeset
   166
  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
   167
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   168
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   169
void loop()
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   170
{
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   171
    SDL_Event event;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   172
    SDL_RWops *stream;
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
   173
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   174
    while(SDL_PollEvent(&event))
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   175
    {
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   176
    /* Record _all_ events */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   177
    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
   178
    eventWrite++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   179
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   180
    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
   181
      {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   182
      case SDL_QUIT:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   183
        quitting = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   184
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   185
      case SDL_KEYDOWN:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   186
        switch (event.key.keysym.sym)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   187
          {
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
   188
              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
   189
              {
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
   190
                  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
   191
                  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
   192
                      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
   193
                      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
   194
                  }
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
   195
                  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
   196
              }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   197
          case SDLK_SPACE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   198
        SDL_RecordGesture(-1);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   199
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   200
          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
   201
        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
   202
        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
   203
        SDL_RWclose(stream);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   204
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   205
          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
   206
        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
   207
        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
   208
        SDL_RWclose(stream);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   209
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   210
          case SDLK_ESCAPE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   211
        quitting = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   212
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   213
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   214
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   215
      case SDL_WINDOWEVENT:
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   216
            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
   217
          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
   218
              !(screen = SDL_GetWindowSurface(window)))
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   219
          {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   220
        SDL_Quit();
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   221
        exit(1);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   222
          }
5456
63258b963fc1 Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   223
            }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   224
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   225
      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
   226
#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
   227
        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
   228
               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
   229
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   230
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   231
      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
   232
#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
   233
        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
   234
           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
   235
#endif
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 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
   238
#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
   239
        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
   240
               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
   241
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   242
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   243
      case SDL_MULTIGESTURE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   244
#if VERBOSE
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   245
        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
   246
           event.mgesture.x,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   247
           event.mgesture.y,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   248
           event.mgesture.dTheta,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   249
           event.mgesture.dDist);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   250
        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
   251
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   252
        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
   253
        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
   254
        knob.ang += event.mgesture.dTheta;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   255
        knob.r += event.mgesture.dDist;
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_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
   258
        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
   259
           event.dgesture.gestureId,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   260
           event.dgesture.error);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   261
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   262
      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
   263
        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
   264
        break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   265
      }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   266
    }
9287
644bf5f51d5c Really patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9286
diff changeset
   267
    DrawScreen(screen, window);
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   268
}
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   269
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   270
int main(int argc, char* argv[])
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   271
{
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   272
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   273
  /* Enable standard application logging */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   274
  SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   275
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   276
  /* gesture variables */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   277
  knob.r = .1f;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   278
  knob.ang = 0;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   279
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   280
  if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   281
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   282
  if (!(screen = initScreen(WIDTH,HEIGHT)))
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   283
  {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   284
      SDL_Quit();
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   285
      return 1;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   286
  }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   287
9289
5f857c00d25d Maybe actually patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9287
diff changeset
   288
  if (!(window = initWindow(NULL,WIDTH,HEIGHT)))
5f857c00d25d Maybe actually patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9287
diff changeset
   289
  {
5f857c00d25d Maybe actually patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9287
diff changeset
   290
      SDL_Quit();
5f857c00d25d Maybe actually patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9287
diff changeset
   291
      return 1;
5f857c00d25d Maybe actually patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9287
diff changeset
   292
  }
5f857c00d25d Maybe actually patched to compile this time?
Ryan C. Gordon <icculus@icculus.org>
parents: 9287
diff changeset
   293
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   294
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   295
    emscripten_set_main_loop(loop, 0, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   296
#else
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   297
    while(!quitting) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   298
        loop();
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   299
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   300
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9275
diff changeset
   301
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   302
  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
   303
  return 0;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   304
}
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   305