Code archives/User Input/Multitouch Trackpad Events

This code has been declared by its author to be Public Domain code.

Download source code

Multitouch Trackpad Events by N2010
If you didn't read the short description, this is only for Mac OS.

Note: doesn't work in fullscreen for some reason. Not sure why, but it'd be easier to get it working to just put the event handling code into the BRL modules.

What this does is it takes a TGLGraphics instance and inserts a responder into the responder chain for the window or view associated with the graphics, and then passes along events to BlitzMax, which you can get at by polling for events or adding a hook for EmitEventHook.

The only important functions are CreateTrackpadHandler and DestroyTrackpadHandler. The event constants are in the source, but only three of them are used, so don't bother checking for the ones marked 'unused.'

Example



tracktouch.m (required)


tracktouch.bmx (required)
SuperStrict

?MacOS
Import "tracktouch.m"

Extern "C"
	Function CreateTrackpadHandler%(gfx:TGraphics)
	Function DestroyTrackpadHandler%(handle:Int)
End Extern
?

Const EVENT_TOUCH_GESTURE:Int = EVENT_USEREVENTMASK+88 ' unused
Const EVENT_TOUCH_MAGNIFY:Int = EVENT_TOUCH_GESTURE+1
Const EVENT_TOUCH_SWIPE:Int = EVENT_TOUCH_MAGNIFY+1
Const EVENT_TOUCH_ROTATE:Int = EVENT_TOUCH_SWIPE+1
Const EVENT_TOUCH_BEGINGESTURE:Int = EVENT_TOUCH_ROTATE+1 ' unused
Const EVENT_TOUCH_ENDGESTURE:Int = EVENT_TOUCH_BEGINGESTURE+1 ' unused

Comments

Romanski2010
I just installed Cocoa by installing DevTools and also tried a cocoa-wrapper in my mods but still can't make it run on my system.

it's having problems with "#Import <Cocoa/Cocoa.h>" in tracktouch.m

I can't really find a lot of installion-guides for this. could you help me out pls?


N2010
Could you provide the actual error from the compiler? I assume you are running Mac OS, so which version of Mac OS do you have?


Romanski2010
I have 10.5.7 .

this is the error:

Compile Error

2: error: invalid preprocessing directive #Import


N2010
Out of curiosity, are you pasting tracktouch.m into MaxIDE?


Romanski2010
I pasted the code above in MAXIDE and saved it as tracktouch.m. yes.

...ups... I think I get it...


Romanski2010
I did it now via xcode and get this error:

Building sample
Compiling:tracktouch.m
/Users/blabla/Documents/Blitzmax/Touchpad/tracktouch.m: In function '-[CTrackpadHandler magnifyWithEvent:]':
/Users/blabla/Documents/Blitzmax/Touchpad/tracktouch.m:105: error: incompatible types in assignment
Build Error: failed to compile /Users/blabla/Documents/Blitzmax/Touchpad/tracktouch.m
Process complete


N2010
magnifyWithEvent: doesn't include line 105, nor does that line have any assignments. Did you change anything?


Romanski2010
no I didn't. cxode just added some lines in the beginning with blind text that's why you're confused about line 105.

maxide selects this part from tracktouch.m :
float*)&data = [event magnification];

it doesn't like this one. with the reason "incompatible types in assignment".


N2010
According to the documentation, NSEvent#magnification is only available in Mac OS 10.6, while my headers are showing they require a minimum of 10.5.2. I suspect [event magnification] may be returning an id in your case. So, I'm not entirely sure what's up (and I'm assuming the missing opening parenthesis is just your mistake in copying).

You'll probably just have to fiddle with the code and see what works.


Romanski2010
Ok Thank you very much Nilium. I will play around with it for a while. And maybe get a new OS.


MacSven2012
I it a cool idea since i have bought a Magix Trackpad for my Mac Pro, but i get this error:

Building example
Compiling:tracktouch.m
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:1:2: error: invalid preprocessing directive #Import
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:2:2: error: invalid preprocessing directive #Import
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'BBClass'
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:17: error: expected specifier-qualifier-list before 'BBClass'
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:28: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Int'
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:34: error: expected specifier-qualifier-list before 'BBClass'
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:45: error: cannot find interface declaration for 'NSResponder', superclass of 'CTrackpadHandler'
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:46: error: expected specifier-qualifier-list before 'NSOpenGLContext'
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:48: error: stray '@' in program
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:53: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'implementation'
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:68: error: expected ';' before '{' token
/Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m:122: error: stray '@' in program
Build Error: failed to compile /Applications/BlitzMax/SourceFiles/TrackPad/tracktouch.m
Prozess abgeschlossen

I am using MacOS X 10.6.8 and XCode 3.2.6.

Any idea?


sendelbros2014
Tried it with 10.9.5/XCode 6.1 and it's working after the first try without any problems.
Thanks a lot. ;)


Code Archives Forum