touch input: reset zoom, attack button
authorkoda
Thu, 07 Jan 2010 22:49:25 +0000
changeset 2683 bad2a30d5d6c
parent 2682 d4c395f25db2
child 2684 04c086d8d9d4
touch input: reset zoom, attack button
cocoaTouch/SDL_uikitview.h
cocoaTouch/SDL_uikitview.m
cocoaTouch/otherSrc/PascalImports.h
hedgewars/uKeys.pas
--- a/cocoaTouch/SDL_uikitview.h	Thu Jan 07 19:50:40 2010 +0000
+++ b/cocoaTouch/SDL_uikitview.h	Thu Jan 07 22:49:25 2010 +0000
@@ -1,24 +1,24 @@
 /*
-    SDL - Simple DirectMedia Layer
-    Copyright (C) 1997-2009 Sam Lantinga
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-	Sam Lantinga, mods for Hedgewars by Vittorio Giovara
-	slouken@libsdl.org, vittorio.giovara@gmail.com
-*/
+ SDL - Simple DirectMedia Layer
+ Copyright (C) 1997-2009 Sam Lantinga
+ 
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ 
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+ 
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ 
+ Sam Lantinga, mods for Hedgewars by Vittorio Giovara
+ slouken@libsdl.org, vittorio.giovara@gmail.com
+ */
 
 #import <UIKit/UIKit.h>
 #include "SDL_stdinc.h"
@@ -36,29 +36,32 @@
 
 // constants for telling which input has been received
 #define kMinimumPinchDelta		100
-#define kMinimumGestureLength	25
-#define kMaximumVariance		5
+#define kMinimumGestureLength	20
+#define kMaximumVariance		4
 
 /* *INDENT-OFF* */
-#if SDL_IPHONE_KEYBOARD
-@interface SDL_uikitview : UIView<UITextFieldDelegate> {
-#else
+//#if SDL_IPHONE_KEYBOARD
+//@interface SDL_uikitview : UIView<UITextFieldDelegate> {
+//#else
 @interface SDL_uikitview : UIView {
-#endif
-	
+//#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;
+-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
+-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
+-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
+
+// see initWithFrame for why "+"
++(void) attackButtonPressed;
++(void) attackButtonReleased;
 
 @property CGFloat initialDistance;
 @property CGPoint gestureStartPoint;
@@ -69,6 +72,6 @@
 - (void)initializeKeyboard;
 @property (readonly) BOOL keyboardVisible;
 #endif 
-	
+
 @end
 /* *INDENT-ON* */
--- a/cocoaTouch/SDL_uikitview.m	Thu Jan 07 19:50:40 2010 +0000
+++ b/cocoaTouch/SDL_uikitview.m	Thu Jan 07 22:49:25 2010 +0000
@@ -56,10 +56,32 @@
 		mice[i].driverdata = NULL;
 		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
 	}
+	
+	UIButton *attackButton;
+
+	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 90,60)];
+	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
+	// this object is inherited by SDL_openglesview.m which is the one allocated by SDL.
+	// We select this class with [self superclass] and call the selectors with "+" because
+	// they are superclass methods 
+	[attackButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchDown];
+	[attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
+	[self insertSubview:attackButton atIndex:10];
+	[attackButton release];
+
 	self.multipleTouchEnabled = YES;
 			
 	return self;
+}
 
+#pragma mark -
+#pragma mark Superclass methods
++(void) attackButtonPressed {
+	HW_shoot();
+}
+
++(void) attackButtonReleased {
+	HW_allKeysUp();
 }
 
 #pragma mark -
@@ -115,15 +137,23 @@
 	UITouch *touch = [touches anyObject];
 	gestureStartPoint = [touch locationInView:self];
 
+	// one tap - single click
 	if (1 == [touch tapCount] ) {
 		//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].windowID, gestureStartPoint.x, gestureStartPoint.y);
 		HW_click();
 	}
 	
+	// two taps - right click
 	if (2 == [touch tapCount] ) {
 		HW_ammoMenu();
 	}
 	
+	// two taps with two fingers - middle click
+	if (2 == [touch tapCount] && 2 == [touches count]) {
+		HW_zoomReset();
+	}
+	
+	// two fingers - begin pinching
 	if (2 == [touches count]) {
 		NSArray *twoTouches = [touches allObjects];
 		UITouch *first = [twoTouches objectAtIndex:0];
@@ -166,22 +196,25 @@
 	[self touchesEnded: touches withEvent: event];
 }
 
-
 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
 	UITouch *touch = [touches anyObject];
 	CGPoint currentPosition = [touch locationInView:self];
 	
-	CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
-    CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
+	CGFloat Xdiff = gestureStartPoint.x - currentPosition.x;
+	CGFloat Ydiff = gestureStartPoint.y - currentPosition.y;
+	CGFloat deltaX = fabsf(Xdiff);
+    CGFloat deltaY = fabsf(Ydiff);
     
 	if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
 		NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
-		HW_walkLeft();
+		if (Xdiff > 0) HW_walkLeft();
+		else HW_walkRight();
     }
     else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
 		NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
-		HW_walkRight();
-    }
+		if (Ydiff > 0) HW_aimUp();
+		else HW_aimDown();
+	}
 	
 	if (2 == [touches count]) {
 		NSArray *twoTouches = [touches allObjects];
--- a/cocoaTouch/otherSrc/PascalImports.h	Thu Jan 07 19:50:40 2010 +0000
+++ b/cocoaTouch/otherSrc/PascalImports.h	Thu Jan 07 22:49:25 2010 +0000
@@ -21,7 +21,9 @@
 	void HW_click(void);
 	void HW_zoomIn(void);
 	void HW_zoomOut(void);
+	void HW_zoomReset(void);
 	void HW_ammoMenu(void);
+	
 	void HW_allKeysUp(void);
 	
 	void HW_walkLeft(void);
--- a/hedgewars/uKeys.pas	Thu Jan 07 19:50:40 2010 +0000
+++ b/hedgewars/uKeys.pas	Thu Jan 07 22:49:25 2010 +0000
@@ -46,6 +46,7 @@
 procedure HW_click; cdecl; export;
 procedure HW_zoomIn; cdecl; export;
 procedure HW_zoomOut; cdecl; export;
+procedure HW_zoomReset; cdecl; export;
 procedure HW_ammoMenu; cdecl; export;
 procedure HW_allKeysUp; cdecl; export;
 procedure HW_walkLeft; cdecl; export;
@@ -53,6 +54,7 @@
 procedure HW_aimUp; cdecl; export;
 procedure HW_aimDown; cdecl; export;
 procedure HW_shoot; cdecl; export;
+procedure HW_whereIsHog; cdecl; export;
 
 {$ENDIF}
 
@@ -123,6 +125,13 @@
 	exit
 end;
 
+procedure HW_zoomReset; cdecl; export;
+begin
+	WriteLnToConsole('HW - reset zoom');
+	middleClick:= true;
+	exit
+end;
+
 procedure HW_ammoMenu; cdecl; export;
 begin
 	WriteLnToConsole('HW - right click');
@@ -176,6 +185,15 @@
 	spaceKey:= true;
 	exit
 end;
+
+procedure HW_whereIsHog; cdecl; export;
+var Xcoord, Ycoord: LongInt;
+begin
+	//Xcoord:= Gear^.dX + WorldDx;
+	WriteLnToConsole('HW - hog is at x: ' + ' y:');
+
+	exit
+end;
 {$ENDIF}
 	
 function KeyNameToCode(name: string): word;