From 8d20b2fbb51a74e05f9a5ecc159feefefc78467b Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Tue, 13 Oct 2015 14:08:39 +0200 Subject: [PATCH 1/4] 3DTouch for iOS Target implemented --- modules/brl/gametarget.monkey | 2 +- modules/brl/native/gametarget.cpp | 8 ++++---- modules/mojo/app.monkey | 4 ++-- modules/mojo/input.monkey | 8 ++++++++ modules/mojo/inputdevice.monkey | 17 ++++++++++++++++- targets/ios/modules/native/iosgame.cpp | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/modules/brl/gametarget.monkey b/modules/brl/gametarget.monkey index f1169229..bba215c8 100644 --- a/modules/brl/gametarget.monkey +++ b/modules/brl/gametarget.monkey @@ -57,7 +57,7 @@ Class BBGameDelegate Abstract Method RenderGame:Void() Abstract Method KeyEvent:Void( event:Int,data:Int ) Abstract Method MouseEvent:Void( event:Int,data:Int,x:Float,y:Float ) Abstract - Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float ) Abstract + Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float,force:Float,maximumPossibleForce:Float) Abstract Method MotionEvent:Void( event:Int,data:Int,x:Float,y:Float,z:Float ) Abstract Method DiscardGraphics:Void() Abstract End diff --git a/modules/brl/native/gametarget.cpp b/modules/brl/native/gametarget.cpp index 09ca1230..c3269915 100644 --- a/modules/brl/native/gametarget.cpp +++ b/modules/brl/native/gametarget.cpp @@ -20,7 +20,7 @@ class BBGameDelegate : public Object{ virtual void RenderGame(){} virtual void KeyEvent( int event,int data ){} virtual void MouseEvent( int event,int data,Float x,Float y ){} - virtual void TouchEvent( int event,int data,Float x,Float y ){} + virtual void TouchEvent( int event,int data,Float x,Float y,Float force, Float maximumPossibleForce){} virtual void MotionEvent( int event,int data,Float x,Float y,Float z ){} virtual void DiscardGraphics(){} }; @@ -87,7 +87,7 @@ class BBGame{ virtual void RenderGame(); virtual void KeyEvent( int ev,int data ); virtual void MouseEvent( int ev,int data,float x,float y ); - virtual void TouchEvent( int ev,int data,float x,float y ); + virtual void TouchEvent( int ev,int data,float x,float y,float force,float maximumPossibleForce ); virtual void MotionEvent( int ev,int data,float x,float y,float z ); virtual void DiscardGraphics(); @@ -372,12 +372,12 @@ void BBGame::MouseEvent( int ev,int data,float x,float y ){ gc_collect(); } -void BBGame::TouchEvent( int ev,int data,float x,float y ){ +void BBGame::TouchEvent( int ev,int data,float x,float y,float force, float maximumPossibleForce ){ if( !_started ) return; try{ - _delegate->TouchEvent( ev,data,x,y ); + _delegate->TouchEvent( ev,data,x,y,force,maximumPossibleForce ); }catch( ThrowableObject *ex ){ Die( ex ); } diff --git a/modules/mojo/app.monkey b/modules/mojo/app.monkey index c15a6605..2b3d2ed8 100644 --- a/modules/mojo/app.monkey +++ b/modules/mojo/app.monkey @@ -130,8 +130,8 @@ Class GameDelegate Extends BBGameDelegate _input.MouseEvent event,data,x,y End - Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float ) - _input.TouchEvent event,data,x,y + Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float, force:Float, maximumPossibleForce:Float ) + _input.TouchEvent event,data,x,y,force,maximumPossibleForce End Method MotionEvent:Void( event:Int,data:Int,x:Float,y:Float,z:Float ) diff --git a/modules/mojo/input.monkey b/modules/mojo/input.monkey index 14098597..58b3cf88 100644 --- a/modules/mojo/input.monkey +++ b/modules/mojo/input.monkey @@ -80,6 +80,14 @@ Function TouchY#( index=0 ) Return device.TouchY( index ) End +Function TouchForce#( index=0 ) + Return device.TouchForce( index ) +End + +Function TouchMaximumPossibleForce#( index= 0) + Return device.TouchMaximumPossibleForce( index ) +End + Function TouchDown( index=0 ) Return device.KeyDown( KEY_TOUCH0+index ) End diff --git a/modules/mojo/inputdevice.monkey b/modules/mojo/inputdevice.monkey index 47ec4210..4e3596cd 100644 --- a/modules/mojo/inputdevice.monkey +++ b/modules/mojo/inputdevice.monkey @@ -82,6 +82,16 @@ Class InputDevice If index>=0 And index<32 Return _touchY[index] Return 0 End + + Method TouchForce#( index ) + If index>=0 And index<32 Return _touchForce[index] + Return 0 + End + + Method TouchMaximumPossibleForce#( index ) + If index>=0 And index<32 Return _touchMaximumPossibleForce[index] + Return 0 + End Method AccelX#() Return _accelX @@ -155,12 +165,13 @@ Class InputDevice _touchY[0]=y End - Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float ) + Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float, force:Float = 0.0, maximumPossibleForce:Float = 0.0 ) Select event Case BBGameEvent.TouchDown KeyEvent BBGameEvent.KeyDown,KEY_TOUCH0+data Case BBGameEvent.TouchUp KeyEvent BBGameEvent.KeyUp,KEY_TOUCH0+data + _touchForce[data] = 0 Return Case BBGameEvent.TouchMove Default @@ -168,6 +179,8 @@ Class InputDevice End _touchX[data]=x _touchY[data]=y + _touchForce[data] = force + _touchMaximumPossibleForce[data] = maximumPossibleForce If data=0 _mouseX=x _mouseY=y @@ -228,6 +241,8 @@ Private Field _mouseY:Float Field _touchX:Float[32] Field _touchY:Float[32] + Field _touchForce:Float[32] + Field _touchMaximumPossibleForce:Float[32] Field _accelX:Float Field _accelY:Float Field _accelZ:Float diff --git a/targets/ios/modules/native/iosgame.cpp b/targets/ios/modules/native/iosgame.cpp index 445427fa..587fd957 100644 --- a/targets/ios/modules/native/iosgame.cpp +++ b/targets/ios/modules/native/iosgame.cpp @@ -458,7 +458,7 @@ void BBIosGame::TouchesEvent( UIEvent *event ){ p.x*=scaleFactor; p.y*=scaleFactor; - TouchEvent( ev,pid,p.x,p.y ); + TouchEvent( ev,pid,p.x,p.y, _touches[pid].force, _touches[pid].maximumPossibleForce ); } } } From 56d682c7f11c8b62f0238b59b0e1be54b0982310 Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Sat, 17 Oct 2015 18:17:00 +0200 Subject: [PATCH 2/4] Added ios9 Check (because else it will crash on devices with older os versions) --- targets/ios/modules/native/iosgame.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/targets/ios/modules/native/iosgame.cpp b/targets/ios/modules/native/iosgame.cpp index 587fd957..9e099984 100644 --- a/targets/ios/modules/native/iosgame.cpp +++ b/targets/ios/modules/native/iosgame.cpp @@ -457,8 +457,13 @@ void BBIosGame::TouchesEvent( UIEvent *event ){ CGPoint p=[touch locationInView:view]; p.x*=scaleFactor; p.y*=scaleFactor; - - TouchEvent( ev,pid,p.x,p.y, _touches[pid].force, _touches[pid].maximumPossibleForce ); + + #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) { + TouchEvent( ev,pid,p.x,p.y, _touches[pid].force, _touches[pid].maximumPossibleForce ); + } else { + TouchEvent( ev,pid,p.x,p.y, 0, 0 ); + } } } } From 1ea46efdd11e2dedf95660bb5e3ea0add00133b0 Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Mon, 2 Nov 2015 17:17:38 +0100 Subject: [PATCH 3/4] Added TouchEvent-Signature to keep compatibility for targets that don't support 3D Touch --- modules/brl/gametarget.monkey | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/brl/gametarget.monkey b/modules/brl/gametarget.monkey index bba215c8..5ae10435 100644 --- a/modules/brl/gametarget.monkey +++ b/modules/brl/gametarget.monkey @@ -58,6 +58,7 @@ Class BBGameDelegate Abstract Method KeyEvent:Void( event:Int,data:Int ) Abstract Method MouseEvent:Void( event:Int,data:Int,x:Float,y:Float ) Abstract Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float,force:Float,maximumPossibleForce:Float) Abstract + Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float) Abstract Method MotionEvent:Void( event:Int,data:Int,x:Float,y:Float,z:Float ) Abstract Method DiscardGraphics:Void() Abstract End From b3b8faabee1571631f88bb279df922a602e503bc Mon Sep 17 00:00:00 2001 From: Jochen Heizmann Date: Mon, 2 Nov 2015 17:18:25 +0100 Subject: [PATCH 4/4] Delegate TouchEvents without Force-Attribute (for targets that don't support 3D Touch) --- modules/mojo/app.monkey | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/mojo/app.monkey b/modules/mojo/app.monkey index 2b3d2ed8..9a7f7c59 100644 --- a/modules/mojo/app.monkey +++ b/modules/mojo/app.monkey @@ -134,6 +134,10 @@ Class GameDelegate Extends BBGameDelegate _input.TouchEvent event,data,x,y,force,maximumPossibleForce End + Method TouchEvent:Void( event:Int,data:Int,x:Float,y:Float ) + TouchEvent(event,data,x,y,0,0) + End + Method MotionEvent:Void( event:Int,data:Int,x:Float,y:Float,z:Float ) _input.MotionEvent event,data,x,y,z End