iphone overlay button animation
authorkoda
Sat, 09 Jan 2010 00:59:12 +0000
changeset 2689 dfda97c153a4
parent 2688 174c94b8ea72
child 2690 8e83c7e31720
iphone overlay button animation
CMakeLists.txt
cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m
cocoaTouch/SDLOverrides/SDL_uikitview.m
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uStore.pas
--- a/CMakeLists.txt	Fri Jan 08 03:52:44 2010 +0000
+++ b/CMakeLists.txt	Sat Jan 09 00:59:12 2010 +0000
@@ -205,6 +205,8 @@
 	"hwconsts.cpp$"
 	"playlist.inc$"
 	"CPack"
+	"^${PROJECT_SOURCE_DIR}/openalbridge"
+	"^${PROJECT_SOURCE_DIR}/cocoaTouch"
 	"^${PROJECT_SOURCE_DIR}/bin/[a-z]"
 	"^${PROJECT_SOURCE_DIR}/tools/templates"
 	"^${PROJECT_SOURCE_DIR}/doc"
--- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Fri Jan 08 03:52:44 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Sat Jan 09 00:59:12 2010 +0000
@@ -81,6 +81,9 @@
 
 	/* Set working directory to resource path */
 	[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
+//#import "SoundEffect.h"	
+//	SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
+//	SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
 	
 	[window addSubview:controller.view];
 	[window makeKeyAndVisible];
--- a/cocoaTouch/SDLOverrides/SDL_uikitview.m	Fri Jan 08 03:52:44 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitview.m	Sat Jan 09 00:59:12 2010 +0000
@@ -34,16 +34,24 @@
 
 @synthesize initialDistance, gestureStartPoint;
 
+// they have to be global variables to allow showControls() to use them
+UIButton *attackButton, *menuButton;
+
 - (void)dealloc {
 #if SDL_IPHONE_KEYBOARD
 	SDL_DelKeyboard(0);
 	[textField release];
 #endif
+	[menuButton release];
+	[attackButton release];
 	[super dealloc];
 }
 
 - (id)initWithFrame:(CGRect)frame {
-
+	// the addTarget parameter for the buttons below is set like that because
+	// 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 
 	self = [super initWithFrame: frame];
 	
 #if SDL_IPHONE_KEYBOARD
@@ -56,26 +64,39 @@
 		mice[i].driverdata = NULL;
 		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
 	}
-	
-	UIButton *attackButton;
 
-	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 90,60)];
+	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 480, 260,50)];
 	[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 addSubview:attackButton];
+
+	menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)];
+	[menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
+	[menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside];
+	[self addSubview:menuButton];
 
 	self.multipleTouchEnabled = YES;
-			
+
 	return self;
 }
 
 #pragma mark -
+#pragma mark Show and Hide overlaid buttons
+
+// standard C function to be called from pascal
+void showControls(void) {
+	NSLog(@"Showing controls");
+	[UIView beginAnimations:nil context:NULL];
+	[UIView setAnimationDuration:0.5];
+	attackButton.frame = CGRectMake(30, 430, 260, 50);
+	menuButton.frame = CGRectMake(0, 430, 30, 50);
+	[UIView commitAnimations];
+}
+
+#pragma mark -
 #pragma mark Superclass methods
+
 +(void) attackButtonPressed {
 	HW_shoot();
 }
--- a/hedgewars/SDLh.pas	Fri Jan 08 03:52:44 2010 +0000
+++ b/hedgewars/SDLh.pas	Sat Jan 09 00:59:12 2010 +0000
@@ -734,7 +734,8 @@
 function  SDLNet_Read32(buf: pointer): LongWord;
 
 {$IFDEF IPHONEOS}
-function get_documents_path: PChar; cdecl; external 'hwutils';
+function  get_documents_path: PChar; cdecl; external 'hwutils';
+procedure IPH_showControls; cdecl; external name 'showControls';
 {$ENDIF}
 
 implementation
--- a/hedgewars/hwengine.pas	Fri Jan 08 03:52:44 2010 +0000
+++ b/hedgewars/hwengine.pas	Sat Jan 09 00:59:12 2010 +0000
@@ -96,7 +96,7 @@
 			FinishProgress;
 			PlayMusic;
 			SetScale(zoom);
-			GameState:= gsGame
+			GameState:= gsGame;
 			end;
 	gsConfirm,
 	gsGame: begin
--- a/hedgewars/uStore.pas	Fri Jan 08 03:52:44 2010 +0000
+++ b/hedgewars/uStore.pas	Sat Jan 09 00:59:12 2010 +0000
@@ -1159,9 +1159,9 @@
 // prepare default translation/scaling
 glLoadIdentity();
 glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
-//{$IFDEF IPHONEOS}
+{$IFDEF IPHONEOS}
 //glRotatef(90, 0, 0, 1);
-//{$ENDIF}
+{$ENDIF}
 glTranslatef(0, -cScreenHeight / 2, 0);
 
 // enable alpha blending
@@ -1181,9 +1181,9 @@
 	glPushMatrix; // save default scaling
 	glLoadIdentity;
 	glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
-//{$IFDEF IPHONEOS}
+{$IFDEF IPHONEOS}
 //	glRotatef(90, 0, 0, 1);
-//{$ENDIF}
+{$ENDIF}
 	glTranslatef(0, -cScreenHeight / 2, 0);
 	end;
 
@@ -1236,7 +1236,13 @@
 begin
 WriteLnToConsole('Freeing progress surface... ');
 FreeTexture(ProgrTex);
-ProgrTex:= nil
+ProgrTex:= nil;
+
+{$IFDEF IPHONEOS}
+// show overlay buttons
+IPH_showControls;
+{$ENDIF}
+
 end;
 
 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);