Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
99ed0692
Commit
99ed0692
authored
Jul 11, 2010
by
Jim Grandpre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some files I had previosuly missed
parent
746dc794
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
316 additions
and
319 deletions
+316
-319
Makefile.in
Makefile.in
+1
-1
SDL_events.h
include/SDL_events.h
+5
-1
SDL_gesture.h
include/SDL_gesture.h
+90
-0
SDL_touch.h
include/SDL_touch.h
+1
-1
SDL_gesture.c
src/events/SDL_gesture.c
+183
-17
SDL_gesture_c.h
src/events/SDL_gesture_c.h
+1
-0
gestureSDLTest.c
touchTest/gestureSDLTest.c
+35
-299
touchPong
touchTest/touchPong
+0
-0
touchSimp
touchTest/touchSimp
+0
-0
No files found.
Makefile.in
View file @
99ed0692
...
...
@@ -44,7 +44,7 @@ EMBEDSPU = @EMBEDSPU@
DIST
=
acinclude autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS include INSTALL Makefile.minimal Makefile.in README
*
sdl-config.in sdl.m4 sdl.pc.in SDL.spec SDL.spec.in src
test
TODO VisualC.html VisualC VisualCE Watcom-Win32.zip WhatsNew Xcode Xcode-iPhoneOS
HDRS
=
SDL.h SDL_assert.h SDL_atomic.h SDL_audio.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_haptic.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_opengles.h SDL_pixels.h SDL_platform.h SDL_power.h SDL_quit.h SDL_rect.h SDL_revision.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h SDL_touch.h
HDRS
=
SDL.h SDL_assert.h SDL_atomic.h SDL_audio.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_haptic.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_opengles.h SDL_pixels.h SDL_platform.h SDL_power.h SDL_quit.h SDL_rect.h SDL_revision.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h SDL_touch.h
SDL_gesture.h
LT_AGE
=
@LT_AGE@
LT_CURRENT
=
@LT_CURRENT@
...
...
include/SDL_events.h
View file @
99ed0692
...
...
@@ -36,6 +36,8 @@
#include "SDL_mouse.h"
#include "SDL_joystick.h"
#include "SDL_quit.h"
#include "SDL_gesture.h"
#include "SDL_touch.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
...
...
@@ -95,6 +97,7 @@ typedef enum
/*Gesture events*/
SDL_DOLLARGESTURE
=
0x800
,
SDL_DOLLARRECORD
,
SDL_MULTIGESTURE
,
/* Obsolete events */
...
...
@@ -359,9 +362,10 @@ typedef struct SDL_DollarGestureEvent
Uint32
type
;
/**< ::SDL_DOLLARGESTURE */
Uint32
windowID
;
/**< The window with mouse focus, if any */
Uint8
touchId
;
/**< The touch device index */
Uint8
gestureId
;
Uint8
padding1
;
Uint8
padding2
;
Uint8
padding3
;
unsigned
long
gestureId
;
float
error
;
/*
//TODO: Enable to give location?
...
...
include/SDL_gesture.h
0 → 100644
View file @
99ed0692
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/**
* \file SDL_gesture.h
*
* Include file for SDL gesture event handling.
*/
#ifndef _SDL_gesture_h
#define _SDL_gesture_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern
"C"
{
/* *INDENT-ON* */
#endif
/* Function prototypes */
/**
* \brief Begin Recording a gesture on the specified touch, or all touches (-1)
*
*
*/
extern
DECLSPEC
int
SDLCALL
SDL_RecordGesture
(
int
touchId
);
/**
* \brief Save all currently loaded Dollar Gesture templates
*
*
*/
extern
DECLSPEC
int
SDLCALL
SDL_SaveAllDollarTemplates
(
FILE
*
fp
);
/**
* \brief Save a currently loaded Dollar Gesture template
*
*
*/
extern
DECLSPEC
int
SDLCALL
SDL_SaveDollarTemplate
(
unsigned
long
gestureId
,
FILE
*
fp
);
/**
* \brief Load Dollar Gesture templates from a file
*
*
*/
extern
DECLSPEC
int
SDLCALL
SDL_LoadDollarTemplates
(
int
touchId
,
FILE
*
fp
);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif
/* _SDL_gesture_h */
/* vi: set ts=4 sw=4 expandtab: */
include/SDL_touch.h
View file @
99ed0692
...
...
@@ -23,7 +23,7 @@
/**
* \file SDL_touch.h
*
* Include file for SDL
mouse
event handling.
* Include file for SDL
touch
event handling.
*/
#ifndef _SDL_touch_h
...
...
src/events/SDL_gesture.c
View file @
99ed0692
...
...
@@ -13,8 +13,7 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
License along with this library; if not, write to the Free Software Founation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
...
...
@@ -66,6 +65,10 @@ typedef struct {
DollarPath
dollarPath
;
}
TouchPoint
;
typedef
struct
{
Point
path
[
DOLLARNPOINTS
];
unsigned
long
hash
;
}
DollarTemplate
;
typedef
struct
{
int
id
;
...
...
@@ -75,11 +78,140 @@ typedef struct {
int
numDownFingers
;
int
numDollarTemplates
;
Point
dollarTemplate
[
MAXTEMPLATES
][
DOLLARNPOINTS
];
DollarTemplate
dollarTemplate
[
MAXTEMPLATES
];
SDL_bool
recording
;
}
GestureTouch
;
GestureTouch
gestureTouch
[
MAXTOUCHES
];
int
numGestureTouches
=
0
;
SDL_bool
recordAll
;
int
SDL_RecordGesture
(
int
touchId
)
{
int
i
;
if
(
touchId
<
0
)
recordAll
=
SDL_TRUE
;
for
(
i
=
0
;
i
<
numGestureTouches
;
i
++
)
{
if
((
touchId
<
0
)
||
(
gestureTouch
[
i
].
id
==
touchId
))
{
gestureTouch
[
i
].
recording
=
SDL_TRUE
;
if
(
touchId
>=
0
)
return
1
;
}
}
return
(
touchId
<
0
);
}
unsigned
long
SDL_HashDollar
(
Point
*
points
)
{
unsigned
long
hash
=
5381
;
int
i
;
for
(
i
=
0
;
i
<
DOLLARNPOINTS
;
i
++
)
{
hash
=
((
hash
<<
5
)
+
hash
)
+
points
[
i
].
x
;
hash
=
((
hash
<<
5
)
+
hash
)
+
points
[
i
].
y
;
}
return
hash
;
}
int
SaveTemplate
(
DollarTemplate
*
templ
,
FILE
*
fp
)
{
int
i
;
fprintf
(
fp
,
"%lu "
,
templ
->
hash
);
for
(
i
=
0
;
i
<
DOLLARNPOINTS
;
i
++
)
{
fprintf
(
fp
,
"%i %i "
,(
int
)
templ
->
path
[
i
].
x
,(
int
)
templ
->
path
[
i
].
y
);
}
fprintf
(
fp
,
"
\n
"
);
}
int
SDL_SaveAllDollarTemplates
(
FILE
*
fp
)
{
int
i
,
j
,
rtrn
=
0
;
for
(
i
=
0
;
i
<
numGestureTouches
;
i
++
)
{
GestureTouch
*
touch
=
&
gestureTouch
[
i
];
for
(
j
=
0
;
j
<
touch
->
numDollarTemplates
;
j
++
)
{
rtrn
+=
SaveTemplate
(
&
touch
->
dollarTemplate
[
i
],
fp
);
}
}
return
rtrn
;
}
int
SDL_SaveDollarTemplate
(
unsigned
long
gestureId
,
FILE
*
fp
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
numGestureTouches
;
i
++
)
{
GestureTouch
*
touch
=
&
gestureTouch
[
i
];
for
(
j
=
0
;
j
<
touch
->
numDollarTemplates
;
j
++
)
{
if
(
touch
->
dollarTemplate
[
i
].
hash
==
gestureId
)
{
return
SaveTemplate
(
&
touch
->
dollarTemplate
[
i
],
fp
);
}
}
}
}
int
SDL_LoadDollarTemplates
(
int
touchId
,
FILE
*
fp
)
{
int
i
,
loaded
=
0
;
GestureTouch
*
touch
=
NULL
;
if
(
touchId
>=
0
)
{
for
(
i
=
0
;
i
<
numGestureTouches
;
i
++
)
if
(
gestureTouch
[
i
].
id
==
touchId
)
touch
=
&
gestureTouch
[
i
];
if
(
touch
==
NULL
)
return
-
1
;
}
while
(
!
feof
(
fp
))
{
DollarTemplate
templ
;
fscanf
(
fp
,
"%lu "
,
&
templ
.
hash
);
for
(
i
=
0
;
i
<
DOLLARNPOINTS
;
i
++
)
{
int
x
,
y
;
if
(
fscanf
(
fp
,
"%i %i "
,
&
x
,
&
y
)
!=
2
)
break
;
templ
.
path
[
i
].
x
=
x
;
templ
.
path
[
i
].
y
=
y
;
}
fscanf
(
fp
,
"
\n
"
);
if
(
touchId
>=
0
)
{
if
(
SDL_AddDollarGesture
(
touch
,
templ
))
loaded
++
;
}
else
{
for
(
i
=
0
;
i
<
numGestureTouches
;
i
++
)
{
if
(
gestureTouch
[
i
].
id
==
touchId
)
{
touch
=
&
gestureTouch
[
i
];
SDL_AddDollarGesture
(
touch
,
templ
);
}
}
loaded
++
;
}
}
return
1
;
}
//path is an already sampled set of points
//Returns the index of the gesture on success, or -1
int
SDL_AddDollarGesture
(
GestureTouch
*
inTouch
,
Point
*
path
)
{
if
(
inTouch
==
NULL
)
{
if
(
numGestureTouches
==
0
)
return
-
1
;
int
i
=
0
;
for
(
i
=
0
;
i
<
numGestureTouches
;
i
++
)
{
inTouch
=
&
gestureTouch
[
i
];
if
(
inTouch
->
numDollarTemplates
<
MAXTEMPLATES
)
{
DollarTemplate
*
templ
=
&
inTouch
->
dollarTemplate
[
inTouch
->
numDollarTemplates
];
memcpy
(
templ
->
path
,
path
,
DOLLARNPOINTS
*
sizeof
(
Point
));
templ
->
hash
=
SDL_HashDollar
(
templ
->
path
);
inTouch
->
numDollarTemplates
++
;
}
}
return
inTouch
->
numDollarTemplates
-
1
;
}
else
if
(
inTouch
->
numDollarTemplates
<
MAXTEMPLATES
)
{
DollarTemplate
*
templ
=
&
inTouch
->
dollarTemplate
[
inTouch
->
numDollarTemplates
];
memcpy
(
templ
->
path
,
path
,
DOLLARNPOINTS
*
sizeof
(
Point
));
templ
->
hash
=
SDL_HashDollar
(
templ
->
path
);
inTouch
->
numDollarTemplates
++
;
return
inTouch
->
numDollarTemplates
-
1
;
}
return
-
1
;
}
float
dollarDifference
(
Point
*
points
,
Point
*
templ
,
float
ang
)
{
// Point p[DOLLARNPOINTS];
...
...
@@ -141,7 +273,7 @@ float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) {
int
bestDiff
=
10000
;
*
bestTempl
=
-
1
;
for
(
i
=
0
;
i
<
touch
->
numDollarTemplates
;
i
++
)
{
int
diff
=
bestDollarDifference
(
points
,
touch
->
dollarTemplate
[
i
]);
int
diff
=
bestDollarDifference
(
points
,
touch
->
dollarTemplate
[
i
]
.
path
);
if
(
diff
<
bestDiff
)
{
bestDiff
=
diff
;
*
bestTempl
=
i
;}
}
return
bestDiff
;
...
...
@@ -239,6 +371,8 @@ int SDL_GestureAddTouch(SDL_Touch* touch) {
gestureTouch
[
numGestureTouches
].
numDollarTemplates
=
0
;
gestureTouch
[
numGestureTouches
].
recording
=
SDL_FALSE
;
numGestureTouches
++
;
return
0
;
}
...
...
@@ -277,6 +411,17 @@ int SDL_SendGestureDollar(GestureTouch* touch,int gestureId,float error) {
return
SDL_PushEvent
(
&
event
)
>
0
;
}
int
SDL_SendDollarRecord
(
GestureTouch
*
touch
,
int
gestureId
)
{
SDL_Event
event
;
event
.
dgesture
.
type
=
SDL_DOLLARRECORD
;
event
.
dgesture
.
touchId
=
touch
->
id
;
event
.
dgesture
.
gestureId
=
gestureId
;
return
SDL_PushEvent
(
&
event
)
>
0
;
}
void
SDL_GestureProcessEvent
(
SDL_Event
*
event
)
{
if
(
event
->
type
==
SDL_FINGERMOTION
||
...
...
@@ -294,23 +439,44 @@ void SDL_GestureProcessEvent(SDL_Event* event)
for
(
j
=
0
;
j
<
inTouch
->
numDownFingers
;
j
++
)
{
if
(
inTouch
->
gestureLast
[
j
].
f
.
id
!=
event
->
tfinger
.
fingerId
)
continue
;
//Finger Up
if
(
event
->
type
==
SDL_FINGERUP
)
{
inTouch
->
numDownFingers
--
;
int
bestTempl
;
float
error
;
error
=
dollarRecognize
(
inTouch
->
gestureLast
[
j
].
dollarPath
,
&
bestTempl
,
inTouch
);
if
(
bestTempl
>=
0
){
//Send Event
int
gestureId
=
0
;
//?
SDL_SendGestureDollar
(
inTouch
->
id
,
gestureId
,
error
);
printf
(
"Dollar error: %f
\n
"
,
error
);
if
(
inTouch
->
recording
)
{
inTouch
->
recording
=
SDL_FALSE
;
Point
path
[
DOLLARNPOINTS
];
dollarNormalize
(
inTouch
->
gestureLast
[
j
].
dollarPath
,
path
);
int
index
;
if
(
recordAll
)
{
index
=
SDL_AddDollarGesture
(
NULL
,
path
);
int
i
;
for
(
i
=
0
;
i
<
numGestureTouches
;
i
++
)
gestureTouch
[
i
].
recording
=
SDL_FALSE
;
}
else
{
index
=
SDL_AddDollarGesture
(
inTouch
,
path
);
}
if
(
index
>=
0
)
{
SDL_SendDollarRecord
(
inTouch
,
inTouch
->
dollarTemplate
[
index
].
hash
);
}
else
{
SDL_SendDollarRecord
(
inTouch
,
-
1
);
}
}
else
{
int
bestTempl
;
float
error
;
error
=
dollarRecognize
(
inTouch
->
gestureLast
[
j
].
dollarPath
,
&
bestTempl
,
inTouch
);
if
(
bestTempl
>=
0
){
//Send Event
int
gestureId
=
inTouch
->
dollarTemplate
[
bestTempl
].
hash
;
SDL_SendGestureDollar
(
inTouch
,
gestureId
,
error
);
printf
(
"Dollar error: %f
\n
"
,
error
);
}
}
inTouch
->
gestureLast
[
j
]
=
inTouch
->
gestureLast
[
inTouch
->
numDownFingers
];
break
;
}
...
...
src/events/SDL_gesture_c.h
View file @
99ed0692
...
...
@@ -26,6 +26,7 @@
extern
void
SDL_GestureProcessEvent
(
SDL_Event
*
event
);
extern
int
SDL_RecordGesture
(
int
touchId
);
#endif
/* _SDL_gesture_c_h */
...
...
touchTest/gestureSDLTest.c
View file @
99ed0692
This diff is collapsed.
Click to expand it.
touchTest/touchPong
View file @
99ed0692
No preview for this file type
touchTest/touchSimp
View file @
99ed0692
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment