# HG changeset patch # User koda # Date 1262893840 0 # Node ID d4c395f25db2625a26020dc33d203e6c8c8a79f4 # Parent dcbb5e98afc796de68b761fc1e520a000810919e additional modifications for touch input diff -r dcbb5e98afc7 -r d4c395f25db2 cocoaTouch/MainWindow.xib --- a/cocoaTouch/MainWindow.xib Thu Jan 07 16:18:32 2010 +0000 +++ b/cocoaTouch/MainWindow.xib Thu Jan 07 19:50:40 2010 +0000 @@ -53,31 +53,28 @@ </object> <object class="IBUITabBarController" id="949193037"> <object class="IBUISimulatedTabBarMetrics" key="IBUISimulatedBottomBarMetrics"/> - <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"> - <int key="IBUIStatusBarStyle">2</int> - </object> <bool key="IBUIWantsFullScreenLayout">YES</bool> - <object class="IBUIViewController" key="IBUISelectedViewController" id="967197078"> - <string key="IBUITitle">Item 5</string> - <object class="IBUITabBarItem" key="IBUITabBarItem" id="1027647142"> - <int key="IBUITag">4</int> - <string key="IBUITitle">Custom</string> + <object class="IBUIViewController" key="IBUISelectedViewController" id="78432802"> + <string key="IBUITitle">Item 4</string> + <object class="IBUITabBarItem" key="IBUITabBarItem" id="457331497"> + <int key="IBUITag">3</int> + <string key="IBUITitle">Settings</string> <object class="NSCustomResource" key="IBUIImage"> <string key="NSClassName">NSImage</string> - <string key="NSResourceName">toolicon.png</string> + <string key="NSResourceName">dependenticon.png</string> </object> <reference key="IBUITabBar"/> </object> <reference key="IBUIToolbarItems" ref="0"/> <reference key="IBUIParentViewController" ref="949193037"/> - <string key="IBUINibName">CustomPickerViewController</string> + <string key="IBUINibName">DependentComponentPickerViewController</string> </object> <object class="NSMutableArray" key="IBUIViewControllers"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="IBUIViewController" id="316666609"> <string key="IBUITitle">Item 1</string> <object class="IBUITabBarItem" key="IBUITabBarItem" id="649951061"> - <string key="IBUITitle">Date</string> + <string key="IBUITitle">Main</string> <object class="NSCustomResource" key="IBUIImage"> <string key="NSClassName">NSImage</string> <string key="NSResourceName">clockicon.png</string> @@ -91,7 +88,7 @@ <string key="IBUITitle">Item 2</string> <object class="IBUITabBarItem" key="IBUITabBarItem" id="121845716"> <int key="IBUITag">1</int> - <string key="IBUITitle">Single</string> + <string key="IBUITitle">Teams</string> <object class="NSCustomResource" key="IBUIImage"> <string key="NSClassName">NSImage</string> <string key="NSResourceName">singleicon.png</string> @@ -105,7 +102,7 @@ <string key="IBUITitle">Item 3</string> <object class="IBUITabBarItem" key="IBUITabBarItem" id="588275822"> <int key="IBUITag">2</int> - <string key="IBUITitle">Double</string> + <string key="IBUITitle">Schemes</string> <object class="NSCustomResource" key="IBUIImage"> <string key="NSClassName">NSImage</string> <string key="NSResourceName">doubleicon.png</string> @@ -116,22 +113,7 @@ <reference key="IBUIParentViewController" ref="949193037"/> <string key="IBUINibName">DoubleComponentPickerViewController</string> </object> - <object class="IBUIViewController" id="78432802"> - <string key="IBUITitle">Item 4</string> - <object class="IBUITabBarItem" key="IBUITabBarItem" id="457331497"> - <int key="IBUITag">3</int> - <string key="IBUITitle">Dependent</string> - <object class="NSCustomResource" key="IBUIImage"> - <string key="NSClassName">NSImage</string> - <string key="NSResourceName">dependenticon.png</string> - </object> - <reference key="IBUITabBar"/> - </object> - <reference key="IBUIToolbarItems" ref="0"/> - <reference key="IBUIParentViewController" ref="949193037"/> - <string key="IBUINibName">DependentComponentPickerViewController</string> - </object> - <reference ref="967197078"/> + <reference ref="78432802"/> </object> <object class="IBUITabBar" key="IBUITabBar" id="906583108"> <nil key="NSNextResponder"/> @@ -216,7 +198,6 @@ <reference ref="56776854"/> <reference ref="18996086"/> <reference ref="78432802"/> - <reference ref="967197078"/> </object> <reference key="parent" ref="0"/> </object> @@ -281,20 +262,6 @@ <reference key="object" ref="457331497"/> <reference key="parent" ref="78432802"/> </object> - <object class="IBObjectRecord"> - <int key="objectID">20</int> - <reference key="object" ref="967197078"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="1027647142"/> - </object> - <reference key="parent" ref="949193037"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">21</int> - <reference key="object" ref="1027647142"/> - <reference key="parent" ref="967197078"/> - </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -317,7 +284,6 @@ <string>2.IBAttributePlaceholdersKey</string> <string>2.IBEditorWindowLastContentRect</string> <string>2.IBPluginDependency</string> - <string>20.CustomClassName</string> <string>3.CustomClassName</string> <string>3.IBPluginDependency</string> </object> @@ -325,7 +291,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <string>UIApplication</string> <string>UIResponder</string> - <string>{{0, 654}, {320, 480}}</string> + <string>{{144, 608}, {320, 480}}</string> <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string>DatePickerViewController</string> @@ -345,7 +311,6 @@ </object> <string>{{820, 472}, {320, 480}}</string> <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> - <string>CustomPickerViewController</string> <string>SDLUIKitDelegate</string> <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> </object> @@ -375,8 +340,17 @@ <string key="className">DatePickerViewController</string> <string key="superclassName">UIViewController</string> <object class="NSMutableDictionary" key="actions"> - <string key="NS.key.0">buttonPressed</string> - <string key="NS.object.0">id</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>buttonPressed</string> + <string>startGame</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>id</string> + </object> </object> <object class="NSMutableDictionary" key="outlets"> <string key="NS.key.0">date_picker</string> @@ -390,10 +364,6 @@ <object class="IBPartialClassDescription"> <string key="className">SDLUIKitDelegate</string> <string key="superclassName">NSObject</string> - <object class="NSMutableDictionary" key="actions"> - <string key="NS.key.0">startSDLgame</string> - <string key="NS.object.0">id</string> - </object> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSArray" key="dict.sortedKeys"> @@ -409,7 +379,7 @@ </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">Classes/SDL_uikitappdelegate.h</string> + <string key="minorKey">../../../hedge.build/trunk/cocoaTouch/SDL_uikitappdelegate.h</string> </object> </object> </object> @@ -679,7 +649,7 @@ <integer value="3100" key="NS.object.0"/> </object> <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> - <string key="IBDocument.LastKnownRelativeProjectPath">../hwengine.xcodeproj</string> + <string key="IBDocument.LastKnownRelativeProjectPath">../../../Documents/xcode/hwengine/hwengine.xcodeproj</string> <int key="IBDocument.defaultPropertyAccessControl">3</int> <string key="IBCocoaTouchPluginVersion">3.1</string> </data> diff -r dcbb5e98afc7 -r d4c395f25db2 cocoaTouch/SDL_uikitview.h --- a/cocoaTouch/SDL_uikitview.h Thu Jan 07 16:18:32 2010 +0000 +++ b/cocoaTouch/SDL_uikitview.h Thu Jan 07 19:50:40 2010 +0000 @@ -34,25 +34,34 @@ #define MAX_SIMULTANEOUS_TOUCHES 1 #endif -#define kMinimumPinchDelta 100 +// constants for telling which input has been received +#define kMinimumPinchDelta 100 +#define kMinimumGestureLength 25 +#define kMaximumVariance 5 + /* *INDENT-OFF* */ #if SDL_IPHONE_KEYBOARD @interface SDL_uikitview : UIView<UITextFieldDelegate> { #else @interface SDL_uikitview : UIView { #endif + SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES]; CGFloat initialDistance; + CGPoint gestureStartPoint; + #if SDL_IPHONE_KEYBOARD UITextField *textField; BOOL keyboardVisible; #endif } + - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; @property CGFloat initialDistance; +@property CGPoint gestureStartPoint; #if SDL_IPHONE_KEYBOARD - (void)showKeyboard; diff -r dcbb5e98afc7 -r d4c395f25db2 cocoaTouch/SDL_uikitview.m --- a/cocoaTouch/SDL_uikitview.m Thu Jan 07 16:18:32 2010 +0000 +++ b/cocoaTouch/SDL_uikitview.m Thu Jan 07 19:50:40 2010 +0000 @@ -22,17 +22,17 @@ #include "PascalImports.h" #import "SDL_uikitview.h" +#import "SDL_uikitappdelegate.h" #if SDL_IPHONE_KEYBOARD #import "SDL_keyboard_c.h" #import "keyinfotable.h" #import "SDL_uikitwindow.h" -#import "SDL_uikitappdelegate.h" #endif @implementation SDL_uikitview -@synthesize initialDistance; +@synthesize initialDistance, gestureStartPoint; - (void)dealloc { #if SDL_IPHONE_KEYBOARD @@ -67,7 +67,6 @@ // we override default touch input to implement our own gestures - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - /*NSEnumerator *enumerator = [touches objectEnumerator]; UITouch *touch =(UITouch*)[enumerator nextObject]; @@ -112,7 +111,15 @@ SDL_SelectMouse(oldMouse); } */ + UITouch *touch = [touches anyObject]; + gestureStartPoint = [touch locationInView:self]; + + if (1 == [touch tapCount] ) { + //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].windowID, gestureStartPoint.x, gestureStartPoint.y); + HW_click(); + } + if (2 == [touch tapCount] ) { HW_ammoMenu(); } @@ -127,6 +134,9 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { initialDistance = 0; + NSLog(@"touches ended, sigh"); + + HW_allKeysUp(); /*NSEnumerator *enumerator = [touches objectEnumerator]; UITouch *touch=nil; @@ -158,10 +168,21 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { + UITouch *touch = [touches anyObject]; + CGPoint currentPosition = [touch locationInView:self]; -// NSEnumerator *enumerator = [touches objectEnumerator]; -// UITouch *touch=nil; - + CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); + CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); + + if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) { + NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); + HW_walkLeft(); + } + else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){ + NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); + HW_walkRight(); + } + if (2 == [touches count]) { NSArray *twoTouches = [touches allObjects]; UITouch *first = [twoTouches objectAtIndex:0]; @@ -180,7 +201,8 @@ } } - /*while(touch = (UITouch *)[enumerator nextObject]) { + /*NSEnumerator *enumerator = [touches objectEnumerator]; + UITouch *touch=nil;while(touch = (UITouch *)[enumerator nextObject]) { // try to find the mouse associated with this touch int i, found = NO; for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { diff -r dcbb5e98afc7 -r d4c395f25db2 cocoaTouch/otherSrc/PascalImports.h --- a/cocoaTouch/otherSrc/PascalImports.h Thu Jan 07 16:18:32 2010 +0000 +++ b/cocoaTouch/otherSrc/PascalImports.h Thu Jan 07 19:50:40 2010 +0000 @@ -13,16 +13,23 @@ #ifdef __cplusplus extern "C" { #endif - -/* add C declarations below for all exported Pascal functions/procedure - * that you want to use - */ + + /* add C declarations below for all exported Pascal functions/procedure + * that you want to use + */ -void HW_click(void); -void HW_zoomIn(void); -void HW_zoomOut(void); -void HW_ammoMenu(void); - + void HW_click(void); + void HW_zoomIn(void); + void HW_zoomOut(void); + void HW_ammoMenu(void); + void HW_allKeysUp(void); + + void HW_walkLeft(void); + void HW_walkRight(void); + void HW_aimUp(void); + void HW_aimDown(void); + void HW_shoot(void); + #ifdef __cplusplus } #endif diff -r dcbb5e98afc7 -r d4c395f25db2 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Thu Jan 07 16:18:32 2010 +0000 +++ b/hedgewars/hwengine.pas Thu Jan 07 19:50:40 2010 +0000 @@ -160,25 +160,12 @@ CurrTime: Longword; event: TSDL_Event; {$IFDEF TOUCHINPUT} -type TDirection = (nodir, left, right); var tiltValue: LongInt; - direction: TDirection = nodir; - movedbybuttons: boolean = false; {$ENDIF} begin PrevTime:= SDL_GetTicks; repeat while SDL_PollEvent(@event) <> 0 do -{$IFDEF TOUCHINPUT} -if (direction <> nodir) and (movedbybuttons = true) then -begin - WriteLnToConsole('* Hedgehog moving *'); - uKeys.isWalking:= true; - if direction = left then uKeys.leftKey:= true - else if direction = right then uKeys.rightKey:= true; -end -else uKeys.isWalking:= false; -{$ENDIF} case event.type_ of {$IFDEF SDL13} SDL_WINDOWEVENT: diff -r dcbb5e98afc7 -r d4c395f25db2 hedgewars/uKeys.pas --- a/hedgewars/uKeys.pas Thu Jan 07 16:18:32 2010 +0000 +++ b/hedgewars/uKeys.pas Thu Jan 07 19:50:40 2010 +0000 @@ -18,6 +18,7 @@ {$INCLUDE "options.inc"} {$IFDEF IPHONEOS} {$MODE OBJFPC} {$ENDIF} +// TODO: insert the above line in options.inc unit uKeys; interface @@ -46,6 +47,13 @@ procedure HW_zoomIn; cdecl; export; procedure HW_zoomOut; cdecl; export; procedure HW_ammoMenu; cdecl; export; +procedure HW_allKeysUp; cdecl; export; +procedure HW_walkLeft; cdecl; export; +procedure HW_walkRight; cdecl; export; +procedure HW_aimUp; cdecl; export; +procedure HW_aimDown; cdecl; export; +procedure HW_shoot; cdecl; export; + {$ENDIF} var hideAmmoMenu: boolean; @@ -93,9 +101,10 @@ {$IFDEF IPHONEOS} // these are called by the touch functions present in SDL_uikitview.m +// they emulate user interaction from mouse or keyboard procedure HW_click; cdecl; export; begin - WriteLnToConsole('HW - general click'); + WriteLnToConsole('HW - left click'); leftClick:= true; exit end; @@ -116,10 +125,57 @@ procedure HW_ammoMenu; cdecl; export; begin - WriteLnToConsole('HW - opening ammomenu'); + WriteLnToConsole('HW - right click'); rightClick:= true; exit end; + +procedure HW_allKeysUp; cdecl; export; +begin + WriteLnToConsole('HW - resetting keyboard'); + + upKey:= false; + downKey:= false; + leftKey:= false; + rightKey:= false; + spaceKey:= false; + exit +end; + +procedure HW_walkLeft; cdecl; export; +begin + WriteLnToConsole('HW - walking left'); + leftKey:= true; + exit +end; + +procedure HW_walkRight; cdecl; export; +begin + WriteLnToConsole('HW - walking right'); + rightKey:= true; + exit +end; + +procedure HW_aimUp; cdecl; export; +begin + WriteLnToConsole('HW - aiming upwards'); + upKey:= true; + exit +end; + +procedure HW_aimDown; cdecl; export; +begin + WriteLnToConsole('HW - aiming downwards'); + downKey:= true; + exit +end; + +procedure HW_shoot; cdecl; export; +begin + WriteLnToConsole('HW - shooting'); + spaceKey:= true; + exit +end; {$ENDIF} function KeyNameToCode(name: string): word; @@ -191,12 +247,6 @@ tkbdn[13]:= ord(enterKey); tkbdn[32]:= ord(spaceKey); -upKey:= false; -downKey:= false; -if isWalking = false then rightKey:= false; -if isWalking = false then leftKey:= false; - -if isAttacking = false then spaceKey:= false; tabKey:= false; enterKey:= false; backspaceKey:= false; @@ -298,13 +348,7 @@ tkbdn[13]:= ord(enterKey); tkbdn[32]:= ord(spaceKey); -upKey:= false; -downKey:= false; tabKey:= false; -if isWalking = false then rightKey:= false; -if isWalking = false then leftKey:= false; - -if isAttacking = false then spaceKey:= false; enterKey:= false; backspaceKey:= false; {$ENDIF} diff -r dcbb5e98afc7 -r d4c395f25db2 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Thu Jan 07 16:18:32 2010 +0000 +++ b/hedgewars/uWorld.pas Thu Jan 07 19:50:40 2010 +0000 @@ -345,9 +345,8 @@ //glScalef(1.0, 1.0, 1.0); {$IFDEF IPHONEOS} -{* see the code in MainLoop *} SDL_GetMouseState(@x, @y); -if ((x > 50) and (x <= 270) and (y > 50) and (y <= 330)) then +//WriteLnToConsole('x; ' + inttostr(x) + ' y: ' + inttostr(y)); {$ENDIF} if not isPaused then MoveCamera;