Commit dc0f95c4 authored by Andreas Schiffler's avatar Andreas Schiffler

Update VS2010 project to add new files; update new files so code builds on Win32/Win64

parent 9412167e
...@@ -110,7 +110,7 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" ...@@ -110,7 +110,7 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
<Culture>0x0409</Culture> <Culture>0x0409</Culture>
</ResourceCompile> </ResourceCompile>
<Link> <Link>
<AdditionalDependencies>msvcrt.lib;msimg32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>msvcrt.lib;msimg32.lib;version.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(IntDir)SDL.dll</OutputFile> <OutputFile>$(IntDir)SDL.dll</OutputFile>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
...@@ -274,6 +274,9 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h" ...@@ -274,6 +274,9 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\src\events\blank_cursor.h" /> <ClInclude Include="..\..\src\events\blank_cursor.h" />
<ClInclude Include="..\..\src\events\default_cursor.h" /> <ClInclude Include="..\..\src\events\default_cursor.h" />
<ClInclude Include="..\..\src\audio\windx5\directx.h" /> <ClInclude Include="..\..\src\audio\windx5\directx.h" />
<ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" />
<ClInclude Include="..\..\src\events\SDL_gesture_c.h" />
<ClInclude Include="..\..\src\events\SDL_touch_c.h" />
<ClInclude Include="..\..\src\libm\math.h" /> <ClInclude Include="..\..\src\libm\math.h" />
<ClInclude Include="..\..\src\libm\math_private.h" /> <ClInclude Include="..\..\src\libm\math_private.h" />
<ClInclude Include="..\..\src\video\mmx.h" /> <ClInclude Include="..\..\src\video\mmx.h" />
...@@ -326,6 +329,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h" ...@@ -326,6 +329,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\src\timer\SDL_timer_c.h" /> <ClInclude Include="..\..\src\timer\SDL_timer_c.h" />
<ClInclude Include="..\..\src\video\win32\SDL_vkeys.h" /> <ClInclude Include="..\..\src\video\win32\SDL_vkeys.h" />
<ClInclude Include="..\..\src\audio\SDL_wave.h" /> <ClInclude Include="..\..\src\audio\SDL_wave.h" />
<ClInclude Include="..\..\src\video\win32\SDL_win32clipboard.h" />
<ClInclude Include="..\..\src\video\win32\SDL_win32events.h" /> <ClInclude Include="..\..\src\video\win32\SDL_win32events.h" />
<ClInclude Include="..\..\src\video\win32\SDL_win32gamma.h" /> <ClInclude Include="..\..\src\video\win32\SDL_win32gamma.h" />
<ClInclude Include="..\..\src\video\win32\SDL_win32keyboard.h" /> <ClInclude Include="..\..\src\video\win32\SDL_win32keyboard.h" />
...@@ -340,6 +344,9 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h" ...@@ -340,6 +344,9 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\src\video\win32\wmmsg.h" /> <ClInclude Include="..\..\src\video\win32\wmmsg.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
<ClCompile Include="..\..\src\events\SDL_gesture.c" />
<ClCompile Include="..\..\src\events\SDL_touch.c" />
<ClCompile Include="..\..\src\libm\e_log.c" /> <ClCompile Include="..\..\src\libm\e_log.c" />
<ClCompile Include="..\..\src\libm\e_pow.c" /> <ClCompile Include="..\..\src\libm\e_pow.c" />
<ClCompile Include="..\..\src\libm\e_rem_pio2.c" /> <ClCompile Include="..\..\src\libm\e_rem_pio2.c" />
...@@ -431,6 +438,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h" ...@@ -431,6 +438,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClCompile Include="..\..\src\timer\SDL_timer.c" /> <ClCompile Include="..\..\src\timer\SDL_timer.c" />
<ClCompile Include="..\..\src\video\SDL_video.c" /> <ClCompile Include="..\..\src\video\SDL_video.c" />
<ClCompile Include="..\..\src\audio\SDL_wave.c" /> <ClCompile Include="..\..\src\audio\SDL_wave.c" />
<ClCompile Include="..\..\src\video\win32\SDL_win32clipboard.c" />
<ClCompile Include="..\..\src\video\win32\SDL_win32events.c" /> <ClCompile Include="..\..\src\video\win32\SDL_win32events.c" />
<ClCompile Include="..\..\src\video\win32\SDL_win32gamma.c" /> <ClCompile Include="..\..\src\video\win32\SDL_win32gamma.c" />
<ClCompile Include="..\..\src\video\win32\SDL_win32keyboard.c" /> <ClCompile Include="..\..\src\video\win32\SDL_win32keyboard.c" />
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "SDL_audiomem.h" #include "SDL_audiomem.h"
#include "SDL_sysaudio.h" #include "SDL_sysaudio.h"
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *_this
static SDL_AudioDriver current_audio; static SDL_AudioDriver current_audio;
static SDL_AudioDevice *open_devices[16]; static SDL_AudioDevice *open_devices[16];
...@@ -321,8 +321,9 @@ SDL_StreamDeinit(SDL_AudioStreamer * stream) ...@@ -321,8 +321,9 @@ SDL_StreamDeinit(SDL_AudioStreamer * stream)
} }
} }
#if defined(ANDROID)
#include <android/log.h> #include <android/log.h>
#endif
/* The general mixing thread function */ /* The general mixing thread function */
int SDLCALL int SDLCALL
...@@ -891,7 +892,7 @@ open_audio_device(const char *devname, int iscapture, ...@@ -891,7 +892,7 @@ open_audio_device(const char *devname, int iscapture,
device->opened = 1; device->opened = 1;
/* Allocate a fake audio memory buffer */ /* Allocate a fake audio memory buffer */
device->fake_stream = SDL_AllocAudioMem(device->spec.size); device->fake_stream = (Uint8 *)SDL_AllocAudioMem(device->spec.size);
if (device->fake_stream == NULL) { if (device->fake_stream == NULL) {
close_audio_device(device); close_audio_device(device);
SDL_OutOfMemory(); SDL_OutOfMemory();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
Sam Lantinga Sam Lantinga
slouken@libsdl.org slouken@libsdl.org
*/ */
#include "SDL_config.h" #include "SDL_config.h"
/* General mouse handling code for SDL */ /* General mouse handling code for SDL */
...@@ -26,6 +27,11 @@ ...@@ -26,6 +27,11 @@
#include "SDL_events_c.h" #include "SDL_events_c.h"
#include "SDL_gesture_c.h" #include "SDL_gesture_c.h"
#include <memory.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
//TODO: Replace with malloc //TODO: Replace with malloc
#define MAXPATHSIZE 1024 #define MAXPATHSIZE 1024
...@@ -100,8 +106,8 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points) { ...@@ -100,8 +106,8 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points) {
unsigned long hash = 5381; unsigned long hash = 5381;
int i; int i;
for(i = 0;i < DOLLARNPOINTS; i++) { for(i = 0;i < DOLLARNPOINTS; i++) {
hash = ((hash<<5) + hash) + points[i].x; hash = ((hash<<5) + hash) + (unsigned long)points[i].x;
hash = ((hash<<5) + hash) + points[i].y; hash = ((hash<<5) + hash) + (unsigned long)points[i].y;
} }
return hash; return hash;
} }
...@@ -110,7 +116,6 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points) { ...@@ -110,7 +116,6 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points) {
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src) { static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src) {
if(src == NULL) return 0; if(src == NULL) return 0;
int i;
//No Longer storing the Hash, rehash on load //No Longer storing the Hash, rehash on load
//if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0; //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;
...@@ -151,14 +156,16 @@ int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) { ...@@ -151,14 +156,16 @@ int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) {
//path is an already sampled set of points //path is an already sampled set of points
//Returns the index of the gesture on success, or -1 //Returns the index of the gesture on success, or -1
static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) { static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) {
SDL_DollarTemplate* dollarTemplate;
SDL_DollarTemplate *templ;
int i = 0;
if(inTouch == NULL) { if(inTouch == NULL) {
if(SDL_numGestureTouches == 0) return -1; if(SDL_numGestureTouches == 0) return -1;
int i = 0;
for(i = 0;i < SDL_numGestureTouches; i++) { for(i = 0;i < SDL_numGestureTouches; i++) {
inTouch = &SDL_gestureTouch[i]; inTouch = &SDL_gestureTouch[i];
SDL_DollarTemplate* dollarTemplate = dollarTemplate =
SDL_realloc(inTouch->dollarTemplate, (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
(inTouch->numDollarTemplates + 1) * (inTouch->numDollarTemplates + 1) *
sizeof(SDL_DollarTemplate)); sizeof(SDL_DollarTemplate));
if(!dollarTemplate) { if(!dollarTemplate) {
...@@ -168,7 +175,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) ...@@ -168,7 +175,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path)
inTouch->dollarTemplate = dollarTemplate; inTouch->dollarTemplate = dollarTemplate;
SDL_DollarTemplate *templ = templ =
&inTouch->dollarTemplate[inTouch->numDollarTemplates]; &inTouch->dollarTemplate[inTouch->numDollarTemplates];
memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint));
templ->hash = SDL_HashDollar(templ->path); templ->hash = SDL_HashDollar(templ->path);
...@@ -177,7 +184,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) ...@@ -177,7 +184,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path)
return inTouch->numDollarTemplates - 1; return inTouch->numDollarTemplates - 1;
} else { } else {
SDL_DollarTemplate* dollarTemplate = SDL_DollarTemplate* dollarTemplate =
SDL_realloc(inTouch->dollarTemplate, ( SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
(inTouch->numDollarTemplates + 1) * (inTouch->numDollarTemplates + 1) *
sizeof(SDL_DollarTemplate)); sizeof(SDL_DollarTemplate));
if(!dollarTemplate) { if(!dollarTemplate) {
...@@ -187,7 +194,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) ...@@ -187,7 +194,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path)
inTouch->dollarTemplate = dollarTemplate; inTouch->dollarTemplate = dollarTemplate;
SDL_DollarTemplate *templ = templ =
&inTouch->dollarTemplate[inTouch->numDollarTemplates]; &inTouch->dollarTemplate[inTouch->numDollarTemplates];
memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint));
templ->hash = SDL_HashDollar(templ->path); templ->hash = SDL_HashDollar(templ->path);
...@@ -198,9 +205,9 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) ...@@ -198,9 +205,9 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path)
} }
int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) { int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) {
if(src == NULL) return 0;
int i,loaded = 0; int i,loaded = 0;
SDL_GestureTouch *touch = NULL; SDL_GestureTouch *touch = NULL;
if(src == NULL) return 0;
if(touchId >= 0) { if(touchId >= 0) {
for(i = 0;i < SDL_numGestureTouches; i++) for(i = 0;i < SDL_numGestureTouches; i++)
if(SDL_gestureTouch[i].id == touchId) if(SDL_gestureTouch[i].id == touchId)
...@@ -240,10 +247,10 @@ float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang) { ...@@ -240,10 +247,10 @@ float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang) {
SDL_FloatPoint p; SDL_FloatPoint p;
int i; int i;
for(i = 0; i < DOLLARNPOINTS; i++) { for(i = 0; i < DOLLARNPOINTS; i++) {
p.x = points[i].x * cos(ang) - points[i].y * sin(ang); p.x = (float)(points[i].x * cos(ang) - points[i].y * sin(ang));
p.y = points[i].x * sin(ang) + points[i].y * cos(ang); p.y = (float)(points[i].x * sin(ang) + points[i].y * cos(ang));
dist += sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+ dist += (float)(sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
(p.y-templ[i].y)*(p.y-templ[i].y)); (p.y-templ[i].y)*(p.y-templ[i].y)));
} }
return dist/DOLLARNPOINTS; return dist/DOLLARNPOINTS;
...@@ -253,26 +260,26 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) { ...@@ -253,26 +260,26 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) {
//------------BEGIN DOLLAR BLACKBOX----------------// //------------BEGIN DOLLAR BLACKBOX----------------//
//-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-// //-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-//
//-"http://depts.washington.edu/aimgroup/proj/dollar/"-// //-"http://depts.washington.edu/aimgroup/proj/dollar/"-//
float ta = -M_PI/4; double ta = -M_PI/4;
float tb = M_PI/4; double tb = M_PI/4;
float dt = M_PI/90; double dt = M_PI/90;
float x1 = PHI*ta + (1-PHI)*tb; float x1 = (float)(PHI*ta + (1-PHI)*tb);
float f1 = dollarDifference(points,templ,x1); float f1 = dollarDifference(points,templ,x1);
float x2 = (1-PHI)*ta + PHI*tb; float x2 = (float)((1-PHI)*ta + PHI*tb);
float f2 = dollarDifference(points,templ,x2); float f2 = dollarDifference(points,templ,x2);
while(abs(ta-tb) > dt) { while(fabs(ta-tb) > dt) {
if(f1 < f2) { if(f1 < f2) {
tb = x2; tb = x2;
x2 = x1; x2 = x1;
f2 = f1; f2 = f1;
x1 = PHI*ta + (1-PHI)*tb; x1 = (float)(PHI*ta + (1-PHI)*tb);
f1 = dollarDifference(points,templ,x1); f1 = dollarDifference(points,templ,x1);
} }
else { else {
ta = x1; ta = x1;
x1 = x2; x1 = x2;
f1 = f2; f1 = f2;
x2 = (1-PHI)*ta + PHI*tb; x2 = (float)((1-PHI)*ta + PHI*tb);
f2 = dollarDifference(points,templ,x2); f2 = dollarDifference(points,templ,x2);
} }
} }
...@@ -288,6 +295,14 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) { ...@@ -288,6 +295,14 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) {
//DollarPath contains raw points, plus (possibly) the calculated length //DollarPath contains raw points, plus (possibly) the calculated length
int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
int i; int i;
float interval;
float dist;
int numPoints = 0;
SDL_FloatPoint centroid;
float xmin,xmax,ymin,ymax;
float ang;
float w,h;
//Calculate length if it hasn't already been done //Calculate length if it hasn't already been done
if(path.length <= 0) { if(path.length <= 0) {
for(i=1;i<path.numPoints;i++) { for(i=1;i<path.numPoints;i++) {
...@@ -295,22 +310,20 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { ...@@ -295,22 +310,20 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
path.p[i-1].x; path.p[i-1].x;
float dy = path.p[i ].y - float dy = path.p[i ].y -
path.p[i-1].y; path.p[i-1].y;
path.length += sqrt(dx*dx+dy*dy); path.length += (float)(sqrt(dx*dx+dy*dy));
} }
} }
//Resample //Resample
float interval = path.length/(DOLLARNPOINTS - 1); interval = path.length/(DOLLARNPOINTS - 1);
float dist = interval; dist = interval;
int numPoints = 0;
SDL_FloatPoint centroid;
centroid.x = 0;centroid.y = 0; centroid.x = 0;centroid.y = 0;
//printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y); //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y);
for(i = 1;i < path.numPoints;i++) { for(i = 1;i < path.numPoints;i++) {
float d = sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+ float d = (float)(sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+
(path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y)); (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y)));
//printf("d = %f dist = %f/%f\n",d,dist,interval); //printf("d = %f dist = %f/%f\n",d,dist,interval);
while(dist + d > interval) { while(dist + d > interval) {
points[numPoints].x = path.p[i-1].x + points[numPoints].x = path.p[i-1].x +
...@@ -338,22 +351,21 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { ...@@ -338,22 +351,21 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
//printf("Centroid (%f,%f)",centroid.x,centroid.y); //printf("Centroid (%f,%f)",centroid.x,centroid.y);
//Rotate Points so point 0 is left of centroid and solve for the bounding box //Rotate Points so point 0 is left of centroid and solve for the bounding box
float xmin,xmax,ymin,ymax;
xmin = centroid.x; xmin = centroid.x;
xmax = centroid.x; xmax = centroid.x;
ymin = centroid.y; ymin = centroid.y;
ymax = centroid.y; ymax = centroid.y;
float ang = atan2(centroid.y - points[0].y, ang = (float)(atan2(centroid.y - points[0].y,
centroid.x - points[0].x); centroid.x - points[0].x));
for(i = 0;i<numPoints;i++) { for(i = 0;i<numPoints;i++) {
float px = points[i].x; float px = points[i].x;
float py = points[i].y; float py = points[i].y;
points[i].x = (px - centroid.x)*cos(ang) - points[i].x = (float)((px - centroid.x)*cos(ang) -
(py - centroid.y)*sin(ang) + centroid.x; (py - centroid.y)*sin(ang) + centroid.x);
points[i].y = (px - centroid.x)*sin(ang) + points[i].y = (float)((px - centroid.x)*sin(ang) +
(py - centroid.y)*cos(ang) + centroid.y; (py - centroid.y)*cos(ang) + centroid.y);
if(points[i].x < xmin) xmin = points[i].x; if(points[i].x < xmin) xmin = points[i].x;
...@@ -363,8 +375,8 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { ...@@ -363,8 +375,8 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
} }
//Scale points to DOLLARSIZE, and translate to the origin //Scale points to DOLLARSIZE, and translate to the origin
float w = xmax-xmin; w = xmax-xmin;
float h = ymax-ymin; h = ymax-ymin;
for(i=0;i<numPoints;i++) { for(i=0;i<numPoints;i++) {
points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w; points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
...@@ -380,17 +392,17 @@ float dollarRecognize(SDL_DollarPath path,int *bestTempl,SDL_GestureTouch* touch ...@@ -380,17 +392,17 @@ float dollarRecognize(SDL_DollarPath path,int *bestTempl,SDL_GestureTouch* touch
//SDL_PrintPath(points); //SDL_PrintPath(points);
int i; int i;
int bestDiff = 10000; float bestDiff = 10000;
*bestTempl = -1; *bestTempl = -1;
for(i = 0;i < touch->numDollarTemplates;i++) { for(i = 0;i < touch->numDollarTemplates;i++) {
int diff = bestDollarDifference(points,touch->dollarTemplate[i].path); float diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;} if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
} }
return bestDiff; return bestDiff;
} }
int SDL_GestureAddTouch(SDL_Touch* touch) { int SDL_GestureAddTouch(SDL_Touch* touch) {
SDL_GestureTouch *gestureTouch = SDL_realloc(SDL_gestureTouch, SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
(SDL_numGestureTouches + 1) * (SDL_numGestureTouches + 1) *
sizeof(SDL_GestureTouch)); sizeof(SDL_GestureTouch));
...@@ -479,6 +491,18 @@ int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId) { ...@@ -479,6 +491,18 @@ int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId) {
void SDL_GestureProcessEvent(SDL_Event* event) void SDL_GestureProcessEvent(SDL_Event* event)
{ {
float x,y;
SDL_FloatPoint path[DOLLARNPOINTS];
int index;
int i;
float pathDx, pathDy;
SDL_FloatPoint lastP;
SDL_FloatPoint lastCentroid;
float lDist;
float Dist;
float dtheta;
float dDist;
if(event->type == SDL_FINGERMOTION || if(event->type == SDL_FINGERMOTION ||
event->type == SDL_FINGERDOWN || event->type == SDL_FINGERDOWN ||
event->type == SDL_FINGERUP) { event->type == SDL_FINGERUP) {
...@@ -492,8 +516,8 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -492,8 +516,8 @@ void SDL_GestureProcessEvent(SDL_Event* event)
// (int)inTouch->res.x,(int)inTouch->res.y); // (int)inTouch->res.x,(int)inTouch->res.y);
float x = ((float)event->tfinger.x)/(float)inTouch->res.x; x = ((float)event->tfinger.x)/(float)inTouch->res.x;
float y = ((float)event->tfinger.y)/(float)inTouch->res.y; y = ((float)event->tfinger.y)/(float)inTouch->res.y;
//Finger Up //Finger Up
...@@ -502,14 +526,11 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -502,14 +526,11 @@ void SDL_GestureProcessEvent(SDL_Event* event)
#ifdef ENABLE_DOLLAR #ifdef ENABLE_DOLLAR
if(inTouch->recording) { if(inTouch->recording) {
inTouch->recording = SDL_FALSE; inTouch->recording = SDL_FALSE;
SDL_FloatPoint path[DOLLARNPOINTS];
dollarNormalize(inTouch->dollarPath,path); dollarNormalize(inTouch->dollarPath,path);
//SDL_PrintPath(path); //SDL_PrintPath(path);
int index;
if(recordAll) { if(recordAll) {
index = SDL_AddDollarGesture(NULL,path); index = SDL_AddDollarGesture(NULL,path);
int i;
for(i = 0;i < SDL_numGestureTouches; i++) for(i = 0;i < SDL_numGestureTouches; i++)
SDL_gestureTouch[i].recording = SDL_FALSE; SDL_gestureTouch[i].recording = SDL_FALSE;
} }
...@@ -554,18 +575,16 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -554,18 +575,16 @@ void SDL_GestureProcessEvent(SDL_Event* event)
if(path->numPoints < MAXPATHSIZE) { if(path->numPoints < MAXPATHSIZE) {
path->p[path->numPoints].x = inTouch->centroid.x; path->p[path->numPoints].x = inTouch->centroid.x;
path->p[path->numPoints].y = inTouch->centroid.y; path->p[path->numPoints].y = inTouch->centroid.y;
float pathDx = pathDx =
(path->p[path->numPoints].x-path->p[path->numPoints-1].x); (path->p[path->numPoints].x-path->p[path->numPoints-1].x);
float pathDy = pathDy =
(path->p[path->numPoints].y-path->p[path->numPoints-1].y); (path->p[path->numPoints].y-path->p[path->numPoints-1].y);
path->length += sqrt(pathDx*pathDx + pathDy*pathDy); path->length += (float)sqrt(pathDx*pathDx + pathDy*pathDy);
path->numPoints++; path->numPoints++;
} }
#endif #endif
SDL_FloatPoint lastP;
lastP.x = x - dx; lastP.x = x - dx;
lastP.y = y - dy; lastP.y = y - dy;
SDL_FloatPoint lastCentroid;
lastCentroid = inTouch->centroid; lastCentroid = inTouch->centroid;
inTouch->centroid.x += dx/inTouch->numDownFingers; inTouch->centroid.x += dx/inTouch->numDownFingers;
...@@ -577,12 +596,12 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -577,12 +596,12 @@ void SDL_GestureProcessEvent(SDL_Event* event)
//lv = inTouch->gestureLast[j].cv; //lv = inTouch->gestureLast[j].cv;
lv.x = lastP.x - lastCentroid.x; lv.x = lastP.x - lastCentroid.x;
lv.y = lastP.y - lastCentroid.y; lv.y = lastP.y - lastCentroid.y;
float lDist = sqrt(lv.x*lv.x + lv.y*lv.y); lDist = (float)sqrt(lv.x*lv.x + lv.y*lv.y);
//printf("lDist = %f\n",lDist); //printf("lDist = %f\n",lDist);
v.x = x - inTouch->centroid.x; v.x = x - inTouch->centroid.x;
v.y = y - inTouch->centroid.y; v.y = y - inTouch->centroid.y;
//inTouch->gestureLast[j].cv = v; //inTouch->gestureLast[j].cv = v;
float Dist = sqrt(v.x*v.x+v.y*v.y); Dist = (float)sqrt(v.x*v.x+v.y*v.y);
// cos(dTheta) = (v . lv)/(|v| * |lv|) // cos(dTheta) = (v . lv)/(|v| * |lv|)
//Normalize Vectors to simplify angle calculation //Normalize Vectors to simplify angle calculation
...@@ -590,9 +609,9 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -590,9 +609,9 @@ void SDL_GestureProcessEvent(SDL_Event* event)
lv.y/=lDist; lv.y/=lDist;
v.x/=Dist; v.x/=Dist;
v.y/=Dist; v.y/=Dist;
float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); dtheta = (float)atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
float dDist = (Dist - lDist); dDist = (Dist - lDist);
if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values
//inTouch->gestureLast[j].dDist = dDist; //inTouch->gestureLast[j].dDist = dDist;
......
...@@ -313,6 +313,11 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, ...@@ -313,6 +313,11 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
float xin, float yin, float pressurein) float xin, float yin, float pressurein)
{ {
int posted; int posted;
Uint16 x;
Uint16 y;
Uint16 pressure;
SDL_Finger *finger;
SDL_Touch* touch = SDL_GetTouch(id); SDL_Touch* touch = SDL_GetTouch(id);
if(!touch) { if(!touch) {
...@@ -321,11 +326,11 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, ...@@ -321,11 +326,11 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
//scale to Integer coordinates //scale to Integer coordinates
Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres); x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres); y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres); pressure = (Uint16)((yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
SDL_Finger *finger = SDL_GetFinger(touch,fingerid); finger = SDL_GetFinger(touch,fingerid);
if(down) { if(down) {
if(finger == NULL) { if(finger == NULL) {
SDL_Finger nf; SDL_Finger nf;
...@@ -393,15 +398,18 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, ...@@ -393,15 +398,18 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative,
int posted; int posted;
Sint16 xrel, yrel; Sint16 xrel, yrel;
float x_max = 0, y_max = 0; float x_max = 0, y_max = 0;
Uint16 x;
Uint16 y;
Uint16 pressure;
if (!touch) { if (!touch) {
return SDL_TouchNotFoundError(id); return SDL_TouchNotFoundError(id);
} }
//scale to Integer coordinates //scale to Integer coordinates
Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres); x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres); y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres); pressure = (Uint16)((yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
if(touch->flush_motion) { if(touch->flush_motion) {
return 0; return 0;
} }
...@@ -544,9 +552,9 @@ SDL_GetTouchName(SDL_TouchID id) ...@@ -544,9 +552,9 @@ SDL_GetTouchName(SDL_TouchID id)
} }
int SDL_TouchNotFoundError(SDL_TouchID id) { int SDL_TouchNotFoundError(SDL_TouchID id) {
int i;
printf("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id); printf("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id);
printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch);
int i;
for(i=0;i < SDL_num_touch;i++) { for(i=0;i < SDL_num_touch;i++) {
printf("ERROR: %li\n",SDL_touchPads[i]->id); printf("ERROR: %li\n",SDL_touchPads[i]->id);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment