# 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 @@ - - 2 - YES - - Item 5 - - 4 - Custom + + Item 4 + + 3 + Settings NSImage - toolicon.png + dependenticon.png - CustomPickerViewController + DependentComponentPickerViewController YES Item 1 - Date + Main NSImage clockicon.png @@ -91,7 +88,7 @@ Item 2 1 - Single + Teams NSImage singleicon.png @@ -105,7 +102,7 @@ Item 3 2 - Double + Schemes NSImage doubleicon.png @@ -116,22 +113,7 @@ DoubleComponentPickerViewController - - Item 4 - - 3 - Dependent - - NSImage - dependenticon.png - - - - - - DependentComponentPickerViewController - - + @@ -216,7 +198,6 @@ - @@ -281,20 +262,6 @@ - - 20 - - - YES - - - - - - 21 - - - @@ -317,7 +284,6 @@ 2.IBAttributePlaceholdersKey 2.IBEditorWindowLastContentRect 2.IBPluginDependency - 20.CustomClassName 3.CustomClassName 3.IBPluginDependency @@ -325,7 +291,7 @@ YES UIApplication UIResponder - {{0, 654}, {320, 480}} + {{144, 608}, {320, 480}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin DatePickerViewController @@ -345,7 +311,6 @@ {{820, 472}, {320, 480}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin - CustomPickerViewController SDLUIKitDelegate com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -375,8 +340,17 @@ DatePickerViewController UIViewController - buttonPressed - id + YES + + YES + buttonPressed + startGame + + + YES + id + id + date_picker @@ -390,10 +364,6 @@ SDLUIKitDelegate NSObject - - startSDLgame - id - YES @@ -409,7 +379,7 @@ IBProjectSource - Classes/SDL_uikitappdelegate.h + ../../../hedge.build/trunk/cocoaTouch/SDL_uikitappdelegate.h @@ -679,7 +649,7 @@ YES - ../hwengine.xcodeproj + ../../../Documents/xcode/hwengine/hwengine.xcodeproj 3 3.1 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 { #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 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;