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