1.1 --- a/.hgignore Sun Aug 22 11:56:07 2010 -0700
1.2 +++ b/.hgignore Sun Aug 22 12:07:55 2010 -0700
1.3 @@ -90,5 +90,6 @@
1.4 test/testatomic
1.5 test/testspriteminimal
1.6 test/testfill
1.7 +test/testgesture
1.8 test/*.exe
1.9 test/*.dSYM
2.1 --- a/Makefile.in Sun Aug 22 11:56:07 2010 -0700
2.2 +++ b/Makefile.in Sun Aug 22 12:07:55 2010 -0700
2.3 @@ -44,7 +44,7 @@
2.4
2.5 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
2.6
2.7 -HDRS = SDL.h SDL_assert.h SDL_atomic.h SDL_audio.h SDL_clipboard.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_haptic.h SDL_input.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
2.8 +HDRS = SDL.h SDL_assert.h SDL_atomic.h SDL_audio.h SDL_clipboard.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_gesture.h SDL_haptic.h SDL_input.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_touch.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h
2.9
2.10 LT_AGE = @LT_AGE@
2.11 LT_CURRENT = @LT_CURRENT@
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/README.gesture Sun Aug 22 12:07:55 2010 -0700
3.3 @@ -0,0 +1,72 @@
3.4 +===========================================================================
3.5 +Dollar Gestures
3.6 +===========================================================================
3.7 +SDL Provides an implementation of the $1 gesture recognition system. This allows for recording, saving, loading, and performing single stroke gestures.
3.8 +
3.9 +Gestures can be performed with any number of fingers (the centroid of the fingers must follow the path of the gesture), but the number of fingers must be constant (a finger cannot go down in the middle of a gesture). The path of a gesture is considered the path from the time when the final finger went down, to the first time any finger comes up.
3.10 +
3.11 +Dollar gestures are assigned an Id based on a hash function. This is guaranteed to remain constant for a given gesture. There is a (small) chance that two different gestures will be assigned the same ID. In this case, simply re-recording one of the gestures should result in a different ID.
3.12 +
3.13 +Recording:
3.14 +----------
3.15 +To begin recording on a touch device call:
3.16 +SDL_RecordGesture(SDL_TouchID touchId), where touchId is the id of the touch device you wish to record on, or -1 to record on all connected devices.
3.17 +
3.18 +Recording terminates as soon as a finger comes up. Recording is acknowledged by an SDL_DOLLARRECORD event.
3.19 +A SDL_DOLLARRECORD event is a dgesture with the following fields:
3.20 +
3.21 +event.dgesture.touchId - the Id of the touch used to record the gesture.
3.22 +event.dgesture.gestureId - the unique id of the recoreded gesture.
3.23 +
3.24 +
3.25 +Performing:
3.26 +-----------
3.27 +As long as there is a dollar gesture assigned to a touch, every finger-up event will also cause an SDL_DOLLARGESTURE event with the following fields:
3.28 +
3.29 +event.dgesture.touchId - the Id of the touch which performed the gesture.
3.30 +event.dgesture.gestureId - the unique id of the closest gesture to the performed stroke.
3.31 +event.dgesture.error - the difference between the gesture template and the actual performed gesture. Lower error is a better match.
3.32 +event.dgesture.numFingers - the number of fingers used to draw the stroke.
3.33 +
3.34 +Most programs will want to define an appropriate error threshold and check to be sure taht the error of a gesture is not abnormally high (an indicator that no gesture was performed).
3.35 +
3.36 +
3.37 +
3.38 +Saving:
3.39 +-------
3.40 +To save a template, call SDL_SaveDollarTemplate(gestureId, src) where gestureId is the id of the gesture you want to save, and src is an SDL_RWops pointer to the file where the gesture will be stored.
3.41 +
3.42 +To save all currently loaded templates, call SDL_SaveAllDollarTemplates(src) where source is an SDL_RWops pointer to the file where the gesture will be stored.
3.43 +
3.44 +Both functions return the number of gestures sucessfully saved.
3.45 +
3.46 +
3.47 +Loading:
3.48 +--------
3.49 +To load templates from a file, call SDL_LoadDollarTemplates(touchId,src) where touchId is the id of the touch to load to (or -1 to load to all touch devices), and src is an SDL_RWops pointer to a gesture save file.
3.50 +
3.51 +SDL_LoadDollarTemplates returns the number of templates sucessfully loaded.
3.52 +
3.53 +
3.54 +
3.55 +===========================================================================
3.56 +Multi Gestures
3.57 +===========================================================================
3.58 +SDL provides simple support for pinch/rotate/swipe gestures.
3.59 +Every time a finger is moved an SDL_MULTIGESTURE event is sent with the following fields:
3.60 +
3.61 +event.mgesture.touchId - the Id of the touch on which the gesture was performed.
3.62 +event.mgesture.x - the normalized x cooridinate of the gesture. (0..1)
3.63 +event.mgesture.y - the normalized y cooridinate of the gesture. (0..1)
3.64 +event.mgesture.dTheta - the amount that the fingers rotated during this motion.
3.65 +event.mgesture.dDist - the amount that the fingers pinched during this motion.
3.66 +event.mgesture.numFingers - the number of fingers used in the gesture.
3.67 +
3.68 +
3.69 +===========================================================================
3.70 +Notes
3.71 +===========================================================================
3.72 +For a complete example see test/testgesture.c
3.73 +
3.74 +Please direct questions/comments to:
3.75 + jim.tla+sdl_touch@gmail.com
4.1 --- a/README.iphoneos Sun Aug 22 11:56:07 2010 -0700
4.2 +++ b/README.iphoneos Sun Aug 22 12:07:55 2010 -0700
4.3 @@ -34,14 +34,6 @@
4.4 5. Delete the contents of main.m and program your app as a regular SDL program instead. You may replace main.m with your own main.c, but you must tell XCode not to use the project prefix file, as it includes Objective-C code.
4.5
4.6 ==============================================================================
4.7 -Notes -- Touch Input
4.8 -==============================================================================
4.9 -
4.10 -Touch input in SDL for iPhone OS is presently exposed through SDL's mouse input API. Multi-touch input is reported as multiple mice, with each touch associated with a specific mouse. This association stays coherent from the time the touch starts to the time a touch ends.
4.11 -
4.12 -By default, multi-touch is turned ON. This requires some care, because if you simply respond to mouse events without checking which mouse caused the event, you may end up fetching data from the wrong mouse, ie, from an incorrect or invalid touch. To turn multi-touch OFF, you can recompile SDL for iPhone with the macro SDL_IPHONE_MULTIPLE_MICE (found in SDL_config_iphoneos.h) set to 0.
4.13 -
4.14 -==============================================================================
4.15 Notes -- Accelerometer as Joystick
4.16 ==============================================================================
4.17
4.18 @@ -55,7 +47,7 @@
4.19
4.20 Your SDL application for iPhone uses OpenGL ES for video by default.
4.21
4.22 -OpenGL ES for iPhone supports two display pixel formats, RGBA8 and RGB565, which provide a 32 bit and 16 bit color buffer respectively. By default, the implementation uses RGB565, but you may use RGBA8 by setting each color component to 8 bits in SDL_GL_SetAttribute.
4.23 +OpenGL ES for iPhone supports several display pixel formats, such as RGBA8 and RGB565, which provide a 32 bit and 16 bit color buffer respectively. By default, the implementation uses RGB565, but you may use RGBA8 by setting each color component to 8 bits in SDL_GL_SetAttribute.
4.24
4.25 If your application doesn't use OpenGL's depth buffer, you may find significant performance improvement by setting SDL_GL_DEPTH_SIZE to 0.
4.26
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/README.touch Sun Aug 22 12:07:55 2010 -0700
5.3 @@ -0,0 +1,101 @@
5.4 +===========================================================================
5.5 +System Specific Notes
5.6 +===========================================================================
5.7 +Linux:
5.8 +The linux touch system is currently based off event streams, and proc/bus/devices. The active user must be given permissions to read /dev/input/TOUCHDEVICE, where TOUCHDEVICE is the event stream for your device. Currently only Wacom tablets are supported. If you have an unsupported tablet contact me at jim.tla+sdl_touch@gmail.com and I will help you get support for it.
5.9 +
5.10 +Mac:
5.11 +The Mac and Iphone API's are pretty. If your touch device supports them then you'll be fine. If it doesn't, then there isn't much we can do.
5.12 +
5.13 +iPhone:
5.14 +Works out of box.
5.15 +
5.16 +Windows:
5.17 +Unfortunately there is no windows support as of yet. Support for Windows 7 is planned, but we currently have no way to test. If you have a Windows 7 WM_TOUCH supported device, and are willing to help test please contact me at jim.tla+sdl_touch@gmail.com
5.18 +
5.19 +===========================================================================
5.20 +Events
5.21 +===========================================================================
5.22 +SDL_FINGERDOWN:
5.23 +Sent when a finger (or stylus) is placed on a touch device.
5.24 +Fields:
5.25 +event.tfinger.touchId - the Id of the touch device.
5.26 +event.tfinger.fingerId - the Id of the finger which just went down.
5.27 +event.tfinger.x - the x coordinate of the touch (0..touch.xres)
5.28 +event.tfinger.y - the y coordinate of the touch (0..touch.yres)
5.29 +event.tfinger.pressure - the pressure of the touch (0..touch.pressureres)
5.30 +
5.31 +SDL_FINGERMOTION:
5.32 +Sent when a finger (or stylus) is moved on the touch device.
5.33 +Fields:
5.34 +Same as FINGERDOWN but with additional:
5.35 +event.tfginer.dx - change in x coordinate during this motion event.
5.36 +event.tfginer.dy - change in y coordinate during this motion event.
5.37 +
5.38 +SDL_FINGERMOTION:
5.39 +Sent when a finger (or stylus) is lifted from the touch device.
5.40 +Fields:
5.41 +Same as FINGERDOWN.
5.42 +
5.43 +
5.44 +===========================================================================
5.45 +Functions
5.46 +===========================================================================
5.47 +SDL provides the ability to access the underlying Touch and Finger structures.
5.48 +These structures should _never_ be modified.
5.49 +
5.50 +The following functions are included from SDL_Touch.h
5.51 +
5.52 +To get a SDL_Touch device call SDL_GetTouch(touchId).
5.53 +This returns an SDL_Touch*.
5.54 +IMPORTANT: If the touch has been removed, or there is no touch with the given ID, SDL_GetTouch will return null. Be sure to check for this!
5.55 +
5.56 +An SDL_Touch has the following fields:
5.57 +>xres,yres,pressures:
5.58 + The resolution at which x,y, and pressure values are reported. Currently these will always be equal to 2^15, but this may not always be the case.
5.59 +
5.60 +>pressure_max, pressure_min, x_max, x_min, y_max, y_min
5.61 + Which give, respectively, the maximum and minumum values that the touch digitizer can return for pressure, x coordiniate, and y coordinate AS REPORTED BY THE OPERATING SYSTEM.
5.62 +On Mac/iPhone systems _max will always be 0, and _min will always be 1.
5.63 +
5.64 +>native_xres,native_yres,native_pressureres:
5.65 + The native resolution of the touch device AS REPORTED BY THE OPERATING SYSTEM.
5.66 +On Mac/iPhone systems these will always be 1.
5.67 +
5.68 +>num_fingers:
5.69 + The number of fingers currently down on the device.
5.70 +
5.71 +>fingers:
5.72 + An array of pointers to the fingers which are on the device.
5.73 +
5.74 +
5.75 +The most common reason to access a touch device is to normalize inputs. This would be accomplished by code like the following:
5.76 +
5.77 + SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
5.78 + if(inTouch == NULL) continue; //The touch has been removed
5.79 +
5.80 + float x = ((float)event.tfinger.x)/inTouch->xres;
5.81 + float y = ((float)event.tfinger.y)/inTouch->yres;
5.82 +
5.83 +
5.84 +
5.85 +To get an SDL_Finger, call SDL_GetFinger(touch,fingerId), where touch is a pointer to an SDL_Touch device, and fingerId is the id of the requested finger.
5.86 +This returns an SDL_Finger*, or null if the finger does not exist, or has been removed.
5.87 +An SDL_Finger is guaranteed to be persistent for the duration of a touch, but it will be de-allocated as soon as the finger is removed. This occurs when the SDL_FINGERUP event is _added_ to the event queue, and thus _before_ the FINGERUP event is polled.
5.88 +As a result, be very careful to check for null return values.
5.89 +
5.90 +An SDL_Finger has the following fields:
5.91 +>x,y,pressure:
5.92 + The current coordinates of the touch.
5.93 +>xdelta,ydelta:
5.94 + The change in position resulting from the last finger motion.
5.95 +>last_x, last_y, last_pressure:
5.96 + The previous coordinates of the touch.
5.97 +
5.98 +===========================================================================
5.99 +Notes
5.100 +===========================================================================
5.101 +For a complete example see test/testgesture.c
5.102 +
5.103 +Please direct questions/comments to:
5.104 + jim.tla+sdl_touch@gmail.com
6.1 --- a/VisualC/SDL/SDL_VS2005.vcproj Sun Aug 22 11:56:07 2010 -0700
6.2 +++ b/VisualC/SDL/SDL_VS2005.vcproj Sun Aug 22 12:07:55 2010 -0700
6.3 @@ -1,10 +1,18 @@
6.4 <?xml version="1.0" encoding="Windows-1252"?>
6.5 <VisualStudioProject
6.6 ProjectType="Visual C++"
6.7 +<<<<<<< local
6.8 Version="8.00"
6.9 +=======
6.10 + Version="9.00"
6.11 +>>>>>>> other
6.12 Name="SDL"
6.13 ProjectGUID="{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}"
6.14 RootNamespace="SDL"
6.15 +<<<<<<< local
6.16 +=======
6.17 + TargetFrameworkVersion="131072"
6.18 +>>>>>>> other
6.19 >
6.20 <Platforms>
6.21 <Platform
6.22 @@ -76,16 +84,36 @@
6.23 />
6.24 <Tool
6.25 Name="VCLinkerTool"
6.26 +<<<<<<< local
6.27 AdditionalOptions="/MACHINE:I386"
6.28 +=======
6.29 + AdditionalOptions="/MACHINE:I386
msvcrt.lib"
6.30 +>>>>>>> other
6.31 AdditionalDependencies="msimg32.lib winmm.lib"
6.32 OutputFile=".\Debug/SDL.dll"
6.33 LinkIncremental="2"
6.34 SuppressStartupBanner="true"
6.35 +<<<<<<< local
6.36 IgnoreAllDefaultLibraries="true"
6.37 +=======
6.38 + IgnoreAllDefaultLibraries="false"
6.39 + IgnoreDefaultLibraryNames=""
6.40 +>>>>>>> other
6.41 GenerateDebugInformation="true"
6.42 ProgramDatabaseFile=".\Debug/SDL.pdb"
6.43 +<<<<<<< local
6.44 SubSystem="2"
6.45 +=======
6.46 + SubSystem="0"
6.47 + RandomizedBaseAddress="1"
6.48 + DataExecutionPrevention="0"
6.49 +>>>>>>> other
6.50 ImportLibrary=".\Debug/SDL.lib"
6.51 +<<<<<<< local
6.52 +=======
6.53 + Profile="true"
6.54 + CLRThreadAttribute="0"
6.55 +>>>>>>> other
6.56 CLRUnmanagedCodeCheck="false"
6.57 />
6.58 <Tool
6.59 @@ -107,9 +135,12 @@
6.60 Name="VCAppVerifierTool"
6.61 />
6.62 <Tool
6.63 +<<<<<<< local
6.64 Name="VCWebDeploymentTool"
6.65 />
6.66 <Tool
6.67 +=======
6.68 +>>>>>>> other
6.69 Name="VCPostBuildEventTool"
6.70 />
6.71 </Configuration>
6.72 @@ -185,6 +216,11 @@
6.73 IgnoreAllDefaultLibraries="true"
6.74 ProgramDatabaseFile=".\Release/SDL.pdb"
6.75 SubSystem="2"
6.76 +<<<<<<< local
6.77 +=======
6.78 + RandomizedBaseAddress="1"
6.79 + DataExecutionPrevention="0"
6.80 +>>>>>>> other
6.81 ImportLibrary=".\Release/SDL.lib"
6.82 />
6.83 <Tool
6.84 @@ -206,9 +242,12 @@
6.85 Name="VCAppVerifierTool"
6.86 />
6.87 <Tool
6.88 +<<<<<<< local
6.89 Name="VCWebDeploymentTool"
6.90 />
6.91 <Tool
6.92 +=======
6.93 +>>>>>>> other
6.94 Name="VCPostBuildEventTool"
6.95 />
6.96 </Configuration>
6.97 @@ -941,6 +980,17 @@
6.98 >
6.99 </File>
6.100 <File
6.101 +<<<<<<< local
6.102 +=======
6.103 + RelativePath="..\..\src\events\SDL_touch.c"
6.104 + >
6.105 + </File>
6.106 + <File
6.107 + RelativePath="..\..\src\events\SDL_touch_c.h"
6.108 + >
6.109 + </File>
6.110 + <File
6.111 +>>>>>>> other
6.112 RelativePath="..\..\src\video\SDL_video.c"
6.113 >
6.114 </File>
8.1 --- a/VisualC/SDLmain/SDLmain_VS2005.vcproj Sun Aug 22 11:56:07 2010 -0700
8.2 +++ b/VisualC/SDLmain/SDLmain_VS2005.vcproj Sun Aug 22 12:07:55 2010 -0700
8.3 @@ -1,9 +1,17 @@
8.4 <?xml version="1.0" encoding="Windows-1252"?>
8.5 <VisualStudioProject
8.6 ProjectType="Visual C++"
8.7 +<<<<<<< local
8.8 Version="8.00"
8.9 +=======
8.10 + Version="9.00"
8.11 +>>>>>>> other
8.12 Name="SDLmain"
8.13 ProjectGUID="{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}"
8.14 +<<<<<<< local
8.15 +=======
8.16 + TargetFrameworkVersion="131072"
8.17 +>>>>>>> other
8.18 >
8.19 <Platforms>
8.20 <Platform
8.21 @@ -25,7 +33,11 @@
8.22 <Tool
8.23 Name="VCPreBuildEventTool"
8.24 Description="Making sure basic SDL headers are in place..."
8.25 +<<<<<<< local
8.26 CommandLine="if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY
echo Copying SDL_config_win32.h to SDL_config.h...
copy "$(ProjectDir)\..\..\include\SDL_config_win32.h" "$(ProjectDir)\..\..\include\SDL_config.h"
:SDLCONFIGOKAY

if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
echo Creating stub SDL_revision.h file...
echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
:SDLREVISIONOKAY"
8.27 +=======
8.28 + CommandLine="if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY
echo Copying SDL_config_win32.h to SDL_config.h...
copy "$(ProjectDir)\..\..\include\SDL_config_win32.h" "$(ProjectDir)\..\..\include\SDL_config.h"
:SDLCONFIGOKAY

if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
echo Creating stub SDL_revision.h file...
echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
:SDLREVISIONOKAY
"
8.29 +>>>>>>> other
8.30 />
8.31 <Tool
8.32 Name="VCCustomBuildTool"
8.33 @@ -98,7 +110,11 @@
8.34 <Tool
8.35 Name="VCPreBuildEventTool"
8.36 Description="Making sure basic SDL headers are in place..."
8.37 +<<<<<<< local
8.38 CommandLine="if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY
echo Copying SDL_config_win32.h to SDL_config.h...
copy "$(ProjectDir)\..\..\include\SDL_config_win32.h" "$(ProjectDir)\..\..\include\SDL_config.h"
:SDLCONFIGOKAY

if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
echo Creating stub SDL_revision.h file...
echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
:SDLREVISIONOKAY"
8.39 +=======
8.40 + CommandLine="if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY
echo Copying SDL_config_win32.h to SDL_config.h...
copy "$(ProjectDir)\..\..\include\SDL_config_win32.h" "$(ProjectDir)\..\..\include\SDL_config.h"
:SDLCONFIGOKAY

if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
echo Creating stub SDL_revision.h file...
echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
:SDLREVISIONOKAY
"
8.41 +>>>>>>> other
8.42 />
8.43 <Tool
8.44 Name="VCCustomBuildTool"
8.45 @@ -171,7 +187,11 @@
8.46 <Tool
8.47 Name="VCPreBuildEventTool"
8.48 Description="Making sure basic SDL headers are in place..."
8.49 +<<<<<<< local
8.50 CommandLine="if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY
echo Copying SDL_config_win32.h to SDL_config.h...
copy "$(ProjectDir)\..\..\include\SDL_config_win32.h" "$(ProjectDir)\..\..\include\SDL_config.h"
:SDLCONFIGOKAY

if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
echo Creating stub SDL_revision.h file...
echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
:SDLREVISIONOKAY"
8.51 +=======
8.52 + CommandLine="if exist "$(ProjectDir)\..\..\include\SDL_config.h" goto SDLCONFIGOKAY
echo Copying SDL_config_win32.h to SDL_config.h...
copy "$(ProjectDir)\..\..\include\SDL_config_win32.h" "$(ProjectDir)\..\..\include\SDL_config.h"
:SDLCONFIGOKAY

if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
echo Creating stub SDL_revision.h file...
echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
:SDLREVISIONOKAY
"
8.53 +>>>>>>> other
8.54 />
8.55 <Tool
8.56 Name="VCCustomBuildTool"
9.1 --- a/Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj Sun Aug 22 11:56:07 2010 -0700
9.2 +++ b/Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj Sun Aug 22 12:07:55 2010 -0700
9.3 @@ -109,7 +109,7 @@
9.4 isa = PBXContainerItemProxy;
9.5 containerPortal = FD1B48920E313154007AB34E /* SDLiPhoneOS.xcodeproj */;
9.6 proxyType = 2;
9.7 - remoteGlobalIDString = 006E982211955059001DE610 /* testsdl.app */;
9.8 + remoteGlobalIDString = 006E982211955059001DE610;
9.9 remoteInfo = testsdl;
9.10 };
9.11 FD1B489D0E313154007AB34E /* PBXContainerItemProxy */ = {
10.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj Sun Aug 22 11:56:07 2010 -0700
10.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj Sun Aug 22 12:07:55 2010 -0700
10.3 @@ -95,6 +95,12 @@
10.4 04B2ECEE1025CE4800F9BC5F /* SDL_revision.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE81025CE4800F9BC5F /* SDL_revision.h */; settings = {ATTRIBUTES = (Public, ); }; };
10.5 04B2ECFF1025CEB900F9BC5F /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04B2ECF11025CEB900F9BC5F /* SDL_atomic.c */; };
10.6 04B2ED081025CF9E00F9BC5F /* SDL_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ED061025CF9E00F9BC5F /* SDL_config.h */; settings = {ATTRIBUTES = (Public, ); }; };
10.7 + 04BA9D6311EF474A00B60E01 /* SDL_gesture_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */; };
10.8 + 04BA9D6411EF474A00B60E01 /* SDL_gesture.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BA9D6011EF474A00B60E01 /* SDL_gesture.c */; };
10.9 + 04BA9D6511EF474A00B60E01 /* SDL_touch_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D6111EF474A00B60E01 /* SDL_touch_c.h */; };
10.10 + 04BA9D6611EF474A00B60E01 /* SDL_touch.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BA9D6211EF474A00B60E01 /* SDL_touch.c */; };
10.11 + 04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */; };
10.12 + 04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7C11EF497E00B60E01 /* SDL_touch.h */; };
10.13 04EC8B521025D12900431D42 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */; };
10.14 04F2AF541104ABC300D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */; };
10.15 04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF551104ABD200D6DDF7 /* SDL_assert.c */; };
10.16 @@ -346,6 +352,12 @@
10.17 04B2ECE81025CE4800F9BC5F /* SDL_revision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_revision.h; path = ../../include/SDL_revision.h; sourceTree = SOURCE_ROOT; };
10.18 04B2ECF11025CEB900F9BC5F /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
10.19 04B2ED061025CF9E00F9BC5F /* SDL_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_config.h; path = ../../include/SDL_config.h; sourceTree = SOURCE_ROOT; };
10.20 + 04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gesture_c.h; sourceTree = "<group>"; };
10.21 + 04BA9D6011EF474A00B60E01 /* SDL_gesture.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gesture.c; sourceTree = "<group>"; };
10.22 + 04BA9D6111EF474A00B60E01 /* SDL_touch_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_touch_c.h; sourceTree = "<group>"; };
10.23 + 04BA9D6211EF474A00B60E01 /* SDL_touch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_touch.c; sourceTree = "<group>"; };
10.24 + 04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_gesture.h; path = ../../include/SDL_gesture.h; sourceTree = SOURCE_ROOT; };
10.25 + 04BA9D7C11EF497E00B60E01 /* SDL_touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_touch.h; path = ../../include/SDL_touch.h; sourceTree = SOURCE_ROOT; };
10.26 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_config_iphoneos.h; path = ../../include/SDL_config_iphoneos.h; sourceTree = SOURCE_ROOT; };
10.27 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_assert.h; path = ../../include/SDL_assert.h; sourceTree = SOURCE_ROOT; };
10.28 04F2AF551104ABD200D6DDF7 /* SDL_assert.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_assert.c; path = ../../src/SDL_assert.c; sourceTree = SOURCE_ROOT; };
10.29 @@ -851,6 +863,7 @@
10.30 FD99B8F60DD52EB400FB1D6B /* SDL_endian.h */,
10.31 FD99B8DC0DD52EB400FB1D6B /* SDL_error.h */,
10.32 FD99B8DD0DD52EB400FB1D6B /* SDL_events.h */,
10.33 + 04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */,
10.34 04461DED0EA76BA3006C462D /* SDL_haptic.h */,
10.35 044E5FB411E6069F0076F181 /* SDL_input.h */,
10.36 FD99B8DE0DD52EB400FB1D6B /* SDL_joystick.h */,
10.37 @@ -876,6 +889,7 @@
10.38 FD99B8EF0DD52EB400FB1D6B /* SDL_syswm.h */,
10.39 FD99B8F00DD52EB400FB1D6B /* SDL_thread.h */,
10.40 FD99B8F10DD52EB400FB1D6B /* SDL_timer.h */,
10.41 + 04BA9D7C11EF497E00B60E01 /* SDL_touch.h */,
10.42 FD99B8F20DD52EB400FB1D6B /* SDL_types.h */,
10.43 FD99B8F30DD52EB400FB1D6B /* SDL_version.h */,
10.44 FD99B8F40DD52EB400FB1D6B /* SDL_video.h */,
10.45 @@ -956,6 +970,10 @@
10.46 FD99B98C0DD52EDC00FB1D6B /* events */ = {
10.47 isa = PBXGroup;
10.48 children = (
10.49 + 04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */,
10.50 + 04BA9D6011EF474A00B60E01 /* SDL_gesture.c */,
10.51 + 04BA9D6111EF474A00B60E01 /* SDL_touch_c.h */,
10.52 + 04BA9D6211EF474A00B60E01 /* SDL_touch.c */,
10.53 FD99B98D0DD52EDC00FB1D6B /* blank_cursor.h */,
10.54 FD99B98E0DD52EDC00FB1D6B /* default_cursor.h */,
10.55 FD99B98F0DD52EDC00FB1D6B /* scancodes_darwin.h */,
10.56 @@ -1191,6 +1209,10 @@
10.57 044E5FB511E6069F0076F181 /* SDL_clipboard.h in Headers */,
10.58 044E5FB611E6069F0076F181 /* SDL_input.h in Headers */,
10.59 0420497011E6F03D007E7EC9 /* SDL_clipboardevents_c.h in Headers */,
10.60 + 04BA9D6311EF474A00B60E01 /* SDL_gesture_c.h in Headers */,
10.61 + 04BA9D6511EF474A00B60E01 /* SDL_touch_c.h in Headers */,
10.62 + 04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */,
10.63 + 04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */,
10.64 );
10.65 runOnlyForDeploymentPostprocessing = 0;
10.66 };
10.67 @@ -1431,6 +1453,8 @@
10.68 006E9889119552DD001DE610 /* SDL_rwopsbundlesupport.m in Sources */,
10.69 044E5FB811E606EB0076F181 /* SDL_clipboard.c in Sources */,
10.70 0420497111E6F03D007E7EC9 /* SDL_clipboardevents.c in Sources */,
10.71 + 04BA9D6411EF474A00B60E01 /* SDL_gesture.c in Sources */,
10.72 + 04BA9D6611EF474A00B60E01 /* SDL_touch.c in Sources */,
10.73 );
10.74 runOnlyForDeploymentPostprocessing = 0;
10.75 };
11.1 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj Sun Aug 22 11:56:07 2010 -0700
11.2 +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj Sun Aug 22 12:07:55 2010 -0700
11.3 @@ -476,6 +476,16 @@
11.4 04F2AF671104AC0800D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF651104AC0800D6DDF7 /* SDL_assert.c */; };
11.5 04F2AF691104AC4500D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF681104AC4500D6DDF7 /* SDL_assert.h */; settings = {ATTRIBUTES = (Public, ); }; };
11.6 04F2AF6A1104AC4500D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF681104AC4500D6DDF7 /* SDL_assert.h */; };
11.7 + 8CB0A76C11F6A84800CBA2DE /* SDL_x11clipboard.c in Sources */ = {isa = PBXBuildFile; fileRef = 8CB0A76A11F6A84800CBA2DE /* SDL_x11clipboard.c */; };
11.8 + 8CB0A76D11F6A84800CBA2DE /* SDL_x11clipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A76B11F6A84800CBA2DE /* SDL_x11clipboard.h */; };
11.9 + 8CB0A77811F6A87F00CBA2DE /* SDL_gesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A77611F6A87F00CBA2DE /* SDL_gesture.h */; };
11.10 + 8CB0A77911F6A87F00CBA2DE /* SDL_touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A77711F6A87F00CBA2DE /* SDL_touch.h */; };
11.11 + 8CB0A77E11F6A8E700CBA2DE /* SDL_gesture_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A77A11F6A8E700CBA2DE /* SDL_gesture_c.h */; };
11.12 + 8CB0A77F11F6A8E700CBA2DE /* SDL_gesture.c in Sources */ = {isa = PBXBuildFile; fileRef = 8CB0A77B11F6A8E700CBA2DE /* SDL_gesture.c */; };
11.13 + 8CB0A78011F6A8E700CBA2DE /* SDL_touch_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A77C11F6A8E700CBA2DE /* SDL_touch_c.h */; };
11.14 + 8CB0A78111F6A8E700CBA2DE /* SDL_touch.c in Sources */ = {isa = PBXBuildFile; fileRef = 8CB0A77D11F6A8E700CBA2DE /* SDL_touch.c */; };
11.15 + 8CB0A78711F6A90B00CBA2DE /* SDL_eventtouch.c in Sources */ = {isa = PBXBuildFile; fileRef = 8CB0A78511F6A90B00CBA2DE /* SDL_eventtouch.c */; };
11.16 + 8CB0A78811F6A90B00CBA2DE /* SDL_eventtouch.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CB0A78611F6A90B00CBA2DE /* SDL_eventtouch.h */; };
11.17 BECDF62E0761BA81005FE872 /* SDL_audio.c in Sources */ = {isa = PBXBuildFile; fileRef = 01538330006D78D67F000001 /* SDL_audio.c */; };
11.18 BECDF62F0761BA81005FE872 /* SDL_audiocvt.c in Sources */ = {isa = PBXBuildFile; fileRef = 01538331006D78D67F000001 /* SDL_audiocvt.c */; };
11.19 BECDF6300761BA81005FE872 /* SDL_audiodev.c in Sources */ = {isa = PBXBuildFile; fileRef = 01538332006D78D67F000001 /* SDL_audiodev.c */; };
11.20 @@ -864,6 +874,17 @@
11.21 0C5AF5FD01191D2B7F000001 /* SDL_version.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_version.h; path = ../../include/SDL_version.h; sourceTree = SOURCE_ROOT; };
11.22 0C5AF5FE01191D2B7F000001 /* SDL_video.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_video.h; path = ../../include/SDL_video.h; sourceTree = SOURCE_ROOT; };
11.23 0C5AF5FF01191D2B7F000001 /* SDL.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL.h; path = ../../include/SDL.h; sourceTree = SOURCE_ROOT; };
11.24 + 8C93F0EA11F803710014F54D /* gestureSDLTest-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "gestureSDLTest-Info.plist"; sourceTree = "<group>"; };
11.25 + 8CB0A76A11F6A84800CBA2DE /* SDL_x11clipboard.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_x11clipboard.c; sourceTree = "<group>"; };
11.26 + 8CB0A76B11F6A84800CBA2DE /* SDL_x11clipboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_x11clipboard.h; sourceTree = "<group>"; };
11.27 + 8CB0A77611F6A87F00CBA2DE /* SDL_gesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_gesture.h; path = ../../include/SDL_gesture.h; sourceTree = SOURCE_ROOT; };
11.28 + 8CB0A77711F6A87F00CBA2DE /* SDL_touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_touch.h; path = ../../include/SDL_touch.h; sourceTree = SOURCE_ROOT; };
11.29 + 8CB0A77A11F6A8E700CBA2DE /* SDL_gesture_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gesture_c.h; sourceTree = "<group>"; };
11.30 + 8CB0A77B11F6A8E700CBA2DE /* SDL_gesture.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gesture.c; sourceTree = "<group>"; };
11.31 + 8CB0A77C11F6A8E700CBA2DE /* SDL_touch_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_touch_c.h; sourceTree = "<group>"; };
11.32 + 8CB0A77D11F6A8E700CBA2DE /* SDL_touch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_touch.c; sourceTree = "<group>"; };
11.33 + 8CB0A78511F6A90B00CBA2DE /* SDL_eventtouch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_eventtouch.c; sourceTree = "<group>"; };
11.34 + 8CB0A78611F6A90B00CBA2DE /* SDL_eventtouch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_eventtouch.h; sourceTree = "<group>"; };
11.35 B24DA50405A88D52006B9F1C /* SDL_cpuinfo.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = SDL_cpuinfo.c; sourceTree = "<group>"; };
11.36 B29A290D04E5B28700A80002 /* SDL_loadso.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_loadso.h; path = ../../include/SDL_loadso.h; sourceTree = "<group>"; };
11.37 B2CF8DC405C444E400E5DC7F /* SDL_cpuinfo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_cpuinfo.h; path = ../../include/SDL_cpuinfo.h; sourceTree = SOURCE_ROOT; };
11.38 @@ -1108,6 +1129,10 @@
11.39 00CFA719106B498B00758660 /* x11 */ = {
11.40 isa = PBXGroup;
11.41 children = (
11.42 + 8CB0A78511F6A90B00CBA2DE /* SDL_eventtouch.c */,
11.43 + 8CB0A78611F6A90B00CBA2DE /* SDL_eventtouch.h */,
11.44 + 8CB0A76A11F6A84800CBA2DE /* SDL_x11clipboard.c */,
11.45 + 8CB0A76B11F6A84800CBA2DE /* SDL_x11clipboard.h */,
11.46 00CFA71A106B498B00758660 /* imKStoUCS.c */,
11.47 00CFA71B106B498B00758660 /* imKStoUCS.h */,
11.48 00CFA71C106B498B00758660 /* SDL_x11dyn.c */,
11.49 @@ -1353,6 +1378,10 @@
11.50 01538367006D79147F000001 /* events */ = {
11.51 isa = PBXGroup;
11.52 children = (
11.53 + 8CB0A77A11F6A8E700CBA2DE /* SDL_gesture_c.h */,
11.54 + 8CB0A77B11F6A8E700CBA2DE /* SDL_gesture.c */,
11.55 + 8CB0A77C11F6A8E700CBA2DE /* SDL_touch_c.h */,
11.56 + 8CB0A77D11F6A8E700CBA2DE /* SDL_touch.c */,
11.57 0420497411E6F052007E7EC9 /* blank_cursor.h */,
11.58 0420497511E6F052007E7EC9 /* default_cursor.h */,
11.59 0420497611E6F052007E7EC9 /* scancodes_darwin.h */,
11.60 @@ -1470,6 +1499,8 @@
11.61 0153844A006D81B07F000001 /* Public Headers */ = {
11.62 isa = PBXGroup;
11.63 children = (
11.64 + 8CB0A77611F6A87F00CBA2DE /* SDL_gesture.h */,
11.65 + 8CB0A77711F6A87F00CBA2DE /* SDL_touch.h */,
11.66 0C5AF5E501191D2B7F000001 /* begin_code.h */,
11.67 0C5AF5E601191D2B7F000001 /* close_code.h */,
11.68 0C5AF5FF01191D2B7F000001 /* SDL.h */,
11.69 @@ -1561,6 +1592,7 @@
11.70 BECDF66B0761BA81005FE872 /* Info-Framework.plist */,
11.71 BEC562FE0761C0E800A33029 /* Linked Frameworks */,
11.72 00D8D9F11195090700638393 /* testsdl-Info.plist */,
11.73 + 8C93F0EA11F803710014F54D /* gestureSDLTest-Info.plist */,
11.74 );
11.75 comments = "To build Universal Binaries, we have experimented with a variety of different options.\nThe complication is that we must retain compatibility with at least 10.2. \nThe Universal Binary defaults only work for > 10.3.9\n\nSo far, we have found:\ngcc 4.0.0 with Xcode 2.1 always links against libgcc_s. gcc 4.0.1 from Xcode 2.2 fixes this problem.\n\nBut gcc 4.0 will not work with < 10.3.9 because we continue to get an undefined symbol to _fprintf$LDBL128.\nSo we must use gcc 3.3 on PPC to accomplish 10.2 support. (But 4.0 is required for i386.)\n\nSetting the deployment target to 10.4 will disable prebinding, so for PPC, we set it less than 10.4 to preserve prebinding for legacy support.\n\nSetting the PPC SDKROOT to /Developers/SDKs/MacOSX10.2.8.sdk will link to 63.0.0 libSystem.B.dylib. Leaving it at current or 10.4u links to 88.1.2. However, as long as we are using gcc 3.3, it doesn't seem to matter as testing has demonstrated both will run. We have decided not to invoke the 10.2.8 SDK because it is not a default installed component with Xcode which will probably cause most people problems. However, rather than deleting the SDKROOT_ppc entry entirely, we have mapped it to 10.4u in case we decide we need to change this setting.\n\nTo use Altivec or SSE, we needed architecture specific flags:\nOTHER_CFLAGS_ppc\nOTHER_CFLAGS_i386\nOTHER_CFLAGS=$(OTHER_CFLAGS_($CURRENT_ARCH))\n\nThe general OTHER_CFLAGS needed to be manually mapped to architecture specific options because Xcode didn't do this automatically for us.\n\n\n";
11.76 name = SDLFramework;
11.77 @@ -1805,6 +1837,12 @@
11.78 0420497D11E6F052007E7EC9 /* scancodes_linux.h in Headers */,
11.79 0420497E11E6F052007E7EC9 /* scancodes_win32.h in Headers */,
11.80 0420497F11E6F052007E7EC9 /* scancodes_xfree86.h in Headers */,
11.81 + 8CB0A76D11F6A84800CBA2DE /* SDL_x11clipboard.h in Headers */,
11.82 + 8CB0A77811F6A87F00CBA2DE /* SDL_gesture.h in Headers */,
11.83 + 8CB0A77911F6A87F00CBA2DE /* SDL_touch.h in Headers */,
11.84 + 8CB0A77E11F6A8E700CBA2DE /* SDL_gesture_c.h in Headers */,
11.85 + 8CB0A78011F6A8E700CBA2DE /* SDL_touch_c.h in Headers */,
11.86 + 8CB0A78811F6A90B00CBA2DE /* SDL_eventtouch.h in Headers */,
11.87 );
11.88 runOnlyForDeploymentPostprocessing = 0;
11.89 };
11.90 @@ -2277,6 +2315,10 @@
11.91 04DEA57511E6009000386CAC /* SDL_clipboard.c in Sources */,
11.92 04DEA57A11E600A600386CAC /* SDL_cocoaclipboard.m in Sources */,
11.93 0420496211E6EFD3007E7EC9 /* SDL_clipboardevents.c in Sources */,
11.94 + 8CB0A76C11F6A84800CBA2DE /* SDL_x11clipboard.c in Sources */,
11.95 + 8CB0A77F11F6A8E700CBA2DE /* SDL_gesture.c in Sources */,
11.96 + 8CB0A78111F6A8E700CBA2DE /* SDL_touch.c in Sources */,
11.97 + 8CB0A78711F6A90B00CBA2DE /* SDL_eventtouch.c in Sources */,
11.98 );
11.99 runOnlyForDeploymentPostprocessing = 0;
11.100 };
12.1 --- a/configure.in Sun Aug 22 11:56:07 2010 -0700
12.2 +++ b/configure.in Sun Aug 22 12:07:55 2010 -0700
12.3 @@ -1005,6 +1005,8 @@
12.4 dnl Find the X11 include and library directories
12.5 CheckX11()
12.6 {
12.7 +
12.8 +
12.9 AC_ARG_ENABLE(video-x11,
12.10 AC_HELP_STRING([--enable-video-x11], [use X11 video driver [[default=yes]]]),
12.11 , enable_video_x11=yes)
13.1 --- a/include/SDL_events.h Sun Aug 22 11:56:07 2010 -0700
13.2 +++ b/include/SDL_events.h Sun Aug 22 12:07:55 2010 -0700
13.3 @@ -36,6 +36,8 @@
13.4 #include "SDL_mouse.h"
13.5 #include "SDL_joystick.h"
13.6 #include "SDL_quit.h"
13.7 +#include "SDL_gesture.h"
13.8 +#include "SDL_touch.h"
13.9
13.10 #include "begin_code.h"
13.11 /* Set up for C function definitions, even when using C++ */
13.12 @@ -90,14 +92,28 @@
13.13 SDL_JOYBUTTONDOWN, /**< Joystick button pressed */
13.14 SDL_JOYBUTTONUP, /**< Joystick button released */
13.15
13.16 + /* Touch events */
13.17 + SDL_FINGERDOWN = 0x700,
13.18 + SDL_FINGERUP,
13.19 + SDL_FINGERMOTION,
13.20 + SDL_TOUCHBUTTONDOWN,
13.21 + SDL_TOUCHBUTTONUP,
13.22 +
13.23 + /* Gesture events */
13.24 + SDL_DOLLARGESTURE = 0x800,
13.25 + SDL_DOLLARRECORD,
13.26 + SDL_MULTIGESTURE,
13.27 +
13.28 /* Clipboard events */
13.29 - SDL_CLIPBOARDUPDATE = 0x700, /**< The clipboard changed */
13.30 +
13.31 + SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
13.32
13.33 /* Obsolete events */
13.34 SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */
13.35 SDL_EVENT_COMPAT2,
13.36 SDL_EVENT_COMPAT3,
13.37
13.38 +
13.39 /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
13.40 * and should be allocated with SDL_RegisterEvents()
13.41 */
13.42 @@ -263,6 +279,79 @@
13.43 Uint8 padding1;
13.44 } SDL_JoyButtonEvent;
13.45
13.46 +
13.47 +/**
13.48 + * \brief Touch finger motion/finger event structure (event.tmotion.*)
13.49 + */
13.50 +typedef struct SDL_TouchFingerEvent
13.51 +{
13.52 + Uint32 type; /**< ::SDL_FINGERMOTION OR
13.53 + SDL_FINGERDOWN OR SDL_FINGERUP*/
13.54 + Uint32 windowID; /**< The window with mouse focus, if any */
13.55 + SDL_TouchID touchId; /**< The touch device id */
13.56 + SDL_FingerID fingerId;
13.57 + Uint8 state; /**< The current button state */
13.58 + Uint8 padding1;
13.59 + Uint8 padding2;
13.60 + Uint8 padding3;
13.61 + Uint16 x;
13.62 + Uint16 y;
13.63 + Sint16 dx;
13.64 + Sint16 dy;
13.65 + Uint16 pressure;
13.66 +} SDL_TouchFingerEvent;
13.67 +
13.68 +
13.69 +/**
13.70 + * \brief Touch finger motion/finger event structure (event.tmotion.*)
13.71 + */
13.72 +typedef struct SDL_TouchButtonEvent
13.73 +{
13.74 + Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
13.75 + Uint32 windowID; /**< The window with mouse focus, if any */
13.76 + SDL_TouchID touchId; /**< The touch device index */
13.77 + Uint8 state; /**< The current button state */
13.78 + Uint8 button; /**< The button changing state */
13.79 + Uint8 padding1;
13.80 + Uint8 padding2;
13.81 +} SDL_TouchButtonEvent;
13.82 +
13.83 +
13.84 +
13.85 +/**
13.86 + * \brief Multiple Finger Gesture Event
13.87 + */
13.88 +typedef struct SDL_MultiGestureEvent
13.89 +{
13.90 + Uint32 type; /**< ::SDL_MULTIGESTURE */
13.91 + Uint32 windowID; /**< The window with mouse focus, if any */
13.92 + SDL_TouchID touchId; /**< The touch device index */
13.93 + float dTheta;
13.94 + float dDist;
13.95 + float x; //currently 0...1. Change to screen coords?
13.96 + float y;
13.97 + Uint16 numFingers;
13.98 + Uint16 padding;
13.99 +} SDL_MultiGestureEvent;
13.100 +
13.101 +typedef struct SDL_DollarGestureEvent
13.102 +{
13.103 + Uint32 type; /**< ::SDL_DOLLARGESTURE */
13.104 + Uint32 windowID; /**< The window with mouse focus, if any */
13.105 + SDL_TouchID touchId; /**< The touch device index */
13.106 + SDL_GestureID gestureId;
13.107 + Uint32 numFingers;
13.108 + float error;
13.109 + /*
13.110 + //TODO: Enable to give location?
13.111 + float x; //currently 0...1. Change to screen coords?
13.112 + float y;
13.113 + */
13.114 +} SDL_DollarGestureEvent;
13.115 +
13.116 +
13.117 +
13.118 +
13.119 /**
13.120 * \brief The "quit requested" event
13.121 */
13.122 @@ -345,6 +434,10 @@
13.123 SDL_QuitEvent quit; /**< Quit request event data */
13.124 SDL_UserEvent user; /**< Custom event data */
13.125 SDL_SysWMEvent syswm; /**< System dependent window event data */
13.126 + SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
13.127 + SDL_TouchButtonEvent tbutton; /**< Touch button event data */
13.128 + SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data*/
13.129 + SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data*/
13.130
13.131 /** Temporarily here for backwards compatibility */
13.132 /*@{*/
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/include/SDL_gesture.h Sun Aug 22 12:07:55 2010 -0700
14.3 @@ -0,0 +1,92 @@
14.4 +/*
14.5 + SDL - Simple DirectMedia Layer
14.6 + Copyright (C) 1997-2010 Sam Lantinga
14.7 +
14.8 + This library is free software; you can redistribute it and/or
14.9 + modify it under the terms of the GNU Lesser General Public
14.10 + License as published by the Free Software Foundation; either
14.11 + version 2.1 of the License, or (at your option) any later version.
14.12 +
14.13 + This library is distributed in the hope that it will be useful,
14.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14.16 + Lesser General Public License for more details.
14.17 +
14.18 + You should have received a copy of the GNU Lesser General Public
14.19 + License along with this library; if not, write to the Free Software
14.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14.21 +
14.22 + Sam Lantinga
14.23 + slouken@libsdl.org
14.24 +*/
14.25 +
14.26 +/**
14.27 + * \file SDL_gesture.h
14.28 + *
14.29 + * Include file for SDL gesture event handling.
14.30 + */
14.31 +
14.32 +#ifndef _SDL_gesture_h
14.33 +#define _SDL_gesture_h
14.34 +
14.35 +#include "SDL_stdinc.h"
14.36 +#include "SDL_error.h"
14.37 +#include "SDL_video.h"
14.38 +
14.39 +#include "SDL_touch.h"
14.40 +
14.41 +
14.42 +#include "begin_code.h"
14.43 +/* Set up for C function definitions, even when using C++ */
14.44 +#ifdef __cplusplus
14.45 +/* *INDENT-OFF* */
14.46 +extern "C" {
14.47 +/* *INDENT-ON* */
14.48 +#endif
14.49 +
14.50 +typedef Sint64 SDL_GestureID;
14.51 +
14.52 +/* Function prototypes */
14.53 +
14.54 +/**
14.55 + * \brief Begin Recording a gesture on the specified touch, or all touches (-1)
14.56 + *
14.57 + *
14.58 + */
14.59 +extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId);
14.60 +
14.61 +
14.62 +/**
14.63 + * \brief Save all currently loaded Dollar Gesture templates
14.64 + *
14.65 + *
14.66 + */
14.67 +extern DECLSPEC int SDLCALL SDL_SaveAllDollarTemplates(SDL_RWops *src);
14.68 +
14.69 +/**
14.70 + * \brief Save a currently loaded Dollar Gesture template
14.71 + *
14.72 + *
14.73 + */
14.74 +extern DECLSPEC int SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *src);
14.75 +
14.76 +
14.77 +/**
14.78 + * \brief Load Dollar Gesture templates from a file
14.79 + *
14.80 + *
14.81 + */
14.82 +extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src);
14.83 +
14.84 +
14.85 +/* Ends C function definitions when using C++ */
14.86 +#ifdef __cplusplus
14.87 +/* *INDENT-OFF* */
14.88 +}
14.89 +/* *INDENT-ON* */
14.90 +#endif
14.91 +#include "close_code.h"
14.92 +
14.93 +#endif /* _SDL_gesture_h */
14.94 +
14.95 +/* vi: set ts=4 sw=4 expandtab: */
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/include/SDL_touch.h Sun Aug 22 12:07:55 2010 -0700
15.3 @@ -0,0 +1,125 @@
15.4 +/*
15.5 + SDL - Simple DirectMedia Layer
15.6 + Copyright (C) 1997-2010 Sam Lantinga
15.7 +
15.8 + This library is free software; you can redistribute it and/or
15.9 + modify it under the terms of the GNU Lesser General Public
15.10 + License as published by the Free Software Foundation; either
15.11 + version 2.1 of the License, or (at your option) any later version.
15.12 +
15.13 + This library is distributed in the hope that it will be useful,
15.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
15.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15.16 + Lesser General Public License for more details.
15.17 +
15.18 + You should have received a copy of the GNU Lesser General Public
15.19 + License along with this library; if not, write to the Free Software
15.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15.21 +
15.22 + Sam Lantinga
15.23 + slouken@libsdl.org
15.24 +*/
15.25 +
15.26 +/**
15.27 + * \file SDL_touch.h
15.28 + *
15.29 + * Include file for SDL touch event handling.
15.30 + */
15.31 +
15.32 +#ifndef _SDL_touch_h
15.33 +#define _SDL_touch_h
15.34 +
15.35 +#include "SDL_stdinc.h"
15.36 +#include "SDL_error.h"
15.37 +#include "SDL_video.h"
15.38 +
15.39 +#include "begin_code.h"
15.40 +/* Set up for C function definitions, even when using C++ */
15.41 +#ifdef __cplusplus
15.42 +/* *INDENT-OFF* */
15.43 +extern "C" {
15.44 +/* *INDENT-ON* */
15.45 +#endif
15.46 +
15.47 +
15.48 +typedef Sint64 SDL_TouchID;
15.49 +typedef Sint64 SDL_FingerID;
15.50 +
15.51 +
15.52 +struct SDL_Finger {
15.53 + SDL_FingerID id;
15.54 + Uint16 x;
15.55 + Uint16 y;
15.56 + Uint16 pressure;
15.57 + Uint16 xdelta;
15.58 + Uint16 ydelta;
15.59 + Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */
15.60 + SDL_bool down;
15.61 +};
15.62 +
15.63 +typedef struct SDL_Touch SDL_Touch;
15.64 +typedef struct SDL_Finger SDL_Finger;
15.65 +
15.66 +
15.67 +struct SDL_Touch {
15.68 +
15.69 + /* Free the touch when it's time */
15.70 + void (*FreeTouch) (SDL_Touch * touch);
15.71 +
15.72 + /* data common for tablets */
15.73 + float pressure_max, pressure_min;
15.74 + float x_max,x_min;
15.75 + float y_max,y_min;
15.76 + Uint16 xres,yres,pressureres;
15.77 + float native_xres,native_yres,native_pressureres;
15.78 + float tilt; /* for future use */
15.79 + float rotation; /* for future use */
15.80 +
15.81 + /* Data common to all touch */
15.82 + SDL_TouchID id;
15.83 + SDL_Window *focus;
15.84 +
15.85 + char *name;
15.86 + Uint8 buttonstate;
15.87 + SDL_bool relative_mode;
15.88 + SDL_bool flush_motion;
15.89 +
15.90 + int num_fingers;
15.91 + int max_fingers;
15.92 + SDL_Finger** fingers;
15.93 +
15.94 + void *driverdata;
15.95 +};
15.96 +
15.97 +
15.98 +
15.99 +/* Function prototypes */
15.100 +
15.101 +/**
15.102 + * \brief Get the touch object at the given id.
15.103 + *
15.104 + *
15.105 + */
15.106 + extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id);
15.107 +
15.108 +
15.109 +
15.110 +/**
15.111 + * \brief Get the finger object of the given touch, at the given id.
15.112 + *
15.113 + *
15.114 + */
15.115 + extern
15.116 + DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id);
15.117 +
15.118 +/* Ends C function definitions when using C++ */
15.119 +#ifdef __cplusplus
15.120 +/* *INDENT-OFF* */
15.121 +}
15.122 +/* *INDENT-ON* */
15.123 +#endif
15.124 +#include "close_code.h"
15.125 +
15.126 +#endif /* _SDL_mouse_h */
15.127 +
15.128 +/* vi: set ts=4 sw=4 expandtab: */
16.1 --- a/src/events/SDL_events.c Sun Aug 22 11:56:07 2010 -0700
16.2 +++ b/src/events/SDL_events.c Sun Aug 22 12:07:55 2010 -0700
16.3 @@ -254,6 +254,7 @@
16.4 retcode = 0;
16.5 retcode += SDL_KeyboardInit();
16.6 retcode += SDL_MouseInit();
16.7 + retcode += SDL_TouchInit();
16.8 retcode += SDL_QuitInit();
16.9 if (retcode < 0) {
16.10 /* We don't expect them to fail, but... */
16.11 @@ -492,6 +493,10 @@
16.12 if (SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0, 0) <= 0) {
16.13 return -1;
16.14 }
16.15 +
16.16 + SDL_GestureProcessEvent(event);
16.17 +
16.18 +
16.19 return 1;
16.20 }
16.21
17.1 --- a/src/events/SDL_events_c.h Sun Aug 22 11:56:07 2010 -0700
17.2 +++ b/src/events/SDL_events_c.h Sun Aug 22 12:07:55 2010 -0700
17.3 @@ -26,8 +26,9 @@
17.4 #include "SDL_thread.h"
17.5 #include "SDL_mouse_c.h"
17.6 #include "SDL_keyboard_c.h"
17.7 +#include "SDL_touch_c.h"
17.8 #include "SDL_windowevents_c.h"
17.9 -
17.10 +#include "SDL_gesture_c.h"
17.11 /* Start and stop the event processing loop */
17.12 extern int SDL_StartEventLoop(Uint32 flags);
17.13 extern void SDL_StopEventLoop(void);
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/src/events/SDL_gesture.c Sun Aug 22 12:07:55 2010 -0700
18.3 @@ -0,0 +1,643 @@
18.4 +/*
18.5 + SDL - Simple DirectMedia Layer
18.6 + Copyright (C) 1997-2010 Sam Lantinga
18.7 +
18.8 + This library is free software; you can redistribute it and/or
18.9 + modify it under the terms of the GNU Lesser General Public
18.10 + License as published by the Free Software Foundation; either
18.11 + version 2.1 of the License, or (at your option) any later version.
18.12 +
18.13 + This library is distributed in the hope that it will be useful,
18.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
18.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18.16 + Lesser General Public License for more details.
18.17 +
18.18 + You should have received a copy of the GNU Lesser General Public
18.19 + License along with this library; if not, write to the Free Software Founation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18.20 +
18.21 + Sam Lantinga
18.22 + slouken@libsdl.org
18.23 +*/
18.24 +#include "SDL_config.h"
18.25 +
18.26 +/* General mouse handling code for SDL */
18.27 +
18.28 +#include "SDL_events.h"
18.29 +#include "SDL_events_c.h"
18.30 +#include "SDL_gesture_c.h"
18.31 +
18.32 +//TODO: Replace with malloc
18.33 +
18.34 +#define MAXPATHSIZE 1024
18.35 +
18.36 +
18.37 +
18.38 +
18.39 +#define DOLLARNPOINTS 64
18.40 +#define DOLLARSIZE 256
18.41 +
18.42 +#define ENABLE_DOLLAR
18.43 +
18.44 +//PHI = ((sqrt(5)-1)/2)
18.45 +#define PHI 0.618033989
18.46 +
18.47 +typedef struct {
18.48 + float x,y;
18.49 +} SDL_FloatPoint;
18.50 +
18.51 +typedef struct {
18.52 + float length;
18.53 +
18.54 + int numPoints;
18.55 + SDL_FloatPoint p[MAXPATHSIZE];
18.56 +} SDL_DollarPath;
18.57 +
18.58 +typedef struct {
18.59 + SDL_FloatPoint path[DOLLARNPOINTS];
18.60 + unsigned long hash;
18.61 +} SDL_DollarTemplate;
18.62 +
18.63 +typedef struct {
18.64 + SDL_GestureID id;
18.65 + SDL_FloatPoint res;
18.66 + SDL_FloatPoint centroid;
18.67 + SDL_DollarPath dollarPath;
18.68 + Uint16 numDownFingers;
18.69 +
18.70 + int numDollarTemplates;
18.71 + SDL_DollarTemplate *dollarTemplate;
18.72 +
18.73 + SDL_bool recording;
18.74 +} SDL_GestureTouch;
18.75 +
18.76 +SDL_GestureTouch *SDL_gestureTouch;
18.77 +int SDL_numGestureTouches = 0;
18.78 +SDL_bool recordAll;
18.79 +
18.80 +void SDL_PrintPath(SDL_FloatPoint *path) {
18.81 + int i;
18.82 + printf("Path:");
18.83 + for(i=0;i<DOLLARNPOINTS;i++) {
18.84 + printf(" (%f,%f)",path[i].x,path[i].y);
18.85 + }
18.86 + printf("\n");
18.87 +}
18.88 +
18.89 +int SDL_RecordGesture(SDL_TouchID touchId) {
18.90 + int i;
18.91 + if(touchId < 0) recordAll = SDL_TRUE;
18.92 + for(i = 0;i < SDL_numGestureTouches; i++) {
18.93 + if((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
18.94 + SDL_gestureTouch[i].recording = SDL_TRUE;
18.95 + if(touchId >= 0)
18.96 + return 1;
18.97 + }
18.98 + }
18.99 + return (touchId < 0);
18.100 +}
18.101 +
18.102 +unsigned long SDL_HashDollar(SDL_FloatPoint* points) {
18.103 + unsigned long hash = 5381;
18.104 + int i;
18.105 + for(i = 0;i < DOLLARNPOINTS; i++) {
18.106 + hash = ((hash<<5) + hash) + points[i].x;
18.107 + hash = ((hash<<5) + hash) + points[i].y;
18.108 + }
18.109 + return hash;
18.110 +}
18.111 +
18.112 +
18.113 +static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src) {
18.114 + if(src == NULL) return 0;
18.115 +
18.116 + int i;
18.117 +
18.118 + //No Longer storing the Hash, rehash on load
18.119 + //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;
18.120 +
18.121 + if(SDL_RWwrite(src,templ->path,
18.122 + sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS)
18.123 + return 0;
18.124 +
18.125 + return 1;
18.126 +}
18.127 +
18.128 +
18.129 +int SDL_SaveAllDollarTemplates(SDL_RWops *src) {
18.130 + int i,j,rtrn = 0;
18.131 + for(i = 0; i < SDL_numGestureTouches; i++) {
18.132 + SDL_GestureTouch* touch = &SDL_gestureTouch[i];
18.133 + for(j = 0;j < touch->numDollarTemplates; j++) {
18.134 + rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
18.135 + }
18.136 + }
18.137 + return rtrn;
18.138 +}
18.139 +
18.140 +int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) {
18.141 + int i,j;
18.142 + for(i = 0; i < SDL_numGestureTouches; i++) {
18.143 + SDL_GestureTouch* touch = &SDL_gestureTouch[i];
18.144 + for(j = 0;j < touch->numDollarTemplates; j++) {
18.145 + if(touch->dollarTemplate[i].hash == gestureId) {
18.146 + return SaveTemplate(&touch->dollarTemplate[i],src);
18.147 + }
18.148 + }
18.149 + }
18.150 + SDL_SetError("Unknown gestureId");
18.151 + return -1;
18.152 +}
18.153 +
18.154 +//path is an already sampled set of points
18.155 +//Returns the index of the gesture on success, or -1
18.156 +static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) {
18.157 + if(inTouch == NULL) {
18.158 + if(SDL_numGestureTouches == 0) return -1;
18.159 + int i = 0;
18.160 + for(i = 0;i < SDL_numGestureTouches; i++) {
18.161 + inTouch = &SDL_gestureTouch[i];
18.162 +
18.163 + SDL_DollarTemplate* dollarTemplate =
18.164 + SDL_realloc(inTouch->dollarTemplate,
18.165 + (inTouch->numDollarTemplates + 1) *
18.166 + sizeof(SDL_DollarTemplate));
18.167 + if(!dollarTemplate) {
18.168 + SDL_OutOfMemory();
18.169 + return -1;
18.170 + }
18.171 +
18.172 + inTouch->dollarTemplate = dollarTemplate;
18.173 +
18.174 + SDL_DollarTemplate *templ =
18.175 + &inTouch->dollarTemplate[inTouch->numDollarTemplates];
18.176 + memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint));
18.177 + templ->hash = SDL_HashDollar(templ->path);
18.178 + inTouch->numDollarTemplates++;
18.179 + }
18.180 + return inTouch->numDollarTemplates - 1;
18.181 + } else {
18.182 + SDL_DollarTemplate* dollarTemplate =
18.183 + SDL_realloc(inTouch->dollarTemplate,
18.184 + (inTouch->numDollarTemplates + 1) *
18.185 + sizeof(SDL_DollarTemplate));
18.186 + if(!dollarTemplate) {
18.187 + SDL_OutOfMemory();
18.188 + return -1;
18.189 + }
18.190 +
18.191 + inTouch->dollarTemplate = dollarTemplate;
18.192 +
18.193 + SDL_DollarTemplate *templ =
18.194 + &inTouch->dollarTemplate[inTouch->numDollarTemplates];
18.195 + memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint));
18.196 + templ->hash = SDL_HashDollar(templ->path);
18.197 + inTouch->numDollarTemplates++;
18.198 + return inTouch->numDollarTemplates - 1;
18.199 + }
18.200 + return -1;
18.201 +}
18.202 +
18.203 +int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) {
18.204 + if(src == NULL) return 0;
18.205 + int i,loaded = 0;
18.206 + SDL_GestureTouch *touch = NULL;
18.207 + if(touchId >= 0) {
18.208 + for(i = 0;i < SDL_numGestureTouches; i++)
18.209 + if(SDL_gestureTouch[i].id == touchId)
18.210 + touch = &SDL_gestureTouch[i];
18.211 + if(touch == NULL) return -1;
18.212 + }
18.213 +
18.214 + while(1) {
18.215 + SDL_DollarTemplate templ;
18.216 +
18.217 + if(SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) <
18.218 + DOLLARNPOINTS) break;
18.219 +
18.220 + if(touchId >= 0) {
18.221 + printf("Adding loaded gesture to 1 touch\n");
18.222 + if(SDL_AddDollarGesture(touch,templ.path)) loaded++;
18.223 + }
18.224 + else {
18.225 + printf("Adding to: %i touches\n",SDL_numGestureTouches);
18.226 + for(i = 0;i < SDL_numGestureTouches; i++) {
18.227 + touch = &SDL_gestureTouch[i];
18.228 + printf("Adding loaded gesture to + touches\n");
18.229 + //TODO: What if this fails?
18.230 + SDL_AddDollarGesture(touch,templ.path);
18.231 + }
18.232 + loaded++;
18.233 + }
18.234 + }
18.235 +
18.236 + return loaded;
18.237 +}
18.238 +
18.239 +
18.240 +float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang) {
18.241 + // SDL_FloatPoint p[DOLLARNPOINTS];
18.242 + float dist = 0;
18.243 + SDL_FloatPoint p;
18.244 + int i;
18.245 + for(i = 0; i < DOLLARNPOINTS; i++) {
18.246 + p.x = points[i].x * cos(ang) - points[i].y * sin(ang);
18.247 + p.y = points[i].x * sin(ang) + points[i].y * cos(ang);
18.248 + dist += sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
18.249 + (p.y-templ[i].y)*(p.y-templ[i].y));
18.250 + }
18.251 + return dist/DOLLARNPOINTS;
18.252 +
18.253 +}
18.254 +
18.255 +float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) {
18.256 + //------------BEGIN DOLLAR BLACKBOX----------------//
18.257 + //-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-//
18.258 + //-"http://depts.washington.edu/aimgroup/proj/dollar/"-//
18.259 + float ta = -M_PI/4;
18.260 + float tb = M_PI/4;
18.261 + float dt = M_PI/90;
18.262 + float x1 = PHI*ta + (1-PHI)*tb;
18.263 + float f1 = dollarDifference(points,templ,x1);
18.264 + float x2 = (1-PHI)*ta + PHI*tb;
18.265 + float f2 = dollarDifference(points,templ,x2);
18.266 + while(abs(ta-tb) > dt) {
18.267 + if(f1 < f2) {
18.268 + tb = x2;
18.269 + x2 = x1;
18.270 + f2 = f1;
18.271 + x1 = PHI*ta + (1-PHI)*tb;
18.272 + f1 = dollarDifference(points,templ,x1);
18.273 + }
18.274 + else {
18.275 + ta = x1;
18.276 + x1 = x2;
18.277 + f1 = f2;
18.278 + x2 = (1-PHI)*ta + PHI*tb;
18.279 + f2 = dollarDifference(points,templ,x2);
18.280 + }
18.281 + }
18.282 + /*
18.283 + if(f1 <= f2)
18.284 + printf("Min angle (x1): %f\n",x1);
18.285 + else if(f1 > f2)
18.286 + printf("Min angle (x2): %f\n",x2);
18.287 + */
18.288 + return SDL_min(f1,f2);
18.289 +}
18.290 +
18.291 +//DollarPath contains raw points, plus (possibly) the calculated length
18.292 +int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
18.293 + int i;
18.294 + //Calculate length if it hasn't already been done
18.295 + if(path.length <= 0) {
18.296 + for(i=1;i<path.numPoints;i++) {
18.297 + float dx = path.p[i ].x -
18.298 + path.p[i-1].x;
18.299 + float dy = path.p[i ].y -
18.300 + path.p[i-1].y;
18.301 + path.length += sqrt(dx*dx+dy*dy);
18.302 + }
18.303 + }
18.304 +
18.305 + //Resample
18.306 + float interval = path.length/(DOLLARNPOINTS - 1);
18.307 + float dist = interval;
18.308 +
18.309 + int numPoints = 0;
18.310 + SDL_FloatPoint centroid;
18.311 + centroid.x = 0;centroid.y = 0;
18.312 +
18.313 + //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y);
18.314 + for(i = 1;i < path.numPoints;i++) {
18.315 + float d = sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+
18.316 + (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y));
18.317 + //printf("d = %f dist = %f/%f\n",d,dist,interval);
18.318 + while(dist + d > interval) {
18.319 + points[numPoints].x = path.p[i-1].x +
18.320 + ((interval-dist)/d)*(path.p[i].x-path.p[i-1].x);
18.321 + points[numPoints].y = path.p[i-1].y +
18.322 + ((interval-dist)/d)*(path.p[i].y-path.p[i-1].y);
18.323 + centroid.x += points[numPoints].x;
18.324 + centroid.y += points[numPoints].y;
18.325 + numPoints++;
18.326 +
18.327 + dist -= interval;
18.328 + }
18.329 + dist += d;
18.330 + }
18.331 + if(numPoints < DOLLARNPOINTS-1) {
18.332 + printf("ERROR: NumPoints = %i\n",numPoints);
18.333 + return 0;
18.334 + }
18.335 + //copy the last point
18.336 + points[DOLLARNPOINTS-1] = path.p[path.numPoints-1];
18.337 + numPoints = DOLLARNPOINTS;
18.338 +
18.339 + centroid.x /= numPoints;
18.340 + centroid.y /= numPoints;
18.341 +
18.342 + //printf("Centroid (%f,%f)",centroid.x,centroid.y);
18.343 + //Rotate Points so point 0 is left of centroid and solve for the bounding box
18.344 + float xmin,xmax,ymin,ymax;
18.345 + xmin = centroid.x;
18.346 + xmax = centroid.x;
18.347 + ymin = centroid.y;
18.348 + ymax = centroid.y;
18.349 +
18.350 + float ang = atan2(centroid.y - points[0].y,
18.351 + centroid.x - points[0].x);
18.352 +
18.353 + for(i = 0;i<numPoints;i++) {
18.354 + float px = points[i].x;
18.355 + float py = points[i].y;
18.356 + points[i].x = (px - centroid.x)*cos(ang) -
18.357 + (py - centroid.y)*sin(ang) + centroid.x;
18.358 + points[i].y = (px - centroid.x)*sin(ang) +
18.359 + (py - centroid.y)*cos(ang) + centroid.y;
18.360 +
18.361 +
18.362 + if(points[i].x < xmin) xmin = points[i].x;
18.363 + if(points[i].x > xmax) xmax = points[i].x;
18.364 + if(points[i].y < ymin) ymin = points[i].y;
18.365 + if(points[i].y > ymax) ymax = points[i].y;
18.366 + }
18.367 +
18.368 + //Scale points to DOLLARSIZE, and translate to the origin
18.369 + float w = xmax-xmin;
18.370 + float h = ymax-ymin;
18.371 +
18.372 + for(i=0;i<numPoints;i++) {
18.373 + points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
18.374 + points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
18.375 + }
18.376 + return numPoints;
18.377 +}
18.378 +
18.379 +float dollarRecognize(SDL_DollarPath path,int *bestTempl,SDL_GestureTouch* touch) {
18.380 +
18.381 + SDL_FloatPoint points[DOLLARNPOINTS];
18.382 + int numPoints = dollarNormalize(path,points);
18.383 + //SDL_PrintPath(points);
18.384 + int i;
18.385 +
18.386 + int bestDiff = 10000;
18.387 + *bestTempl = -1;
18.388 + for(i = 0;i < touch->numDollarTemplates;i++) {
18.389 + int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
18.390 + if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
18.391 + }
18.392 + return bestDiff;
18.393 +}
18.394 +
18.395 +int SDL_GestureAddTouch(SDL_Touch* touch) {
18.396 + SDL_GestureTouch *gestureTouch = SDL_realloc(SDL_gestureTouch,
18.397 + (SDL_numGestureTouches + 1) *
18.398 + sizeof(SDL_GestureTouch));
18.399 +
18.400 + if(!gestureTouch) {
18.401 + SDL_OutOfMemory();
18.402 + return -1;
18.403 + }
18.404 +
18.405 + SDL_gestureTouch = gestureTouch;
18.406 +
18.407 + SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
18.408 + SDL_gestureTouch[SDL_numGestureTouches].res.y = touch->yres;
18.409 + SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
18.410 +
18.411 + SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
18.412 + SDL_gestureTouch[SDL_numGestureTouches].id = touch->id;
18.413 +
18.414 + SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0;
18.415 +
18.416 + SDL_gestureTouch[SDL_numGestureTouches].recording = SDL_FALSE;
18.417 +
18.418 + SDL_numGestureTouches++;
18.419 + return 0;
18.420 +}
18.421 +
18.422 +int SDL_GestureRemoveTouch(SDL_TouchID id) {
18.423 + int i;
18.424 + for(i = 0;i < SDL_numGestureTouches; i++) {
18.425 + if(SDL_gestureTouch[i].id == id) {
18.426 + SDL_numGestureTouches--;
18.427 + SDL_gestureTouch[i] = SDL_gestureTouch[SDL_numGestureTouches];
18.428 + return 1;
18.429 + }
18.430 + }
18.431 + return -1;
18.432 +}
18.433 +
18.434 +
18.435 +SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) {
18.436 + int i;
18.437 + for(i = 0;i < SDL_numGestureTouches; i++) {
18.438 + //printf("%i ?= %i\n",SDL_gestureTouch[i].id,id);
18.439 + if(SDL_gestureTouch[i].id == id) return &SDL_gestureTouch[i];
18.440 + }
18.441 + return NULL;
18.442 +}
18.443 +
18.444 +int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist) {
18.445 + SDL_Event event;
18.446 + event.mgesture.type = SDL_MULTIGESTURE;
18.447 + event.mgesture.touchId = touch->id;
18.448 + event.mgesture.x = touch->centroid.x;
18.449 + event.mgesture.y = touch->centroid.y;
18.450 + event.mgesture.dTheta = dTheta;
18.451 + event.mgesture.dDist = dDist;
18.452 + event.mgesture.numFingers = touch->numDownFingers;
18.453 + return SDL_PushEvent(&event) > 0;
18.454 +}
18.455 +
18.456 +int SDL_SendGestureDollar(SDL_GestureTouch* touch,
18.457 + SDL_GestureID gestureId,float error) {
18.458 + SDL_Event event;
18.459 + event.dgesture.type = SDL_DOLLARGESTURE;
18.460 + event.dgesture.touchId = touch->id;
18.461 + /*
18.462 + //TODO: Add this to give location of gesture?
18.463 + event.mgesture.x = touch->centroid.x;
18.464 + event.mgesture.y = touch->centroid.y;
18.465 + */
18.466 + event.dgesture.gestureId = gestureId;
18.467 + event.dgesture.error = error;
18.468 + //A finger came up to trigger this event.
18.469 + event.dgesture.numFingers = touch->numDownFingers + 1;
18.470 + return SDL_PushEvent(&event) > 0;
18.471 +}
18.472 +
18.473 +
18.474 +int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId) {
18.475 + SDL_Event event;
18.476 + event.dgesture.type = SDL_DOLLARRECORD;
18.477 + event.dgesture.touchId = touch->id;
18.478 + event.dgesture.gestureId = gestureId;
18.479 + return SDL_PushEvent(&event) > 0;
18.480 +}
18.481 +
18.482 +
18.483 +void SDL_GestureProcessEvent(SDL_Event* event)
18.484 +{
18.485 + if(event->type == SDL_FINGERMOTION ||
18.486 + event->type == SDL_FINGERDOWN ||
18.487 + event->type == SDL_FINGERUP) {
18.488 + SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
18.489 +
18.490 + //Shouldn't be possible
18.491 + if(inTouch == NULL) return;
18.492 +
18.493 + //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x,
18.494 + // (int)event->tfinger.y,
18.495 + // (int)inTouch->res.x,(int)inTouch->res.y);
18.496 +
18.497 +
18.498 + float x = ((float)event->tfinger.x)/(float)inTouch->res.x;
18.499 + float y = ((float)event->tfinger.y)/(float)inTouch->res.y;
18.500 +
18.501 +
18.502 + //Finger Up
18.503 + if(event->type == SDL_FINGERUP) {
18.504 + inTouch->numDownFingers--;
18.505 +
18.506 +#ifdef ENABLE_DOLLAR
18.507 + if(inTouch->recording) {
18.508 + inTouch->recording = SDL_FALSE;
18.509 + SDL_FloatPoint path[DOLLARNPOINTS];
18.510 + dollarNormalize(inTouch->dollarPath,path);
18.511 + //SDL_PrintPath(path);
18.512 + int index;
18.513 + if(recordAll) {
18.514 + index = SDL_AddDollarGesture(NULL,path);
18.515 + int i;
18.516 + for(i = 0;i < SDL_numGestureTouches; i++)
18.517 + SDL_gestureTouch[i].recording = SDL_FALSE;
18.518 + }
18.519 + else {
18.520 + index = SDL_AddDollarGesture(inTouch,path);
18.521 + }
18.522 +
18.523 + if(index >= 0) {
18.524 + SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
18.525 + }
18.526 + else {
18.527 + SDL_SendDollarRecord(inTouch,-1);
18.528 + }
18.529 + }
18.530 + else {
18.531 + int bestTempl;
18.532 + float error;
18.533 + error = dollarRecognize(inTouch->dollarPath,
18.534 + &bestTempl,inTouch);
18.535 + if(bestTempl >= 0){
18.536 + //Send Event
18.537 + unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
18.538 + SDL_SendGestureDollar(inTouch,gestureId,error);
18.539 + //printf ("%s\n",);("Dollar error: %f\n",error);
18.540 + }
18.541 + }
18.542 +#endif
18.543 + //inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];
18.544 + if(inTouch->numDownFingers > 0) {
18.545 + inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
18.546 + x)/inTouch->numDownFingers;
18.547 + inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
18.548 + y)/inTouch->numDownFingers;
18.549 + }
18.550 + }
18.551 + else if(event->type == SDL_FINGERMOTION) {
18.552 + float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x;
18.553 + float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y;
18.554 + //printf("dx,dy: (%f,%f)\n",dx,dy);
18.555 +#ifdef ENABLE_DOLLAR
18.556 + SDL_DollarPath* path = &inTouch->dollarPath;
18.557 + if(path->numPoints < MAXPATHSIZE) {
18.558 + path->p[path->numPoints].x = inTouch->centroid.x;
18.559 + path->p[path->numPoints].y = inTouch->centroid.y;
18.560 + float pathDx =
18.561 + (path->p[path->numPoints].x-path->p[path->numPoints-1].x);
18.562 + float pathDy =
18.563 + (path->p[path->numPoints].y-path->p[path->numPoints-1].y);
18.564 + path->length += sqrt(pathDx*pathDx + pathDy*pathDy);
18.565 + path->numPoints++;
18.566 + }
18.567 +#endif
18.568 + SDL_FloatPoint lastP;
18.569 + lastP.x = x - dx;
18.570 + lastP.y = y - dy;
18.571 + SDL_FloatPoint lastCentroid;
18.572 + lastCentroid = inTouch->centroid;
18.573 +
18.574 + inTouch->centroid.x += dx/inTouch->numDownFingers;
18.575 + inTouch->centroid.y += dy/inTouch->numDownFingers;
18.576 + //printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y);
18.577 + if(inTouch->numDownFingers > 1) {
18.578 + SDL_FloatPoint lv; //Vector from centroid to last x,y position
18.579 + SDL_FloatPoint v; //Vector from centroid to current x,y position
18.580 + //lv = inTouch->gestureLast[j].cv;
18.581 + lv.x = lastP.x - lastCentroid.x;
18.582 + lv.y = lastP.y - lastCentroid.y;
18.583 + float lDist = sqrt(lv.x*lv.x + lv.y*lv.y);
18.584 + //printf("lDist = %f\n",lDist);
18.585 + v.x = x - inTouch->centroid.x;
18.586 + v.y = y - inTouch->centroid.y;
18.587 + //inTouch->gestureLast[j].cv = v;
18.588 + float Dist = sqrt(v.x*v.x+v.y*v.y);
18.589 + // cos(dTheta) = (v . lv)/(|v| * |lv|)
18.590 +
18.591 + //Normalize Vectors to simplify angle calculation
18.592 + lv.x/=lDist;
18.593 + lv.y/=lDist;
18.594 + v.x/=Dist;
18.595 + v.y/=Dist;
18.596 + float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
18.597 +
18.598 + float dDist = (Dist - lDist);
18.599 + if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values
18.600 +
18.601 + //inTouch->gestureLast[j].dDist = dDist;
18.602 + //inTouch->gestureLast[j].dtheta = dtheta;
18.603 +
18.604 + //printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
18.605 + //gdtheta = gdtheta*.9 + dtheta*.1;
18.606 + //gdDist = gdDist*.9 + dDist*.1
18.607 + //knob.r += dDist/numDownFingers;
18.608 + //knob.ang += dtheta;
18.609 + //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
18.610 + //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
18.611 + SDL_SendGestureMulti(inTouch,dtheta,dDist);
18.612 + }
18.613 + else {
18.614 + //inTouch->gestureLast[j].dDist = 0;
18.615 + //inTouch->gestureLast[j].dtheta = 0;
18.616 + //inTouch->gestureLast[j].cv.x = 0;
18.617 + //inTouch->gestureLast[j].cv.y = 0;
18.618 + }
18.619 + //inTouch->gestureLast[j].f.p.x = x;
18.620 + //inTouch->gestureLast[j].f.p.y = y;
18.621 + //break;
18.622 + //pressure?
18.623 + }
18.624 +
18.625 + if(event->type == SDL_FINGERDOWN) {
18.626 +
18.627 + inTouch->numDownFingers++;
18.628 + inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
18.629 + x)/inTouch->numDownFingers;
18.630 + inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
18.631 + y)/inTouch->numDownFingers;
18.632 + //printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
18.633 + // inTouch->centroid.x,inTouch->centroid.y);
18.634 +
18.635 +#ifdef ENABLE_DOLLAR
18.636 + inTouch->dollarPath.length = 0;
18.637 + inTouch->dollarPath.p[0].x = x;
18.638 + inTouch->dollarPath.p[0].y = y;
18.639 + inTouch->dollarPath.numPoints = 1;
18.640 +#endif
18.641 + }
18.642 + }
18.643 +}
18.644 +
18.645 + /* vi: set ts=4 sw=4 expandtab: */
18.646 +
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/src/events/SDL_gesture_c.h Sun Aug 22 12:07:55 2010 -0700
19.3 @@ -0,0 +1,35 @@
19.4 +/*
19.5 + SDL - Simple DirectMedia Layer
19.6 + Copyright (C) 1997-2010 Sam Lantinga
19.7 +
19.8 + This library is free software; you can redistribute it and/or
19.9 + modify it under the terms of the GNU Lesser General Public
19.10 + License as published by the Free Software Foundation; either
19.11 + version 2.1 of the License, or (at your option) any later version.
19.12 +
19.13 + This library is distributed in the hope that it will be useful,
19.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
19.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19.16 + Lesser General Public License for more details.
19.17 +
19.18 + You should have received a copy of the GNU Lesser General Public
19.19 + License along with this library; if not, write to the Free Software
19.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19.21 +
19.22 + Sam Lantinga
19.23 + slouken@libsdl.org
19.24 +*/
19.25 +#include "SDL_config.h"
19.26 +
19.27 +#ifndef _SDL_gesture_c_h
19.28 +#define _SDL_gesture_c_h
19.29 +
19.30 +extern void SDL_GestureProcessEvent(SDL_Event* event);
19.31 +
19.32 +extern int SDL_RecordGesture(SDL_TouchID touchId);
19.33 +
19.34 +extern int SDL_GestureAddTouch(SDL_Touch* touch);
19.35 +
19.36 +#endif /* _SDL_gesture_c_h */
19.37 +
19.38 +/* vi: set ts=4 sw=4 expandtab: */
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/src/events/SDL_touch.c Sun Aug 22 12:07:55 2010 -0700
20.3 @@ -0,0 +1,555 @@
20.4 +/*
20.5 + SDL - Simple DirectMedia Layer
20.6 + Copyright (C) 1997-2010 Sam Lantinga
20.7 +
20.8 + This library is free software; you can redistribute it and/or
20.9 + modify it under the terms of the GNU Lesser General Public
20.10 + License as published by the Free Software Foundation; either
20.11 + version 2.1 of the License, or (at your option) any later version.
20.12 +
20.13 + This library is distributed in the hope that it will be useful,
20.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20.16 + Lesser General Public License for more details.
20.17 +
20.18 + You should have received a copy of the GNU Lesser General Public
20.19 + License along with this library; if not, write to the Free Software
20.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20.21 +
20.22 + Sam Lantinga
20.23 + slouken@libsdl.org
20.24 +*/
20.25 +#include "SDL_config.h"
20.26 +
20.27 +/* General touch handling code for SDL */
20.28 +
20.29 +#include "SDL_events.h"
20.30 +#include "SDL_events_c.h"
20.31 +#include "../video/SDL_sysvideo.h"
20.32 +
20.33 +#include <stdio.h>
20.34 +
20.35 +
20.36 +static int SDL_num_touch = 0;
20.37 +static SDL_Touch **SDL_touchPads = NULL;
20.38 +
20.39 +
20.40 +/* Public functions */
20.41 +int
20.42 +SDL_TouchInit(void)
20.43 +{
20.44 + return (0);
20.45 +}
20.46 +
20.47 +SDL_Touch *
20.48 +SDL_GetTouch(SDL_TouchID id)
20.49 +{
20.50 + int index = SDL_GetTouchIndexId(id);
20.51 + if (index < 0 || index >= SDL_num_touch) {
20.52 + return NULL;
20.53 + }
20.54 + return SDL_touchPads[index];
20.55 +}
20.56 +
20.57 +SDL_Touch *
20.58 +SDL_GetTouchIndex(int index)
20.59 +{
20.60 + if (index < 0 || index >= SDL_num_touch) {
20.61 + return NULL;
20.62 + }
20.63 + return SDL_touchPads[index];
20.64 +}
20.65 +
20.66 +int
20.67 +SDL_GetFingerIndexId(SDL_Touch* touch,SDL_FingerID fingerid)
20.68 +{
20.69 + int i;
20.70 + for(i = 0;i < touch->num_fingers;i++)
20.71 + if(touch->fingers[i]->id == fingerid)
20.72 + return i;
20.73 + return -1;
20.74 +}
20.75 +
20.76 +
20.77 +SDL_Finger *
20.78 +SDL_GetFinger(SDL_Touch* touch,SDL_FingerID id)
20.79 +{
20.80 + int index = SDL_GetFingerIndexId(touch,id);
20.81 + if(index < 0 || index >= touch->num_fingers)
20.82 + return NULL;
20.83 + return touch->fingers[index];
20.84 +}
20.85 +
20.86 +
20.87 +int
20.88 +SDL_GetTouchIndexId(SDL_TouchID id)
20.89 +{
20.90 + int index;
20.91 + SDL_Touch *touch;
20.92 +
20.93 + for (index = 0; index < SDL_num_touch; ++index) {
20.94 + touch = SDL_touchPads[index];
20.95 + if (touch->id == id) {
20.96 + return index;
20.97 + }
20.98 + }
20.99 + return -1;
20.100 +}
20.101 +
20.102 +int
20.103 +SDL_AddTouch(const SDL_Touch * touch, char *name)
20.104 +{
20.105 + SDL_Touch **touchPads;
20.106 + int index,length;
20.107 +
20.108 + if (SDL_GetTouchIndexId(touch->id) != -1) {
20.109 + SDL_SetError("Touch ID already in use");
20.110 + }
20.111 +
20.112 + /* Add the touch to the list of touch */
20.113 + touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
20.114 + (SDL_num_touch + 1) * sizeof(*touch));
20.115 + if (!touchPads) {
20.116 + SDL_OutOfMemory();
20.117 + return -1;
20.118 + }
20.119 +
20.120 + SDL_touchPads = touchPads;
20.121 + index = SDL_num_touch++;
20.122 +
20.123 + SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
20.124 + if (!SDL_touchPads[index]) {
20.125 + SDL_OutOfMemory();
20.126 + return -1;
20.127 + }
20.128 + *SDL_touchPads[index] = *touch;
20.129 +
20.130 + /* we're setting the touch properties */
20.131 + length = 0;
20.132 + length = SDL_strlen(name);
20.133 + SDL_touchPads[index]->focus = 0;
20.134 + SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
20.135 + SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);
20.136 +
20.137 + SDL_touchPads[index]->num_fingers = 0;
20.138 + SDL_touchPads[index]->max_fingers = 1;
20.139 + SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
20.140 + SDL_touchPads[index]->fingers[0] = NULL;
20.141 + SDL_touchPads[index]->buttonstate = 0;
20.142 + SDL_touchPads[index]->relative_mode = SDL_FALSE;
20.143 + SDL_touchPads[index]->flush_motion = SDL_FALSE;
20.144 +
20.145 + SDL_touchPads[index]->xres = (1<<(16-1));
20.146 + SDL_touchPads[index]->yres = (1<<(16-1));
20.147 + //Do I want this here? Probably
20.148 + SDL_GestureAddTouch(SDL_touchPads[index]);
20.149 +
20.150 + return index;
20.151 +}
20.152 +
20.153 +void
20.154 +SDL_DelTouch(SDL_TouchID id)
20.155 +{
20.156 + int index = SDL_GetTouchIndexId(id);
20.157 + SDL_Touch *touch = SDL_GetTouch(id);
20.158 +
20.159 + if (!touch) {
20.160 + return;
20.161 + }
20.162 +
20.163 +
20.164 + SDL_free(touch->name);
20.165 +
20.166 + if (touch->FreeTouch) {
20.167 + touch->FreeTouch(touch);
20.168 + }
20.169 + SDL_free(touch);
20.170 +
20.171 + SDL_num_touch--;
20.172 + SDL_touchPads[index] = SDL_touchPads[SDL_num_touch];
20.173 +}
20.174 +
20.175 +void
20.176 +SDL_TouchQuit(void)
20.177 +{
20.178 + int i;
20.179 +
20.180 + for (i = SDL_num_touch-1; i > 0 ; --i) {
20.181 + SDL_DelTouch(i);
20.182 + }
20.183 + SDL_num_touch = 0;
20.184 +
20.185 + if (SDL_touchPads) {
20.186 + SDL_free(SDL_touchPads);
20.187 + SDL_touchPads = NULL;
20.188 + }
20.189 +}
20.190 +
20.191 +int
20.192 +SDL_GetNumTouch(void)
20.193 +{
20.194 + return SDL_num_touch;
20.195 +}
20.196 +SDL_Window *
20.197 +SDL_GetTouchFocusWindow(SDL_TouchID id)
20.198 +{
20.199 + SDL_Touch *touch = SDL_GetTouch(id);
20.200 +
20.201 + if (!touch) {
20.202 + return 0;
20.203 + }
20.204 + return touch->focus;
20.205 +}
20.206 +
20.207 +void
20.208 +SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window)
20.209 +{
20.210 + int index = SDL_GetTouchIndexId(id);
20.211 + SDL_Touch *touch = SDL_GetTouch(id);
20.212 + int i;
20.213 + SDL_bool focus;
20.214 +
20.215 + if (!touch || (touch->focus == window)) {
20.216 + return;
20.217 + }
20.218 +
20.219 + /* See if the current window has lost focus */
20.220 + if (touch->focus) {
20.221 + focus = SDL_FALSE;
20.222 + for (i = 0; i < SDL_num_touch; ++i) {
20.223 + SDL_Touch *check;
20.224 + if (i != index) {
20.225 + check = SDL_touchPads[i];
20.226 + if (check && check->focus == touch->focus) {
20.227 + focus = SDL_TRUE;
20.228 + break;
20.229 + }
20.230 + }
20.231 + }
20.232 + if (!focus) {
20.233 + SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
20.234 + }
20.235 + }
20.236 +
20.237 + touch->focus = window;
20.238 +
20.239 + if (touch->focus) {
20.240 + focus = SDL_FALSE;
20.241 + for (i = 0; i < SDL_num_touch; ++i) {
20.242 + SDL_Touch *check;
20.243 + if (i != index) {
20.244 + check = SDL_touchPads[i];
20.245 + if (check && check->focus == touch->focus) {
20.246 + focus = SDL_TRUE;
20.247 + break;
20.248 + }
20.249 + }
20.250 + }
20.251 + if (!focus) {
20.252 + SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
20.253 + }
20.254 + }
20.255 +}
20.256 +
20.257 +int
20.258 +SDL_AddFinger(SDL_Touch* touch,SDL_Finger *finger)
20.259 +{
20.260 + int index;
20.261 + SDL_Finger **fingers;
20.262 + //printf("Adding Finger...\n");
20.263 + if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
20.264 + SDL_SetError("Finger ID already in use");
20.265 + }
20.266 +
20.267 + /* Add the touch to the list of touch */
20.268 + if(touch->num_fingers >= touch->max_fingers){
20.269 + //printf("Making room for it!\n");
20.270 + fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
20.271 + (touch->num_fingers + 1) * sizeof(SDL_Finger *));
20.272 + touch->max_fingers = touch->num_fingers+1;
20.273 + if (!fingers) {
20.274 + SDL_OutOfMemory();
20.275 + return -1;
20.276 + } else {
20.277 + touch->max_fingers = touch->num_fingers+1;
20.278 + touch->fingers = fingers;
20.279 + }
20.280 + }
20.281 +
20.282 + index = touch->num_fingers;
20.283 + //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);
20.284 +
20.285 + touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
20.286 + if (!touch->fingers[index]) {
20.287 + SDL_OutOfMemory();
20.288 + return -1;
20.289 + }
20.290 + *(touch->fingers[index]) = *finger;
20.291 + touch->num_fingers++;
20.292 +
20.293 + return index;
20.294 +}
20.295 +
20.296 +int
20.297 +SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid)
20.298 +{
20.299 + int index = SDL_GetFingerIndexId(touch,fingerid);
20.300 + SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
20.301 +
20.302 + if (!finger) {
20.303 + return -1;
20.304 + }
20.305 +
20.306 +
20.307 + SDL_free(finger);
20.308 + touch->num_fingers--;
20.309 + touch->fingers[index] = touch->fingers[touch->num_fingers];
20.310 + return 0;
20.311 +}
20.312 +
20.313 +
20.314 +int
20.315 +SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
20.316 + float xin, float yin, float pressurein)
20.317 +{
20.318 + int posted;
20.319 + SDL_Touch* touch = SDL_GetTouch(id);
20.320 +
20.321 + if(!touch) {
20.322 + return SDL_TouchNotFoundError(id);
20.323 + }
20.324 +
20.325 +
20.326 + //scale to Integer coordinates
20.327 + Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres);
20.328 + Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres);
20.329 + Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres);
20.330 +
20.331 + SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
20.332 + if(down) {
20.333 + if(finger == NULL) {
20.334 + SDL_Finger nf;
20.335 + nf.id = fingerid;
20.336 + nf.x = x;
20.337 + nf.y = y;
20.338 + nf.pressure = pressure;
20.339 + nf.xdelta = 0;
20.340 + nf.ydelta = 0;
20.341 + nf.last_x = x;
20.342 + nf.last_y = y;
20.343 + nf.last_pressure = pressure;
20.344 + nf.down = SDL_FALSE;
20.345 + if(SDL_AddFinger(touch,&nf) < 0) return 0;
20.346 + finger = SDL_GetFinger(touch,fingerid);
20.347 + }
20.348 + else if(finger->down) return 0;
20.349 + if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input
20.350 + posted = 0;
20.351 + if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
20.352 + SDL_Event event;
20.353 + event.tfinger.type = SDL_FINGERDOWN;
20.354 + event.tfinger.touchId = id;
20.355 + event.tfinger.x = x;
20.356 + event.tfinger.y = y;
20.357 + event.tfinger.pressure = pressure;
20.358 + event.tfinger.state = touch->buttonstate;
20.359 + event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
20.360 + event.tfinger.fingerId = fingerid;
20.361 + posted = (SDL_PushEvent(&event) > 0);
20.362 + }
20.363 + if(posted) finger->down = SDL_TRUE;
20.364 + return posted;
20.365 + }
20.366 + else {
20.367 + if(finger == NULL) {printf("Finger not found...\n");return 0;}
20.368 + posted = 0;
20.369 + if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
20.370 + SDL_Event event;
20.371 + event.tfinger.type = SDL_FINGERUP;
20.372 + event.tfinger.touchId = id;
20.373 + event.tfinger.state = touch->buttonstate;
20.374 + event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
20.375 + event.tfinger.fingerId = fingerid;
20.376 + //I don't trust the coordinates passed on fingerUp
20.377 + event.tfinger.x = finger->x;
20.378 + event.tfinger.y = finger->y;
20.379 + event.tfinger.dx = 0;
20.380 + event.tfinger.dy = 0;
20.381 +
20.382 + if(SDL_DelFinger(touch,fingerid) < 0) return 0;
20.383 + posted = (SDL_PushEvent(&event) > 0);
20.384 + }
20.385 + return posted;
20.386 + }
20.387 +}
20.388 +
20.389 +int
20.390 +SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative,
20.391 + float xin, float yin, float pressurein)
20.392 +{
20.393 + int index = SDL_GetTouchIndexId(id);
20.394 + SDL_Touch *touch = SDL_GetTouch(id);
20.395 + SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
20.396 + int posted;
20.397 + Sint16 xrel, yrel;
20.398 + float x_max = 0, y_max = 0;
20.399 +
20.400 + if (!touch) {
20.401 + return SDL_TouchNotFoundError(id);
20.402 + }
20.403 +
20.404 + //scale to Integer coordinates
20.405 + Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres);
20.406 + Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres);
20.407 + Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres);
20.408 + if(touch->flush_motion) {
20.409 + return 0;
20.410 + }
20.411 +
20.412 + if(finger == NULL || !finger->down) {
20.413 + return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein);
20.414 + } else {
20.415 + /* the relative motion is calculated regarding the last position */
20.416 + if (relative) {
20.417 + xrel = x;
20.418 + yrel = y;
20.419 + x = (finger->last_x + x);
20.420 + y = (finger->last_y + y);
20.421 + } else {
20.422 + if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/
20.423 + if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/
20.424 + if(pressurein < touch->pressure_min) pressure = finger->last_pressure;
20.425 + xrel = x - finger->last_x;
20.426 + yrel = y - finger->last_y;
20.427 + //printf("xrel,yrel (%i,%i)\n",(int)xrel,(int)yrel);
20.428 + }
20.429 +
20.430 + /* Drop events that don't change state */
20.431 + if (!xrel && !yrel) {
20.432 +#if 0
20.433 + printf("Touch event didn't change state - dropped!\n");
20.434 +#endif
20.435 + return 0;
20.436 + }
20.437 +
20.438 + /* Update internal touch coordinates */
20.439 +
20.440 + finger->x = x;
20.441 + finger->y = y;
20.442 +
20.443 + /*Should scale to window? Normalize? Maintain Aspect?*/
20.444 + //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
20.445 +
20.446 + /* make sure that the pointers find themselves inside the windows */
20.447 + /* only check if touch->xmax is set ! */
20.448 + /*
20.449 + if (x_max && touch->x > x_max) {
20.450 + touch->x = x_max;
20.451 + } else if (touch->x < 0) {
20.452 + touch->x = 0;
20.453 + }
20.454 +
20.455 + if (y_max && touch->y > y_max) {
20.456 + touch->y = y_max;
20.457 + } else if (touch->y < 0) {
20.458 + touch->y = 0;
20.459 + }
20.460 + */
20.461 + finger->xdelta = xrel;
20.462 + finger->ydelta = yrel;
20.463 + finger->pressure = pressure;
20.464 +
20.465 +
20.466 +
20.467 + /* Post the event, if desired */
20.468 + posted = 0;
20.469 + if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
20.470 + SDL_Event event;
20.471 + event.tfinger.type = SDL_FINGERMOTION;
20.472 + event.tfinger.touchId = id;
20.473 + event.tfinger.fingerId = fingerid;
20.474 + event.tfinger.x = x;
20.475 + event.tfinger.y = y;
20.476 + event.tfinger.dx = xrel;
20.477 + event.tfinger.dy = yrel;
20.478 +
20.479 + event.tfinger.pressure = pressure;
20.480 + event.tfinger.state = touch->buttonstate;
20.481 + event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
20.482 + posted = (SDL_PushEvent(&event) > 0);
20.483 + }
20.484 + finger->last_x = finger->x;
20.485 + finger->last_y = finger->y;
20.486 + finger->last_pressure = finger->pressure;
20.487 + return posted;
20.488 + }
20.489 +}
20.490 +int
20.491 +SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button)
20.492 +{
20.493 + SDL_Touch *touch = SDL_GetTouch(id);
20.494 + int posted;
20.495 + Uint32 type;
20.496 +
20.497 +
20.498 + if (!touch) {
20.499 + return SDL_TouchNotFoundError(id);
20.500 + }
20.501 +
20.502 + /* Figure out which event to perform */
20.503 + switch (state) {
20.504 + case SDL_PRESSED:
20.505 + if (touch->buttonstate & SDL_BUTTON(button)) {
20.506 + /* Ignore this event, no state change */
20.507 + return 0;
20.508 + }
20.509 + type = SDL_TOUCHBUTTONDOWN;
20.510 + touch->buttonstate |= SDL_BUTTON(button);
20.511 + break;
20.512 + case SDL_RELEASED:
20.513 + if (!(touch->buttonstate & SDL_BUTTON(button))) {
20.514 + /* Ignore this event, no state change */
20.515 + return 0;
20.516 + }
20.517 + type = SDL_TOUCHBUTTONUP;
20.518 + touch->buttonstate &= ~SDL_BUTTON(button);
20.519 + break;
20.520 + default:
20.521 + /* Invalid state -- bail */
20.522 + return 0;
20.523 + }
20.524 +
20.525 + /* Post the event, if desired */
20.526 + posted = 0;
20.527 + if (SDL_GetEventState(type) == SDL_ENABLE) {
20.528 + SDL_Event event;
20.529 + event.type = type;
20.530 + event.tbutton.touchId = touch->id;
20.531 + event.tbutton.state = state;
20.532 + event.tbutton.button = button;
20.533 + event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
20.534 + posted = (SDL_PushEvent(&event) > 0);
20.535 + }
20.536 + return posted;
20.537 +}
20.538 +
20.539 +char *
20.540 +SDL_GetTouchName(SDL_TouchID id)
20.541 +{
20.542 + SDL_Touch *touch = SDL_GetTouch(id);
20.543 + if (!touch) {
20.544 + return NULL;
20.545 + }
20.546 + return touch->name;
20.547 +}
20.548 +
20.549 +int SDL_TouchNotFoundError(SDL_TouchID id) {
20.550 + printf("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id);
20.551 + printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch);
20.552 + int i;
20.553 + for(i=0;i < SDL_num_touch;i++) {
20.554 + printf("ERROR: %li\n",SDL_touchPads[i]->id);
20.555 + }
20.556 + return 0;
20.557 +}
20.558 +/* vi: set ts=4 sw=4 expandtab: */
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/src/events/SDL_touch_c.h Sun Aug 22 12:07:55 2010 -0700
21.3 @@ -0,0 +1,79 @@
21.4 +/*
21.5 + SDL - Simple DirectMedia Layer
21.6 + Copyright (C) 1997-2010 Sam Lantinga
21.7 +
21.8 + This library is free software; you can redistribute it and/or
21.9 + modify it under the terms of the GNU Lesser General Public
21.10 + License as published by the Free Software Foundation; either
21.11 + version 2.1 of the License, or (at your option) any later version.
21.12 +
21.13 + This library is distributed in the hope that it will be useful,
21.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21.16 + Lesser General Public License for more details.
21.17 +
21.18 + You should have received a copy of the GNU Lesser General Public
21.19 + License along with this library; if not, write to the Free Software
21.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21.21 +
21.22 + Sam Lantinga
21.23 + slouken@libsdl.org
21.24 +*/
21.25 +#include "SDL_config.h"
21.26 +#include "../../include/SDL_touch.h"
21.27 +
21.28 +#ifndef _SDL_touch_c_h
21.29 +#define _SDL_touch_c_h
21.30 +
21.31 +
21.32 +
21.33 +/* Initialize the touch subsystem */
21.34 +extern int SDL_TouchInit(void);
21.35 +
21.36 +/*Get the touch at an index */
21.37 +extern SDL_Touch *SDL_GetTouchIndex(int index);
21.38 +
21.39 +/* Get the touch with id = id */
21.40 +extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
21.41 +
21.42 +/*Get the finger at an index */
21.43 +extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index);
21.44 +
21.45 +/* Get the finger with id = id */
21.46 +extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,SDL_FingerID id);
21.47 +
21.48 +
21.49 +/* Add a touch, possibly reattaching at a particular index (or -1),
21.50 + returning the index of the touch, or -1 if there was an error. */
21.51 +extern int SDL_AddTouch(const SDL_Touch * touch, char *name);
21.52 +
21.53 +
21.54 +/* Remove a touch at an index, clearing the slot for later */
21.55 +extern void SDL_DelTouch(SDL_TouchID id);
21.56 +
21.57 +/* Set the touch focus window */
21.58 +extern void SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window);
21.59 +
21.60 +/* Send a touch motion event for a touch */
21.61 +extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
21.62 + int relative, float x, float y, float z);
21.63 +
21.64 +/* Send a touch down/up event for a touch */
21.65 +extern int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid,
21.66 + SDL_bool down, float x, float y, float pressure);
21.67 +
21.68 +/* Send a touch button event for a touch */
21.69 +extern int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button);
21.70 +
21.71 +/* Shutdown the touch subsystem */
21.72 +extern void SDL_TouchQuit(void);
21.73 +
21.74 +/* Get the index of a touch device */
21.75 +extern int SDL_GetTouchIndexId(SDL_TouchID id);
21.76 +
21.77 +/* Print a debug message for a nonexistent touch */
21.78 +extern int SDL_TouchNotFoundError(SDL_TouchID id);
21.79 +
21.80 +#endif /* _SDL_touch_c_h */
21.81 +
21.82 +/* vi: set ts=4 sw=4 expandtab: */
22.1 --- a/src/video/cocoa/SDL_cocoaevents.m Sun Aug 22 11:56:07 2010 -0700
22.2 +++ b/src/video/cocoa/SDL_cocoaevents.m Sun Aug 22 12:07:55 2010 -0700
22.3 @@ -192,6 +192,9 @@
22.4 if ( event == nil ) {
22.5 break;
22.6 }
22.7 +
22.8 + //printf("Type: %i, Subtype: %i\n",[event type],[event subtype]);
22.9 +
22.10 switch ([event type]) {
22.11 case NSLeftMouseDown:
22.12 case NSOtherMouseDown:
22.13 @@ -203,6 +206,7 @@
22.14 case NSRightMouseDragged:
22.15 case NSOtherMouseDragged: /* usually middle mouse dragged */
22.16 case NSMouseMoved:
22.17 + printf("Mouse Type: %i, Subtype: %i\n",[event type],[event subtype]);
22.18 Cocoa_HandleMouseEvent(_this, event);
22.19 /* Pass through to NSApp to make sure everything stays in sync */
22.20 [NSApp sendEvent:event];
22.21 @@ -217,6 +221,8 @@
22.22 if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged)
22.23 [NSApp sendEvent: event];
22.24 break;
22.25 + case NSTabletPoint:
22.26 + printf("Tablet Event Received\n");
22.27 default:
22.28 [NSApp sendEvent:event];
22.29 break;
24.1 --- a/src/video/cocoa/SDL_cocoawindow.h Sun Aug 22 11:56:07 2010 -0700
24.2 +++ b/src/video/cocoa/SDL_cocoawindow.h Sun Aug 22 12:07:55 2010 -0700
24.3 @@ -64,6 +64,20 @@
24.4 -(void) rightMouseDragged:(NSEvent *) theEvent;
24.5 -(void) otherMouseDragged:(NSEvent *) theEvent;
24.6 -(void) scrollWheel:(NSEvent *) theEvent;
24.7 +-(void) touchesBeganWithEvent:(NSEvent *) theEvent;
24.8 +-(void) touchesMovedWithEvent:(NSEvent *) theEvent;
24.9 +-(void) touchesEndedWithEvent:(NSEvent *) theEvent;
24.10 +-(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
24.11 +
24.12 +/* Touch event handling */
24.13 +typedef enum {
24.14 + COCOA_TOUCH_DOWN,
24.15 + COCOA_TOUCH_UP,
24.16 + COCOA_TOUCH_MOVE,
24.17 + COCOA_TOUCH_CANCELLED
24.18 +} cocoaTouchType;
24.19 +-(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event;
24.20 +
24.21 @end
24.22 /* *INDENT-ON* */
24.23
25.1 --- a/src/video/cocoa/SDL_cocoawindow.m Sun Aug 22 11:56:07 2010 -0700
25.2 +++ b/src/video/cocoa/SDL_cocoawindow.m Sun Aug 22 12:07:55 2010 -0700
25.3 @@ -25,8 +25,8 @@
25.4 #include "../SDL_sysvideo.h"
25.5 #include "../../events/SDL_keyboard_c.h"
25.6 #include "../../events/SDL_mouse_c.h"
25.7 +#include "../../events/SDL_touch_c.h"
25.8 #include "../../events/SDL_windowevents_c.h"
25.9 -
25.10 #include "SDL_cocoavideo.h"
25.11
25.12 static __inline__ void ConvertNSRect(NSRect *r)
25.13 @@ -60,6 +60,7 @@
25.14 [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
25.15
25.16 [_data->nswindow setAcceptsMouseMovedEvents:YES];
25.17 + [[_data->nswindow contentView] setAcceptsTouchEvents:YES];
25.18 }
25.19
25.20 - (void)close
25.21 @@ -268,6 +269,91 @@
25.22 SDL_SendMouseWheel(_data->window, (int)x, (int)y);
25.23 }
25.24
25.25 +- (void)touchesBeganWithEvent:(NSEvent *) theEvent
25.26 +{
25.27 + [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
25.28 +}
25.29 +
25.30 +- (void)touchesMovedWithEvent:(NSEvent *) theEvent
25.31 +{
25.32 + [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
25.33 +}
25.34 +
25.35 +- (void)touchesEndedWithEvent:(NSEvent *) theEvent
25.36 +{
25.37 + [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
25.38 +}
25.39 +
25.40 +- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
25.41 +{
25.42 + [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
25.43 +}
25.44 +
25.45 +- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
25.46 +{
25.47 + NSSet *touches = 0;
25.48 + NSEnumerator *enumerator;
25.49 + NSTouch *touch;
25.50 +
25.51 + switch (type) {
25.52 + case COCOA_TOUCH_DOWN:
25.53 + touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
25.54 + break;
25.55 + case COCOA_TOUCH_UP:
25.56 + case COCOA_TOUCH_CANCELLED:
25.57 + touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
25.58 + break;
25.59 + case COCOA_TOUCH_MOVE:
25.60 + touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
25.61 + break;
25.62 + }
25.63 +
25.64 + enumerator = [touches objectEnumerator];
25.65 + touch = (NSTouch*)[enumerator nextObject];
25.66 + while (touch) {
25.67 + SDL_TouchID touchId = (SDL_TouchID)[touch device];
25.68 + if (!SDL_GetTouch(touchId)) {
25.69 + SDL_Touch touch;
25.70 +
25.71 + touch.id = touchId;
25.72 + touch.x_min = 0;
25.73 + touch.x_max = 1;
25.74 + touch.native_xres = touch.x_max - touch.x_min;
25.75 + touch.y_min = 0;
25.76 + touch.y_max = 1;
25.77 + touch.native_yres = touch.y_max - touch.y_min;
25.78 + touch.pressure_min = 0;
25.79 + touch.pressure_max = 1;
25.80 + touch.native_pressureres = touch.pressure_max - touch.pressure_min;
25.81 +
25.82 + if (SDL_AddTouch(&touch, "") < 0) {
25.83 + return;
25.84 + }
25.85 + }
25.86 +
25.87 + SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
25.88 + float x = [touch normalizedPosition].x;
25.89 + float y = [touch normalizedPosition].y;
25.90 + /* Make the origin the upper left instead of the lower left */
25.91 + y = 1.0f - y;
25.92 +
25.93 + switch (type) {
25.94 + case COCOA_TOUCH_DOWN:
25.95 + SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);
25.96 + break;
25.97 + case COCOA_TOUCH_UP:
25.98 + case COCOA_TOUCH_CANCELLED:
25.99 + SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1);
25.100 + break;
25.101 + case COCOA_TOUCH_MOVE:
25.102 + SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1);
25.103 + break;
25.104 + }
25.105 +
25.106 + touch = (NSTouch*)[enumerator nextObject];
25.107 + }
25.108 +}
25.109 +
25.110 @end
25.111
25.112 @interface SDLWindow : NSWindow
26.1 --- a/src/video/uikit/SDL_uikitview.h Sun Aug 22 11:56:07 2010 -0700
26.2 +++ b/src/video/uikit/SDL_uikitview.h Sun Aug 22 12:07:55 2010 -0700
26.3 @@ -13,8 +13,7 @@
26.4 Lesser General Public License for more details.
26.5
26.6 You should have received a copy of the GNU Lesser General Public
26.7 - License along with this library; if not, write to the Free Software
26.8 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26.9 + License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26.10
26.11 Sam Lantinga
26.12 slouken@libsdl.org
26.13 @@ -24,10 +23,11 @@
26.14 #include "SDL_stdinc.h"
26.15 #include "SDL_events.h"
26.16
26.17 -#if SDL_IPHONE_MULTIPLE_MICE
26.18 +#define IPHONE_TOUCH_EFFICIENT_DANGEROUS
26.19 +#define FIXED_MULTITOUCH
26.20 +
26.21 +#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
26.22 #define MAX_SIMULTANEOUS_TOUCHES 5
26.23 -#else
26.24 -#define MAX_SIMULTANEOUS_TOUCHES 1
26.25 #endif
26.26
26.27 /* *INDENT-OFF* */
26.28 @@ -37,8 +37,11 @@
26.29 @interface SDL_uikitview : UIView {
26.30 #endif
26.31
26.32 -#if FIXME_MULTITOUCH
26.33 - SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
26.34 +#ifdef FIXED_MULTITOUCH
26.35 + long touchId;
26.36 +#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
26.37 + UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
26.38 +#endif
26.39 #endif
26.40
26.41 #if SDL_IPHONE_KEYBOARD
27.1 --- a/src/video/uikit/SDL_uikitview.m Sun Aug 22 11:56:07 2010 -0700
27.2 +++ b/src/video/uikit/SDL_uikitview.m Sun Aug 22 12:07:55 2010 -0700
27.3 @@ -24,6 +24,7 @@
27.4
27.5 #include "../../events/SDL_keyboard_c.h"
27.6 #include "../../events/SDL_mouse_c.h"
27.7 +#include "../../events/SDL_touch_c.h"
27.8
27.9 #if SDL_IPHONE_KEYBOARD
27.10 #import "keyinfotable.h"
27.11 @@ -48,16 +49,27 @@
27.12 [self initializeKeyboard];
27.13 #endif
27.14
27.15 -#if FIXME_MULTITOUCH
27.16 - int i;
27.17 - for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
27.18 - mice[i].id = i;
27.19 - mice[i].driverdata = NULL;
27.20 - SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
27.21 - }
27.22 - self.multipleTouchEnabled = YES;
27.23 +#ifdef FIXED_MULTITOUCH
27.24 + SDL_Touch touch;
27.25 + touch.id = 0; //TODO: Should be -1?
27.26 +
27.27 + //touch.driverdata = SDL_malloc(sizeof(EventTouchData));
27.28 + //EventTouchData* data = (EventTouchData*)(touch.driverdata);
27.29 +
27.30 + touch.x_min = 0;
27.31 + touch.x_max = frame.size.width;
27.32 + touch.native_xres = touch.x_max - touch.x_min;
27.33 + touch.y_min = 0;
27.34 + touch.y_max = frame.size.height;
27.35 + touch.native_yres = touch.y_max - touch.y_min;
27.36 + touch.pressure_min = 0;
27.37 + touch.pressure_max = 1;
27.38 + touch.native_pressureres = touch.pressure_max - touch.pressure_min;
27.39 +
27.40 +
27.41 + touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
27.42 #endif
27.43 -
27.44 +
27.45 return self;
27.46
27.47 }
27.48 @@ -67,48 +79,8 @@
27.49 NSEnumerator *enumerator = [touches objectEnumerator];
27.50 UITouch *touch = (UITouch*)[enumerator nextObject];
27.51
27.52 -#if FIXME_MULTITOUCH
27.53 - /* associate touches with mice, so long as we have slots */
27.54 - int i;
27.55 - int found = 0;
27.56 - for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) {
27.57 + //NSLog("Click");
27.58
27.59 - /* check if this mouse is already tracking a touch */
27.60 - if (mice[i].driverdata != NULL) {
27.61 - continue;
27.62 - }
27.63 - /*
27.64 - mouse not associated with anything right now,
27.65 - associate the touch with this mouse
27.66 - */
27.67 - found = 1;
27.68 -
27.69 - /* save old mouse so we can switch back */
27.70 - int oldMouse = SDL_SelectMouse(-1);
27.71 -
27.72 - /* select this slot's mouse */
27.73 - SDL_SelectMouse(i);
27.74 - CGPoint locationInView = [touch locationInView: self];
27.75 -
27.76 - /* set driver data to touch object, we'll use touch object later */
27.77 - mice[i].driverdata = [touch retain];
27.78 -
27.79 - /* send moved event */
27.80 - SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
27.81 -
27.82 - /* send mouse down event */
27.83 - SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
27.84 -
27.85 - /* re-calibrate relative mouse motion */
27.86 - SDL_GetRelativeMouseState(i, NULL, NULL);
27.87 -
27.88 - /* switch back to our old mouse */
27.89 - SDL_SelectMouse(oldMouse);
27.90 -
27.91 - /* grab next touch */
27.92 - touch = (UITouch*)[enumerator nextObject];
27.93 - }
27.94 -#else
27.95 if (touch) {
27.96 CGPoint locationInView = [touch locationInView: self];
27.97
27.98 @@ -118,6 +90,37 @@
27.99 /* send mouse down event */
27.100 SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
27.101 }
27.102 +
27.103 +#ifdef FIXED_MULTITOUCH
27.104 + while(touch) {
27.105 + CGPoint locationInView = [touch locationInView: self];
27.106 +
27.107 +
27.108 +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
27.109 + //FIXME: TODO: Using touch as the fingerId is potentially dangerous
27.110 + //It is also much more efficient than storing the UITouch pointer
27.111 + //and comparing it to the incoming event.
27.112 + SDL_SendFingerDown(touchId,(long)touch,
27.113 + SDL_TRUE,locationInView.x,locationInView.y,
27.114 + 1);
27.115 +#else
27.116 + int i;
27.117 + for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
27.118 + if(finger[i] == NULL) {
27.119 + finger[i] = touch;
27.120 + SDL_SendFingerDown(touchId,i,
27.121 + SDL_TRUE,locationInView.x,locationInView.y,
27.122 + 1);
27.123 + break;
27.124 + }
27.125 + }
27.126 +#endif
27.127 +
27.128 +
27.129 +
27.130 +
27.131 + touch = (UITouch*)[enumerator nextObject];
27.132 + }
27.133 #endif
27.134 }
27.135
27.136 @@ -126,30 +129,34 @@
27.137 NSEnumerator *enumerator = [touches objectEnumerator];
27.138 UITouch *touch = (UITouch*)[enumerator nextObject];
27.139
27.140 -#if FIXME_MULTITOUCH
27.141 - while(touch) {
27.142 - /* search for the mouse slot associated with this touch */
27.143 - int i, found = NO;
27.144 - for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
27.145 - if (mice[i].driverdata == touch) {
27.146 - /* found the mouse associate with the touch */
27.147 - [(UITouch*)(mice[i].driverdata) release];
27.148 - mice[i].driverdata = NULL;
27.149 - /* send mouse up */
27.150 - SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
27.151 - /* discontinue search for this touch */
27.152 - found = YES;
27.153 - }
27.154 - }
27.155 -
27.156 - /* grab next touch */
27.157 - touch = (UITouch*)[enumerator nextObject];
27.158 - }
27.159 -#else
27.160 if (touch) {
27.161 /* send mouse up */
27.162 SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
27.163 }
27.164 +
27.165 +#ifdef FIXED_MULTITOUCH
27.166 + while(touch) {
27.167 + CGPoint locationInView = [touch locationInView: self];
27.168 +
27.169 +
27.170 +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
27.171 + SDL_SendFingerDown(touchId,(long)touch,
27.172 + SDL_FALSE,locationInView.x,locationInView.y,
27.173 + 1);
27.174 +#else
27.175 + int i;
27.176 + for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
27.177 + if(finger[i] == touch) {
27.178 + SDL_SendFingerDown(touchId,i,
27.179 + SDL_FALSE,locationInView.x,locationInView.y,
27.180 + 1);
27.181 + break;
27.182 + }
27.183 + }
27.184 +#endif
27.185 +
27.186 + touch = (UITouch*)[enumerator nextObject];
27.187 + }
27.188 #endif
27.189 }
27.190
27.191 @@ -167,31 +174,36 @@
27.192 NSEnumerator *enumerator = [touches objectEnumerator];
27.193 UITouch *touch = (UITouch*)[enumerator nextObject];
27.194
27.195 -#if FIXME_MULTITOUCH
27.196 - while(touch) {
27.197 - /* try to find the mouse associated with this touch */
27.198 - int i, found = NO;
27.199 - for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
27.200 - if (mice[i].driverdata == touch) {
27.201 - /* found proper mouse */
27.202 - CGPoint locationInView = [touch locationInView: self];
27.203 - /* send moved event */
27.204 - SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
27.205 - /* discontinue search */
27.206 - found = YES;
27.207 - }
27.208 - }
27.209 -
27.210 - /* grab next touch */
27.211 - touch = (UITouch*)[enumerator nextObject];
27.212 - }
27.213 -#else
27.214 if (touch) {
27.215 CGPoint locationInView = [touch locationInView: self];
27.216
27.217 /* send moved event */
27.218 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
27.219 }
27.220 +
27.221 +#ifdef FIXED_MULTITOUCH
27.222 + while(touch) {
27.223 + CGPoint locationInView = [touch locationInView: self];
27.224 +
27.225 +
27.226 +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
27.227 + SDL_SendTouchMotion(touchId,(long)touch,
27.228 + SDL_FALSE,locationInView.x,locationInView.y,
27.229 + 1);
27.230 +#else
27.231 + int i;
27.232 + for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
27.233 + if(finger[i] == touch) {
27.234 + SDL_SendTouchMotion(touchId,i,
27.235 + SDL_FALSE,locationInView.x,locationInView.y,
27.236 + 1);
27.237 + break;
27.238 + }
27.239 + }
27.240 +#endif
27.241 +
27.242 + touch = (UITouch*)[enumerator nextObject];
27.243 + }
27.244 #endif
27.245 }
27.246
28.1 --- a/src/video/win32/SDL_win32events.c Sun Aug 22 11:56:07 2010 -0700
28.2 +++ b/src/video/win32/SDL_win32events.c Sun Aug 22 12:07:55 2010 -0700
28.3 @@ -20,9 +20,9 @@
28.4 slouken@libsdl.org
28.5 */
28.6
28.7 -#if (_WIN32_WINNT < 0x0501)
28.8 +#if (_WIN32_WINNT < 0x601)
28.9 #undef _WIN32_WINNT
28.10 -#define _WIN32_WINNT 0x0501
28.11 +#define _WIN32_WINNT 0x601
28.12 #endif
28.13
28.14 #include "SDL_config.h"
28.15 @@ -32,11 +32,14 @@
28.16 #include "SDL_vkeys.h"
28.17 #include "../../events/SDL_events_c.h"
28.18
28.19 -/*#define WMMSG_DEBUG*/
28.20 +
28.21 +
28.22 +#define WMMSG_DEBUG
28.23 #ifdef WMMSG_DEBUG
28.24 -#include <stdio.h>
28.25 +#include <stdio.h>
28.26 #include "wmmsg.h"
28.27 #endif
28.28 +//#include <stdio.h>
28.29
28.30 /* Masks for processing the windows KEYDOWN and KEYUP messages */
28.31 #define REPEATED_KEYMASK (1<<30)
28.32 @@ -121,9 +124,10 @@
28.33 if (!data) {
28.34 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
28.35 }
28.36 +
28.37 #ifdef WMMSG_DEBUG
28.38 - {
28.39 - FILE *log = fopen("wmmsg.txt", "a");
28.40 + {
28.41 + FILE *log = fopen("wmmsg.txt", "a");
28.42 fprintf(log, "Received windows message: %p ", hwnd);
28.43 if (msg > MAX_WMMSG) {
28.44 fprintf(log, "%d", msg);
28.45 @@ -509,7 +513,39 @@
28.46 }
28.47 returnCode = 0;
28.48 break;
28.49 - }
28.50 + case WM_TOUCH:
28.51 + {
28.52 + //printf("Got Touch Event!\n");
28.53 +
28.54 + FILE *log = fopen("wmmsg.txt", "a");
28.55 + fprintf(log, "Received Touch Message: %p ", hwnd);
28.56 + if (msg > MAX_WMMSG) {
28.57 + fprintf(log, "%d", msg);
28.58 + } else {
28.59 + fprintf(log, "%s", wmtab[msg]);
28.60 + }
28.61 + fprintf(log, "WM_TOUCH = %d -- 0x%X, 0x%X\n",msg, wParam, lParam);
28.62 + fclose(log);
28.63 +
28.64 + }
28.65 + break;
28.66 + case WM_GESTURE:
28.67 + {
28.68 + //printf("Got Touch Event!\n");
28.69 +
28.70 + FILE *log = fopen("wmmsg.txt", "a");
28.71 + fprintf(log, "Received Gesture Message: %p ", hwnd);
28.72 + if (msg > MAX_WMMSG) {
28.73 + fprintf(log, "%d", msg);
28.74 + } else {
28.75 + fprintf(log, "%s", wmtab[msg]);
28.76 + }
28.77 + fprintf(log, "WM_GESTURE = %d -- 0x%X, 0x%X\n",msg, wParam, lParam);
28.78 + fclose(log);
28.79 +
28.80 + }
28.81 + break;
28.82 + }
28.83
28.84 /* If there's a window proc, assume it's going to handle messages */
28.85 if (data->wndproc) {
29.1 --- a/src/video/win32/SDL_win32video.h Sun Aug 22 11:56:07 2010 -0700
29.2 +++ b/src/video/win32/SDL_win32video.h Sun Aug 22 12:07:55 2010 -0700
29.3 @@ -32,7 +32,14 @@
29.4 #define UNICODE
29.5 #endif
29.6 #undef WINVER
29.7 -#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */
29.8 +//#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */
29.9 +#define WINVER 0x601 /* Need 0x600 (_WIN32_WINNT_WIN7) for WM_Touch */
29.10 +#if (_WIN32_WINNT < 0x601)
29.11 +#undef _WIN32_WINNT
29.12 +#define _WIN32_WINNT 0x601
29.13 +#endif
29.14 +
29.15 +
29.16 #include <windows.h>
29.17
29.18 #if SDL_VIDEO_RENDER_D3D
30.1 --- a/src/video/win32/SDL_win32window.c Sun Aug 22 11:56:07 2010 -0700
30.2 +++ b/src/video/win32/SDL_win32window.c Sun Aug 22 12:07:55 2010 -0700
30.3 @@ -218,6 +218,7 @@
30.4 WIN_SetError("Couldn't create window");
30.5 return -1;
30.6 }
30.7 + //RegisterTouchWindow(hwnd, 0);
30.8
30.9 WIN_PumpEvents(_this);
30.10
31.1 --- a/src/video/win32/wmmsg.h Sun Aug 22 11:56:07 2010 -0700
31.2 +++ b/src/video/win32/wmmsg.h Sun Aug 22 12:07:55 2010 -0700
31.3 @@ -283,7 +283,7 @@
31.4 "WM_INITMENU",
31.5 "WM_INITMENUPOPUP",
31.6 "UNKNOWN (280)",
31.7 - "UNKNOWN (281)",
31.8 + "WM_GESTURE",
31.9 "UNKNOWN (282)",
31.10 "UNKNOWN (283)",
31.11 "UNKNOWN (284)",
31.12 @@ -578,7 +578,7 @@
31.13 "UNKNOWN (573)",
31.14 "UNKNOWN (574)",
31.15 "UNKNOWN (575)",
31.16 - "UNKNOWN (576)",
31.17 + "WM_TOUCH",
31.18 "UNKNOWN (577)",
31.19 "UNKNOWN (578)",
31.20 "UNKNOWN (579)",
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
32.2 +++ b/src/video/x11/SDL_eventtouch.c Sun Aug 22 12:07:55 2010 -0700
32.3 @@ -0,0 +1,128 @@
32.4 +/*
32.5 + SDL - Simple DirectMedia Layer
32.6 + Copyright (C) 1997-2010 Sam Lantinga
32.7 +
32.8 + This library is free software; you can redistribute it and/or
32.9 + modify it under the terms of the GNU Lesser General Public
32.10 + License as published by the Free Software Foundation; either
32.11 + version 2.1 of the License, or (at your option) any later version.
32.12 +
32.13 + This library is distributed in the hope that it will be useful,
32.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
32.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32.16 + Lesser General Public License for more details.
32.17 +
32.18 + You should have received a copy of the GNU Lesser General Public
32.19 + License along with this library; if not, write to the Free Software
32.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32.21 +
32.22 + Sam Lantinga
32.23 + slouken@libsdl.org
32.24 +*/
32.25 +#include "SDL_config.h"
32.26 +#include "SDL_x11video.h"
32.27 +#include "SDL_eventtouch.h"
32.28 +#include "../../events/SDL_touch_c.h"
32.29 +
32.30 +
32.31 +#ifdef SDL_INPUT_LINUXEV
32.32 +#include <linux/input.h>
32.33 +#include <fcntl.h>
32.34 +#endif
32.35 +
32.36 +void
32.37 +X11_InitTouch(_THIS)
32.38 +{
32.39 +#ifdef SDL_INPUT_LINUXEV
32.40 + printf("Initializing touch...\n");
32.41 +
32.42 + FILE *fd;
32.43 + fd = fopen("/proc/bus/input/devices","r");
32.44 +
32.45 + char c;
32.46 + int i = 0;
32.47 + char line[256];
32.48 + char tstr[256];
32.49 + int vendor = -1,product = -1,event = -1;
32.50 + while(!feof(fd)) {
32.51 + if(fgets(line,256,fd) <=0) continue;
32.52 + //printf("%s",line);
32.53 + if(line[0] == '\n') {
32.54 + if(vendor == 1386){
32.55 + printf("Wacom... Assuming it is a touch device\n");
32.56 + sprintf(tstr,"/dev/input/event%i",event);
32.57 + printf("At location: %s\n",tstr);
32.58 +
32.59 + SDL_Touch touch;
32.60 + touch.pressure_max = 0;
32.61 + touch.pressure_min = 0;
32.62 + touch.id = event;
32.63 +
32.64 +
32.65 + touch.driverdata = SDL_malloc(sizeof(EventTouchData));
32.66 + EventTouchData* data = (EventTouchData*)(touch.driverdata);
32.67 +
32.68 + data->x = -1;
32.69 + data->y = -1;
32.70 + data->pressure = -1;
32.71 + data->finger = 0;
32.72 + data->up = SDL_FALSE;
32.73 +
32.74 +
32.75 + printf("Opening device...\n");
32.76 + //printf("New Touch - DataPtr: %i\n",data);
32.77 + data->eventStream = open(tstr,
32.78 + O_RDONLY | O_NONBLOCK);
32.79 + ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
32.80 + printf ("Reading From : %s\n", tstr);
32.81 +
32.82 +
32.83 +
32.84 + int abs[5];
32.85 + ioctl(data->eventStream,EVIOCGABS(0),abs);
32.86 + touch.x_min = abs[1];
32.87 + touch.x_max = abs[2];
32.88 + touch.native_xres = touch.x_max - touch.x_min;
32.89 + ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
32.90 + touch.y_min = abs[1];
32.91 + touch.y_max = abs[2];
32.92 + touch.native_yres = touch.y_max - touch.y_min;
32.93 + ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
32.94 + touch.pressure_min = abs[1];
32.95 + touch.pressure_max = abs[2];
32.96 + touch.native_pressureres = touch.pressure_max - touch.pressure_min;
32.97 +
32.98 + SDL_AddTouch(&touch, tstr);
32.99 + }
32.100 + vendor = -1;
32.101 + product = -1;
32.102 + event = -1;
32.103 + }
32.104 + else if(line[0] == 'I') {
32.105 + i = 1;
32.106 + while(line[i]) {
32.107 + sscanf(&line[i],"Vendor=%x",&vendor);
32.108 + sscanf(&line[i],"Product=%x",&product);
32.109 + i++;
32.110 + }
32.111 + }
32.112 + else if(line[0] == 'H') {
32.113 + i = 1;
32.114 + while(line[i]) {
32.115 + sscanf(&line[i],"event%d",&event);
32.116 + i++;
32.117 + }
32.118 + }
32.119 + }
32.120 +
32.121 + close(fd);
32.122 +#endif
32.123 +}
32.124 +
32.125 +void
32.126 +X11_QuitTouch(_THIS)
32.127 +{
32.128 + SDL_TouchQuit();
32.129 +}
32.130 +
32.131 +/* vi: set ts=4 sw=4 expandtab: */
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/src/video/x11/SDL_eventtouch.h Sun Aug 22 12:07:55 2010 -0700
33.3 @@ -0,0 +1,43 @@
33.4 +/*
33.5 + SDL - Simple DirectMedia Layer
33.6 + Copyright (C) 1997-2010 Sam Lantinga
33.7 +
33.8 + This library is free software; you can redistribute it and/or
33.9 + modify it under the terms of the GNU Lesser General Public
33.10 + License as published by the Free Software Foundation; either
33.11 + version 2.1 of the License, or (at your option) any later version.
33.12 +
33.13 + This library is distributed in the hope that it will be useful,
33.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
33.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33.16 + Lesser General Public License for more details.
33.17 +
33.18 + You should have received a copy of the GNU Lesser General Public
33.19 + License along with this library; if not, write to the Free Software
33.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33.21 +
33.22 + Sam Lantinga
33.23 + slouken@libsdl.org
33.24 +*/
33.25 +#include "SDL_config.h"
33.26 +
33.27 +#ifndef _SDL_eventtouch_h
33.28 +#define _SDL_eventtouch_h
33.29 +
33.30 +
33.31 +//What should this be?
33.32 +#if SDL_VIDEO_DRIVER_X11_XINPUT
33.33 +typedef struct EventTouchData
33.34 +{
33.35 + int x,y,pressure,finger; //Temporary Variables until sync
33.36 + int eventStream;
33.37 + SDL_bool up;
33.38 +} EventTouchData;
33.39 +#endif
33.40 +
33.41 +extern void X11_InitTouch(_THIS);
33.42 +extern void X11_QuitTouch(_THIS);
33.43 +
33.44 +#endif /* _SDL_eventtouch_h */
33.45 +
33.46 +/* vi: set ts=4 sw=4 expandtab: */
34.1 --- a/src/video/x11/SDL_x11events.c Sun Aug 22 11:56:07 2010 -0700
34.2 +++ b/src/video/x11/SDL_x11events.c Sun Aug 22 12:07:55 2010 -0700
34.3 @@ -30,10 +30,18 @@
34.4 #include "SDL_x11video.h"
34.5 #include "../../events/SDL_events_c.h"
34.6 #include "../../events/SDL_mouse_c.h"
34.7 +#include "../../events/SDL_touch_c.h"
34.8
34.9 #include "SDL_timer.h"
34.10 #include "SDL_syswm.h"
34.11
34.12 +#include <stdio.h>
34.13 +
34.14 +#ifdef SDL_INPUT_LINUXEV
34.15 +//Touch Input/event* includes
34.16 +#include <linux/input.h>
34.17 +#include <fcntl.h>
34.18 +#endif
34.19 /*#define DEBUG_XEVENTS*/
34.20
34.21 /* Check to see if this is a repeated key.
34.22 @@ -121,7 +129,6 @@
34.23 SDL_SetMouseFocus(data->window);
34.24 }
34.25 break;
34.26 -
34.27 /* Losing mouse coverage? */
34.28 case LeaveNotify:{
34.29 #ifdef DEBUG_XEVENTS
34.30 @@ -495,6 +502,79 @@
34.31 while (X11_Pending(data->display)) {
34.32 X11_DispatchEvent(_this);
34.33 }
34.34 +
34.35 +#ifdef SDL_INPUT_LINUXEV
34.36 + /* Process Touch events - TODO When X gets touch support, use that instead*/
34.37 + int i = 0,rd;
34.38 + char name[256];
34.39 + struct input_event ev[64];
34.40 + int size = sizeof (struct input_event);
34.41 +
34.42 + for(i = 0;i < SDL_GetNumTouch();++i) {
34.43 + SDL_Touch* touch = SDL_GetTouchIndex(i);
34.44 + if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
34.45 + EventTouchData* data;
34.46 + data = (EventTouchData*)(touch->driverdata);
34.47 + if(data == NULL) {
34.48 + printf("No driver data\n");
34.49 + continue;
34.50 + }
34.51 + if(data->eventStream <= 0)
34.52 + printf("Error: Couldn't open stream\n");
34.53 + rd = read(data->eventStream, ev, size * 64);
34.54 + //printf("Got %i/%i bytes\n",rd,size);
34.55 + if(rd >= size) {
34.56 + for (i = 0; i < rd / sizeof(struct input_event); i++) {
34.57 + switch (ev[i].type) {
34.58 + case EV_ABS:
34.59 + //printf("Got position x: %i!\n",data->x);
34.60 + switch (ev[i].code) {
34.61 + case ABS_X:
34.62 + data->x = ev[i].value;
34.63 + break;
34.64 + case ABS_Y:
34.65 + data->y = ev[i].value;
34.66 + break;
34.67 + case ABS_PRESSURE:
34.68 + data->pressure = ev[i].value;
34.69 + if(data->pressure < 0) data->pressure = 0;
34.70 + break;
34.71 + case ABS_MISC:
34.72 + if(ev[i].value == 0)
34.73 + data->up = SDL_TRUE;
34.74 + break;
34.75 + }
34.76 + break;
34.77 + case EV_MSC:
34.78 + if(ev[i].code == MSC_SERIAL)
34.79 + data->finger = ev[i].value;
34.80 + break;
34.81 + case EV_SYN:
34.82 + //printf("Id: %i\n",touch->id);
34.83 + if(data->up) {
34.84 + SDL_SendFingerDown(touch->id,data->finger,
34.85 + SDL_FALSE,data->x,data->y,
34.86 + data->pressure);
34.87 + }
34.88 + else if(data->x >= 0 || data->y >= 0)
34.89 + SDL_SendTouchMotion(touch->id,data->finger,
34.90 + SDL_FALSE,data->x,data->y,
34.91 + data->pressure);
34.92 +
34.93 + //printf("Synched: %i tx: %i, ty: %i\n",
34.94 + // data->finger,data->x,data->y);
34.95 + data->x = -1;
34.96 + data->y = -1;
34.97 + data->pressure = -1;
34.98 + data->finger = 0;
34.99 + data->up = SDL_FALSE;
34.100 +
34.101 + break;
34.102 + }
34.103 + }
34.104 + }
34.105 + }
34.106 +#endif
34.107 }
34.108
34.109 /* This is so wrong it hurts */
35.1 --- a/src/video/x11/SDL_x11video.c Sun Aug 22 11:56:07 2010 -0700
35.2 +++ b/src/video/x11/SDL_x11video.c Sun Aug 22 12:07:55 2010 -0700
35.3 @@ -25,6 +25,7 @@
35.4
35.5 #include "SDL_video.h"
35.6 #include "SDL_mouse.h"
35.7 +#include "SDL_eventtouch.h"
35.8 #include "../SDL_sysvideo.h"
35.9 #include "../SDL_pixels_c.h"
35.10
35.11 @@ -354,6 +355,7 @@
35.12 }
35.13 X11_InitMouse(_this);
35.14
35.15 + X11_InitTouch(_this);
35.16 return 0;
35.17 }
35.18
35.19 @@ -374,6 +376,7 @@
35.20 X11_QuitModes(_this);
35.21 X11_QuitKeyboard(_this);
35.22 X11_QuitMouse(_this);
35.23 + X11_QuitTouch(_this);
35.24 }
35.25
35.26 SDL_bool
36.1 --- a/src/video/x11/SDL_x11video.h Sun Aug 22 11:56:07 2010 -0700
36.2 +++ b/src/video/x11/SDL_x11video.h Sun Aug 22 12:07:55 2010 -0700
36.3 @@ -62,6 +62,7 @@
36.4 #include "SDL_x11keyboard.h"
36.5 #include "SDL_x11modes.h"
36.6 #include "SDL_x11mouse.h"
36.7 +#include "SDL_eventtouch.h"
36.8 #include "SDL_x11opengl.h"
36.9 #include "SDL_x11window.h"
36.10
37.1 --- a/test/Makefile.in Sun Aug 22 11:56:07 2010 -0700
37.2 +++ b/test/Makefile.in Sun Aug 22 12:07:55 2010 -0700
37.3 @@ -7,7 +7,7 @@
37.4 CFLAGS = @CFLAGS@
37.5 LIBS = @LIBS@
37.6
37.7 -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testfill$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
37.8 +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testfill$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) testgesture$(EXE)
37.9
37.10 all: Makefile $(TARGETS)
37.11
37.12 @@ -151,6 +151,9 @@
37.13
37.14 testatomic$(EXE): $(srcdir)/testatomic.c
37.15 $(CC) -o $@ $? $(CFLAGS) $(LIBS)
37.16 +
37.17 +testgesture$(EXE): $(srcdir)/testgesture.c
37.18 + $(CC) -o $@ $? $(CFLAGS) $(LIBS)
37.19
37.20 testime$(EXE): $(srcdir)/testime.c
37.21 $(CC) -o $@ $? $(CFLAGS) $(LIBS) @SDL_TTF_LIB@
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/test/testgesture.c Sun Aug 22 12:07:55 2010 -0700
38.3 @@ -0,0 +1,297 @@
38.4 +/* Usage:
38.5 + * Spacebar to begin recording a gesture on all touches.
38.6 + * s to save all touches into "./gestureSave"
38.7 + * l to load all touches from "./gestureSave"
38.8 + */
38.9 +
38.10 +#include <stdio.h>
38.11 +#include <SDL.h>
38.12 +#include <math.h>
38.13 +#include <SDL_touch.h>
38.14 +#include <SDL_gesture.h>
38.15 +
38.16 +
38.17 +/* Make sure we have good macros for printing 32 and 64 bit values */
38.18 +#ifndef PRIs32
38.19 +#define PRIs32 "d"
38.20 +#endif
38.21 +#ifndef PRIu32
38.22 +#define PRIu32 "u"
38.23 +#endif
38.24 +#ifndef PRIs64
38.25 +#ifdef __WIN32__
38.26 +#define PRIs64 "I64"
38.27 +#else
38.28 +#define PRIs64 "lld"
38.29 +#endif
38.30 +#endif
38.31 +#ifndef PRIu64
38.32 +#ifdef __WIN32__
38.33 +#define PRIu64 "I64u"
38.34 +#else
38.35 +#define PRIu64 "llu"
38.36 +#endif
38.37 +#endif
38.38 +
38.39 +#define WIDTH 640
38.40 +#define HEIGHT 480
38.41 +#define BPP 4
38.42 +#define DEPTH 32
38.43 +
38.44 +//MUST BE A POWER OF 2!
38.45 +#define EVENT_BUF_SIZE 256
38.46 +
38.47 +
38.48 +#define VERBOSE SDL_FALSE
38.49 +
38.50 +SDL_Event events[EVENT_BUF_SIZE];
38.51 +int eventWrite;
38.52 +
38.53 +int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
38.54 +
38.55 +typedef struct {
38.56 + float x,y;
38.57 +} Point;
38.58 +
38.59 +typedef struct {
38.60 + float ang,r;
38.61 + Point p;
38.62 +} Knob;
38.63 +
38.64 +Knob knob;
38.65 +
38.66 +void handler (int sig)
38.67 +{
38.68 + printf ("\exiting...(%d)\n", sig);
38.69 + exit (0);
38.70 +}
38.71 +
38.72 +void perror_exit (char *error)
38.73 +{
38.74 + perror (error);
38.75 + handler (9);
38.76 +}
38.77 +
38.78 +void setpix(SDL_Surface *screen, int x, int y, unsigned int col)
38.79 +{
38.80 + Uint32 *pixmem32;
38.81 + Uint32 colour;
38.82 +
38.83 + if((unsigned)x > screen->w) return;
38.84 + if((unsigned)y > screen->h) return;
38.85 +
38.86 + pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x;
38.87 +
38.88 + Uint8 r,g,b;
38.89 + float a;
38.90 +
38.91 + memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
38.92 +
38.93 + SDL_GetRGB(colour,screen->format,&r,&g,&b);
38.94 + //r = 0;g = 0; b = 0;
38.95 + a = (col>>24)&0xFF;
38.96 + if(a == 0) a = 0xFF; //Hack, to make things easier.
38.97 + a /= 0xFF;
38.98 + r = r*(1-a) + ((col>>16)&0xFF)*(a);
38.99 + g = g*(1-a) + ((col>> 8)&0xFF)*(a);
38.100 + b = b*(1-a) + ((col>> 0)&0xFF)*(a);
38.101 + colour = SDL_MapRGB( screen->format,r, g, b);
38.102 +
38.103 +
38.104 + *pixmem32 = colour;
38.105 +}
38.106 +
38.107 +void drawLine(SDL_Surface *screen,int x0,int y0,int x1,int y1,unsigned int col) {
38.108 + float t;
38.109 + for(t=0;t<1;t+=1.f/SDL_max(abs(x0-x1),abs(y0-y1)))
38.110 + setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col);
38.111 +}
38.112 +
38.113 +void drawCircle(SDL_Surface* screen,int x,int y,int r,unsigned int c)
38.114 +{
38.115 + int tx,ty;
38.116 + float xr;
38.117 + for(ty = -abs(r);ty <= abs(r);ty++) {
38.118 + xr = sqrt(r*r - ty*ty);
38.119 + if(r > 0) { //r > 0 ==> filled circle
38.120 + for(tx=-xr+.5;tx<=xr-.5;tx++) {
38.121 + setpix(screen,x+tx,y+ty,c);
38.122 + }
38.123 + }
38.124 + else {
38.125 + setpix(screen,x-xr+.5,y+ty,c);
38.126 + setpix(screen,x+xr-.5,y+ty,c);
38.127 + }
38.128 + }
38.129 +}
38.130 +
38.131 +void drawKnob(SDL_Surface* screen,Knob k) {
38.132 + drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
38.133 + drawCircle(screen,(k.p.x+k.r/2*cos(k.ang))*screen->w,
38.134 + (k.p.y+k.r/2*sin(k.ang))*screen->h,k.r/4*screen->w,0);
38.135 +}
38.136 +
38.137 +void DrawScreen(SDL_Surface* screen)
38.138 +{
38.139 + int x, y;
38.140 + if(SDL_MUSTLOCK(screen))
38.141 + {
38.142 + if(SDL_LockSurface(screen) < 0) return;
38.143 + }
38.144 + for(y = 0;y < screen->h;y++)
38.145 + for(x = 0;x < screen->w;x++)
38.146 + setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
38.147 +
38.148 + int i;
38.149 + //draw Touch History
38.150 + for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) {
38.151 + SDL_Event event = events[i&(EVENT_BUF_SIZE-1)];
38.152 + int age = eventWrite - i - 1;
38.153 + if(event.type == SDL_FINGERMOTION ||
38.154 + event.type == SDL_FINGERDOWN ||
38.155 + event.type == SDL_FINGERUP) {
38.156 + SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
38.157 + if(inTouch == NULL) continue;
38.158 +
38.159 + float x = ((float)event.tfinger.x)/inTouch->xres;
38.160 + float y = ((float)event.tfinger.y)/inTouch->yres;
38.161 +
38.162 + //draw the touch:
38.163 + unsigned int c = colors[event.tfinger.touchId%7];
38.164 + unsigned int col =
38.165 + ((unsigned int)(c*(.1+.85))) |
38.166 + ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
38.167 +
38.168 + if(event.type == SDL_FINGERMOTION)
38.169 + drawCircle(screen,x*screen->w,y*screen->h,5,col);
38.170 + else if(event.type == SDL_FINGERDOWN)
38.171 + drawCircle(screen,x*screen->w,y*screen->h,-10,col);
38.172 + }
38.173 + }
38.174 +
38.175 + if(knob.p.x > 0)
38.176 + drawKnob(screen,knob);
38.177 +
38.178 + if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
38.179 + SDL_Flip(screen);
38.180 +}
38.181 +
38.182 +SDL_Surface* initScreen(int width,int height)
38.183 +{
38.184 + return SDL_SetVideoMode(width, height, DEPTH,
38.185 + SDL_HWSURFACE | SDL_RESIZABLE);
38.186 +}
38.187 +
38.188 +int main(int argc, char* argv[])
38.189 +{
38.190 + SDL_Surface *screen;
38.191 + SDL_Event event;
38.192 +
38.193 + //gesture variables
38.194 + knob.r = .1;
38.195 + knob.ang = 0;
38.196 +
38.197 +
38.198 + SDL_bool quitting = SDL_FALSE;
38.199 + SDL_RWops *src;
38.200 +
38.201 + if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
38.202 +
38.203 + if (!(screen = initScreen(WIDTH,HEIGHT)))
38.204 + {
38.205 + SDL_Quit();
38.206 + return 1;
38.207 + }
38.208 +
38.209 + while(!quitting) {
38.210 + while(SDL_PollEvent(&event))
38.211 + {
38.212 + //Record _all_ events
38.213 + events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
38.214 + eventWrite++;
38.215 +
38.216 + switch (event.type)
38.217 + {
38.218 + case SDL_QUIT:
38.219 + quitting = SDL_TRUE;
38.220 + break;
38.221 + case SDL_KEYDOWN:
38.222 + switch (event.key.keysym.sym)
38.223 + {
38.224 + case SDLK_SPACE:
38.225 + SDL_RecordGesture(-1);
38.226 + break;
38.227 + case SDLK_s:
38.228 + src = SDL_RWFromFile("gestureSave","w");
38.229 + printf("Wrote %i templates\n",SDL_SaveAllDollarTemplates(src));
38.230 + SDL_RWclose(src);
38.231 + break;
38.232 + case SDLK_l:
38.233 + src = SDL_RWFromFile("gestureSave","r");
38.234 + printf("Loaded: %i\n",SDL_LoadDollarTemplates(-1,src));
38.235 + SDL_RWclose(src);
38.236 + break;
38.237 + case SDLK_ESCAPE:
38.238 + quitting = SDL_TRUE;
38.239 + break;
38.240 + }
38.241 + break;
38.242 + case SDL_VIDEORESIZE:
38.243 + if (!(screen = initScreen(event.resize.w,
38.244 + event.resize.h)))
38.245 + {
38.246 + SDL_Quit();
38.247 + return 1;
38.248 + }
38.249 + break;
38.250 + case SDL_FINGERMOTION:
38.251 + ;
38.252 +#if VERBOSE
38.253 + printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
38.254 + event.tfinger.x,event.tfinger.y);
38.255 +#endif
38.256 + SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
38.257 + SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
38.258 + break;
38.259 + case SDL_FINGERDOWN:
38.260 +#if VERBOSE
38.261 + printf("Finger: %"PRIs64" down - x: %i, y: %i\n",
38.262 + event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
38.263 +#endif
38.264 + break;
38.265 + case SDL_FINGERUP:
38.266 +#if VERBOSE
38.267 + printf("Finger: %"PRIs64" up - x: %i, y: %i\n",
38.268 + event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
38.269 +#endif
38.270 + break;
38.271 + case SDL_MULTIGESTURE:
38.272 +#if VERBOSE
38.273 + printf("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f\n",
38.274 + event.mgesture.x,
38.275 + event.mgesture.y,
38.276 + event.mgesture.dTheta,
38.277 + event.mgesture.dDist);
38.278 + printf("MG: numDownTouch = %i\n",event.mgesture.numFingers);
38.279 +#endif
38.280 + knob.p.x = event.mgesture.x;
38.281 + knob.p.y = event.mgesture.y;
38.282 + knob.ang += event.mgesture.dTheta;
38.283 + knob.r += event.mgesture.dDist;
38.284 + break;
38.285 + case SDL_DOLLARGESTURE:
38.286 + printf("Gesture %"PRIs64" performed, error: %f\n",
38.287 + event.dgesture.gestureId,
38.288 + event.dgesture.error);
38.289 + break;
38.290 + case SDL_DOLLARRECORD:
38.291 + printf("Recorded gesture: %"PRIs64"\n",event.dgesture.gestureId);
38.292 + break;
38.293 + }
38.294 + }
38.295 + DrawScreen(screen);
38.296 + }
38.297 + SDL_Quit();
38.298 + return 0;
38.299 +}
38.300 +