update sdl functions to latest revision
authorkoda
Sun, 16 May 2010 17:23:30 +0000
changeset 3463 23c50be687a9
parent 3462 4b36933dce1d
child 3464 cdb0ddeb38ba
update sdl functions to latest revision add a grayscale utility to uiimage implement a preliminary support for chatting revert rotation changes for engine lots of code cleanup restored main event loop in hwengine fix some sdl bindings
cocoaTouch/MainMenuViewController.h
cocoaTouch/MainMenuViewController.m
cocoaTouch/MapConfigViewController.m
cocoaTouch/OverlayViewController.h
cocoaTouch/OverlayViewController.m
cocoaTouch/PopoverMenuViewController.m
cocoaTouch/SDLOverrides/SDL_uikitappdelegate.h
cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m
cocoaTouch/SDLOverrides/SDL_uikitwindow.h
cocoaTouch/SDLOverrides/SDL_uikitwindow.m
cocoaTouch/otherSrc/UIImageExtra.h
cocoaTouch/otherSrc/UIImageExtra.m
cocoaTouch/xib/GameConfigViewController-iPad.xib
cocoaTouch/xib/OverlayViewController.xib
hedgewars/PascalExports.pas
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uGame.pas
hedgewars/uLand.pas
hedgewars/uLandObjects.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
hedgewars/uWorld.pas
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
--- a/cocoaTouch/MainMenuViewController.h	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/MainMenuViewController.h	Sun May 16 17:23:30 2010 +0000
@@ -12,18 +12,12 @@
 @class GameConfigViewController;
 
 @interface MainMenuViewController : UIViewController {
-    UIView *cover;
     UILabel *versionLabel;
     SplitViewRootController *splitRootViewController;
     GameConfigViewController *gameConfigViewController;
 }
 
-@property (nonatomic,retain) UIView *cover;
 @property (nonatomic,retain) IBOutlet UILabel *versionLabel;
 
--(void) appear;
--(void) disappear;
--(void) hideBehind;
-
 -(IBAction) switchViews:(id)sender;
 @end
--- a/cocoaTouch/MainMenuViewController.m	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/MainMenuViewController.m	Sun May 16 17:23:30 2010 +0000
@@ -14,7 +14,7 @@
 #import "CommodityFunctions.h"
 
 @implementation MainMenuViewController
-@synthesize cover, versionLabel;
+@synthesize versionLabel;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
 	return rotationManager(interfaceOrientation);
@@ -90,62 +90,24 @@
 }
 
 #pragma mark -
--(void) appear {
-    [[SDLUIKitDelegate sharedAppDelegate].uiwindow addSubview:self.view];
-    [self release];
-    
-    [UIView beginAnimations:@"inserting main controller" context:NULL];
-	[UIView setAnimationDuration:1];
-	self.view.alpha = 1;
-	[UIView commitAnimations];
-    
-    [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(hideBehind) userInfo:nil repeats:NO];
-}
-
--(void) disappear {
-    if (nil != cover)
-        [cover release];
-    
-    [UIView beginAnimations:@"removing main controller" context:NULL];
-	[UIView setAnimationDuration:1];
-	self.view.alpha = 0;
-	[UIView commitAnimations];
-    [self retain];
-    //[self.view removeFromSuperview];
-}
-
-// this is a silly way to hide the sdl contex that remained active
--(void) hideBehind {
-    if (nil == cover) {
-        cover= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-        cover.backgroundColor = [UIColor blackColor];
-    }
-    [[SDLUIKitDelegate sharedAppDelegate].uiwindow insertSubview:cover belowSubview:self.view];
-}
-
-#pragma mark -
 -(IBAction) switchViews:(id) sender {
     UIButton *button = (UIButton *)sender;
     UIAlertView *alert;
-    NSString *configNibName;
-    NSString *debugStr;
-    
+    NSString *debugStr, *configNibName;
+
     switch (button.tag) {
         case 0:
-            if (1) { // bug in UIModalTransitionStylePartialCurl?
-                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-                    configNibName = @"GameConfigViewController-iPad";
-                else
-                    configNibName = @"GameConfigViewController-iPhone";
-
-                gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:configNibName
-                                                                                      bundle:nil];
+            // bug in UIModalTransitionStylePartialCurl, displays the controller awkwardly if it is not allocated every time
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+                configNibName = @"GameConfigViewController-iPad";
+            else
+                configNibName = @"GameConfigViewController-iPhone";
+            
+            gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:configNibName bundle:nil];        
 #ifdef __IPHONE_3_2
-                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-                    gameConfigViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
+            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+                gameConfigViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
 #endif
-            }
-            
             [self presentModalViewController:gameConfigViewController animated:YES];
             break;
         case 2:
@@ -190,7 +152,6 @@
 
 
 -(void) viewDidUnload {
-    self.cover = nil;
     self.versionLabel = nil;
     gameConfigViewController = nil;
     splitRootViewController = nil;
@@ -199,7 +160,6 @@
 
 -(void) dealloc {
     [versionLabel release];
-    [cover release];
     [splitRootViewController release];
     [gameConfigViewController release];
 	[super dealloc];
--- a/cocoaTouch/MapConfigViewController.m	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/MapConfigViewController.m	Sun May 16 17:23:30 2010 +0000
@@ -254,8 +254,9 @@
         // the % prevents a strange bug that occurs sporadically
         NSString *themeName = [self.themeArray objectAtIndex:row % [self.themeArray count]];
         cell.textLabel.text = themeName;
-        UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/Icon.png",THEMES_DIRECTORY(),themeName]];
-        cell.imageView.image = [image scaleToSize:CGSizeMake(40, 40)];
+        UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/Icon.png",THEMES_DIRECTORY(),themeName]];
+        cell.imageView.image = image;
+        [image release];
     } else {
         cell.textLabel.text = [self.mapArray objectAtIndex:row];
         cell.imageView.image = nil;
--- a/cocoaTouch/OverlayViewController.h	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/OverlayViewController.h	Sun May 16 17:23:30 2010 +0000
@@ -20,12 +20,15 @@
     PopoverMenuViewController *popupMenu;
     BOOL isPopoverVisible;
     
+    UITextField *writeChatTextField;
+    
     CGFloat initialDistanceForPinching;
     CGPoint gestureStartPoint;
 }
 
 @property (nonatomic,retain) id popoverController;
 @property (nonatomic,retain) PopoverMenuViewController *popupMenu;
+@property (nonatomic,retain) UITextField *writeChatTextField;
 
 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@@ -38,6 +41,8 @@
 -(void) showPopover;
 -(void) dismissPopover;
 -(void) dimOverlay;
--(void) showMenuAfterwards;
+-(void) activateOverlay;
+-(void) chatAppear;
+-(void) chatDisappear;
 
 @end
--- a/cocoaTouch/OverlayViewController.m	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/OverlayViewController.m	Sun May 16 17:23:30 2010 +0000
@@ -11,11 +11,16 @@
 #import "PascalImports.h"
 #import "CGPointUtils.h"
 #import "SDL_mouse.h"
+#import "SDL_config_iphoneos.h"
 #import "PopoverMenuViewController.h"
 #import "CommodityFunctions.h"
 
+#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
+#define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
+
+
 @implementation OverlayViewController
-@synthesize popoverController, popupMenu;
+@synthesize popoverController, popupMenu, writeChatTextField;
 
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
@@ -33,7 +38,7 @@
     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
     CGRect rect = [[UIScreen mainScreen] bounds];
     CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
-    UIView *sdlView = [[SDLUIKitDelegate sharedAppDelegate].uiwindow viewWithTag:SDL_VIEW_TAG];
+    UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345];
     
     [UIView beginAnimations:@"rotation" context:NULL];
     [UIView setAnimationDuration:0.8f];
@@ -42,21 +47,31 @@
         case UIDeviceOrientationLandscapeLeft:
             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
+            [self chatDisappear];
+            [dimTimer setFireDate:HIDING_TIME_DEFAULT];
             HW_setLandscape(YES);
             break;
         case UIDeviceOrientationLandscapeRight:
             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
+            [self chatDisappear];
+            [dimTimer setFireDate:HIDING_TIME_DEFAULT];
             HW_setLandscape(YES);
             break;
         case UIDeviceOrientationPortrait:
             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270));
             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
+            [self chatAppear];
+            [self activateOverlay];
+            [dimTimer setFireDate:HIDING_TIME_NEVER];
             HW_setLandscape(NO);
             break;
         case UIDeviceOrientationPortraitUpsideDown:
             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
+            [self chatAppear];
+            [self activateOverlay];
+            [dimTimer setFireDate:HIDING_TIME_NEVER];
             HW_setLandscape(NO);
             break;
         default:
@@ -64,10 +79,34 @@
             break;
     }
     self.view.frame = usefulRect;
-    sdlView.frame = usefulRect;
+    //sdlView.frame = usefulRect;
     [UIView commitAnimations];
 }
 
+-(void) chatAppear {
+    if (writeChatTextField == nil) {
+        writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)];
+        writeChatTextField.textColor = [UIColor whiteColor];
+        writeChatTextField.backgroundColor = [UIColor blueColor];
+        writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
+        writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo;
+        writeChatTextField.enablesReturnKeyAutomatically = NO;
+        writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
+        writeChatTextField.keyboardType = UIKeyboardTypeDefault;
+        writeChatTextField.returnKeyType = UIReturnKeyDefault;
+        writeChatTextField.secureTextEntry = NO;	
+        [self.view addSubview:writeChatTextField];
+    }
+    writeChatTextField.alpha = 1;
+    //[self activateOverlay];
+}
+
+-(void) chatDisappear {
+    writeChatTextField.alpha = 0;
+    [writeChatTextField resignFirstResponder];
+    [dimTimer setFireDate:HIDING_TIME_DEFAULT];
+}
+
 -(void) viewDidLoad {
     isPopoverVisible = NO;
     self.view.alpha = 0;
@@ -89,31 +128,6 @@
                                              selector:@selector(dismissPopover)
                                                  name:@"dismissPopover"
                                                object:nil];
-    // present the overlay after 2 seconds
-    [NSTimer scheduledTimerWithTimeInterval:2
-                                     target:self
-                                   selector:@selector(showMenuAfterwards)
-                                   userInfo:nil
-                                    repeats:NO];
-}
-
--(void) viewDidUnload {
-    self.popoverController = nil;
-    self.popupMenu = nil;
-    [super viewDidUnload];
-}
-
--(void) dealloc {
-	[dimTimer invalidate];
-    [popupMenu release];
-    [popoverController release];
-    // dimTimer is autoreleased
-    [super dealloc];
-}
-
-// draws the controller overlay after the sdl window has taken control
--(void) showMenuAfterwards {
-    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
     
     // need to split paths because iphone doesn't rotate (so we don't need to subscribe to any notification
     // nor perform engine actions when rotating
@@ -134,13 +148,29 @@
 	[UIView commitAnimations];
 }
 
+-(void) viewDidUnload {
+    self.writeChatTextField = nil;
+    self.popoverController = nil;
+    self.popupMenu = nil;
+    [super viewDidUnload];
+}
+
+-(void) dealloc {
+	[dimTimer invalidate];
+    [writeChatTextField release];
+    [popupMenu release];
+    [popoverController release];
+    // dimTimer is autoreleased
+    [super dealloc];
+}
+
 // dim the overlay when there's no more input for a certain amount of time
 -(IBAction) buttonReleased:(id) sender {
 	HW_allKeysUp();
-    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
+    [dimTimer setFireDate:HIDING_TIME_DEFAULT];
 }
 
-// nice transition for dimming
+// nice transition for dimming, should be called only by the timer himself
 -(void) dimOverlay {
     [UIView beginAnimations:@"overlay dim" context:NULL];
    	[UIView setAnimationDuration:0.6];
@@ -151,7 +181,7 @@
 // set the overlay visible and put off the timer for enough time
 -(void) activateOverlay {
     self.view.alpha = 1;
-    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
+    [dimTimer setFireDate:HIDING_TIME_NEVER];
 }
 
 // issue certain action based on the tag of the button 
@@ -208,6 +238,7 @@
 // on iphone instead just use the tableViewController directly (and implement manually all animations)
 -(IBAction) showPopover{
     isPopoverVisible = YES;
+    CGRect anchorForPopover;
     Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
     if (popoverControllerClass) {
 #ifdef __IPHONE_3_2
@@ -215,10 +246,15 @@
         popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
         [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
         [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
+
+        if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
+            anchorForPopover = CGRectMake(960, 0, 220, 32);
+        else
+            anchorForPopover = CGRectMake(736, 0, 220, 32);
         
-        [popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32)
+        [popoverController presentPopoverFromRect:anchorForPopover
                                            inView:self.view
-                         permittedArrowDirections:UIPopoverArrowDirectionUp 
+                         permittedArrowDirections:UIPopoverArrowDirectionUp
                                          animated:YES];
 #endif
     } else {
@@ -235,7 +271,7 @@
     popupMenu.tableView.scrollEnabled = NO;
 }
 
-// on ipad just dismiss it, on iphone transtion on the right
+// on ipad just dismiss it, on iphone transtion to the right
 -(void) dismissPopover {
     if (YES == isPopoverVisible) {
         isPopoverVisible = NO;
@@ -252,13 +288,14 @@
         
             [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
             [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
-            
-            //[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
         }
         [self buttonReleased:nil];
     }
 }
 
+-(void) textFieldDoneEditing:(id) sender{
+    [sender resignFirstResponder];
+}
 
 #pragma mark -
 #pragma mark Custom touch event handling
@@ -273,6 +310,10 @@
     if (isPopoverVisible) {
         [self dismissPopover];
     }
+    if (writeChatTextField) {
+        [self.writeChatTextField resignFirstResponder];
+        [dimTimer setFireDate:HIDING_TIME_DEFAULT];
+    }
     
     gestureStartPoint = [touch locationInView:self.view];
         
--- a/cocoaTouch/PopoverMenuViewController.m	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/PopoverMenuViewController.m	Sun May 16 17:23:30 2010 +0000
@@ -10,6 +10,7 @@
 #import "PopoverMenuViewController.h"
 #import "PascalImports.h"
 #import "CommodityFunctions.h"
+#import "SDL_sysvideo.h"
 
 @implementation PopoverMenuViewController
 @synthesize menuList;
@@ -75,7 +76,12 @@
             break;
         case 1:
 			HW_chat();
-            //SDL_iPhoneKeyboardShow([SDLUIKitDelegate sharedAppDelegate].window);
+            /*
+            SDL_VideoDevice *_this = SDL_GetVideoDevice();
+            SDL_VideoDisplay *display = &_this->displays[0];
+            SDL_Window *window = display->windows;
+            SDL_iPhoneKeyboardShow(window);
+            */
             break;
         case 2:
             // expand the view (and table) so that the actionsheet can be selected on the iPhone
--- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.h	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.h	Sun May 16 17:23:30 2010 +0000
@@ -1,6 +1,6 @@
 /*
     SDL - Simple DirectMedia Layer
-    Copyright (C) 1997-2009 Sam Lantinga
+    Copyright (C) 1997-2010 Sam Lantinga
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -16,27 +16,20 @@
     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
+    Sam Lantinga
+    slouken@libsdl.org
 */
 
 #import <UIKit/UIKit.h>
-#import "SDL_video.h"
+#import "SDL_uikitopenglview.h"
 
 @class MainMenuViewController;
 @class OverlayViewController;
 
-@interface SDLUIKitDelegate:NSObject <UIApplicationDelegate> {
-	SDL_Window *window;
-	UIWindow *uiwindow;
-
-	MainMenuViewController *mainViewController;
+@interface SDLUIKitDelegate:NSObject<UIApplicationDelegate> {
+    MainMenuViewController *mainViewController;
     BOOL isInGame;
 }
-
-@property (readwrite, assign) SDL_Window *window;
-@property (readwrite, retain) UIWindow *uiwindow;
-
 +(SDLUIKitDelegate *)sharedAppDelegate;
 -(void) startSDLgame;
 
--- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Sun May 16 17:23:30 2010 +0000
@@ -20,10 +20,11 @@
  slouken@libsdl.org, vittorio.giovara@gmail.com
 */
 
-#import <pthread.h>
 #import "SDL_uikitappdelegate.h"
 #import "SDL_uikitopenglview.h"
+#import "SDL_uikitwindow.h"
 #import "SDL_events_c.h"
+#import "../SDL_sysvideo.h"
 #import "jumphack.h"
 #import "SDL_video.h"
 #import "GameSetup.h"
@@ -54,7 +55,6 @@
 }
 
 @implementation SDLUIKitDelegate
-@synthesize uiwindow, window;
 
 // convenience method
 +(SDLUIKitDelegate *)sharedAppDelegate {
@@ -64,70 +64,74 @@
 
 -(id) init {
 	if (self = [super init]){
-        self.uiwindow = nil;
-        self.window = NULL;
         mainViewController = nil;
         isInGame = NO;
-        return self;
-    } else 
-        return nil;
+    }
+    return self;
 }
 
 -(void) dealloc {
-    SDL_DestroyWindow(self.window);
     [mainViewController release];
-	[uiwindow release];
 	[super dealloc];
 }
 
 // main routine for calling the actual game engine
 -(IBAction) startSDLgame {
-    [mainViewController disappear];
+    [UIView beginAnimations:@"removing main controller" context:NULL];
+	[UIView setAnimationDuration:1];
+	mainViewController.view.alpha = 0;
+	[UIView commitAnimations];
 
     // pull out useful configuration info from various files
 	GameSetup *setup = [[GameSetup alloc] init];
 	[setup startThread:@"engineProtocol"];
 	const char **gameArgs = [setup getSettings];
 	[setup release];
-    
-    OverlayViewController *overlayController;
-    // overlay with controls, become visible after 2 seconds
-    overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
+
+    //NSLog(@"%@",[[[UIApplication sharedApplication] windows]);
+    // since the sdlwindow is not yet created, we add the overlayController with a delay
+    [self performSelector:@selector(later) withObject:nil afterDelay:4];
     
-    [uiwindow addSubview:overlayController.view];
-    [overlayController release];
-
+    // this is the pascal fuction that starts the game (wrapped around isInGame)
     isInGame = YES;
-	Game(gameArgs); // this is the pascal fuction that starts the game
+	Game(gameArgs);
     isInGame = NO;
     
     free(gameArgs);
-    [overlayController.view removeFromSuperview];
+    //[overlayController.view removeFromSuperview];
     
-    [mainViewController appear];
+    [UIView beginAnimations:@"inserting main controller" context:NULL];
+	[UIView setAnimationDuration:1];
+	mainViewController.view.alpha = 1;
+	[UIView commitAnimations];
 }
 
-// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib)
+-(void) later {
+    // overlay with controls, become visible after 4 seconds, with a transparency effect
+    OverlayViewController *overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
+    
+    [[[UIApplication sharedApplication] keyWindow] addSubview:overlayController.view];
+    [overlayController release];
+}
+
+// override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib)
 -(void) applicationDidFinishLaunching:(UIApplication *)application {
-	//[application setStatusBarHidden:YES animated:NO];
-    //[application setStatusBarHidden:YES withAnimation:NO];
     [application setStatusBarHidden:YES];
     [application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];  
     
-	self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-	self.uiwindow.backgroundColor = [UIColor blackColor];
+    UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+	uiwindow.backgroundColor = [UIColor blackColor];
 	
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
         mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil];
     else
         mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil];
+
 	[uiwindow addSubview:mainViewController.view];
-    
+	[uiwindow makeKeyAndVisible];
+
 	// Set working directory to resource path
 	[[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]];
-
-	[uiwindow makeKeyAndVisible];
-	[uiwindow layoutSubviews];
 }
 
 -(void) applicationWillTerminate:(UIApplication *)application {
@@ -141,14 +145,42 @@
 
 -(void) applicationWillResignActive:(UIApplication *)application {
 	//NSLog(@"%@", NSStringFromSelector(_cmd));
-    if (isInGame) HW_pause();
-	//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+    if (isInGame) {
+        HW_pause();
+        
+        // Send every window on every screen a MINIMIZED event.
+        SDL_VideoDevice *_this = SDL_GetVideoDevice();
+        if (!_this)
+            return;
+
+        int i;
+        for (i = 0; i < _this->num_displays; i++) {
+            const SDL_VideoDisplay *display = &_this->displays[i];
+            SDL_Window *window;
+            for (window = display->windows; window != nil; window = window->next)
+                SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+        }
+    }
 }
 
 -(void) applicationDidBecomeActive:(UIApplication *)application {
 	//NSLog(@"%@", NSStringFromSelector(_cmd));
-    if (isInGame) HW_pause();
-	//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+    if (isInGame) {
+        HW_pause();
+
+        // Send every window on every screen a RESTORED event.
+        SDL_VideoDevice *_this = SDL_GetVideoDevice();
+        if (!_this)
+            return;
+
+        int i;
+        for (i = 0; i < _this->num_displays; i++) {
+            const SDL_VideoDisplay *display = &_this->displays[i];
+            SDL_Window *window;
+            for (window = display->windows; window != nil; window = window->next)
+                SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+        }
+    }
 }
 
 @end
--- a/cocoaTouch/SDLOverrides/SDL_uikitwindow.h	Sat May 15 09:21:25 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- 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 "SDL_config.h"
-#import "SDL_uikitopenglview.h"
-//#import "../SDL_sysvideo.h"
-
-typedef struct SDL_WindowData SDL_WindowData;
-
-extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
-extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
-
-@class UIWindow;
-
-struct SDL_WindowData
-{
-    SDL_Window *window;
-    UIWindow *uiwindow;
-    SDL_uikitopenglview *view;
-};
-
-/* vi: set ts=4 sw=4 expandtab: */
--- a/cocoaTouch/SDLOverrides/SDL_uikitwindow.m	Sat May 15 09:21:25 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/*
- 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
- */
-#include "SDL_config.h"
-
-#include "SDL_video.h"
-#include "SDL_mouse.h"
-#include "../SDL_sysvideo.h"
-#include "../SDL_pixels_c.h"
-#include "../../events/SDL_events_c.h"
-
-#include "SDL_uikitvideo.h"
-#include "SDL_uikitevents.h"
-#include "SDL_uikitwindow.h"
-#import "SDL_uikitappdelegate.h"
-
-#import "SDL_uikitopenglview.h"
-#import "SDL_renderer_sw.h"
-
-#include <UIKit/UIKit.h>
-#include <Foundation/Foundation.h>
-
-static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) {
-	SDL_WindowData *data;
-	
-	/* Allocate the window data */
-	data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
-	if (!data) {
-		SDL_OutOfMemory();
-		return -1;
-	}
-	data->window = window;
-	data->uiwindow = uiwindow;
-	data->view = nil;
-	
-	/* Fill in the SDL window with the window data */
-	{
-		window->x = 0;
-		window->y = 0;
-		window->w = (int)uiwindow.frame.size.width;
-		window->h = (int)uiwindow.frame.size.height;
-	}
-	
-	window->driverdata = data;
-	
-	window->flags &= ~SDL_WINDOW_RESIZABLE;		/* window is NEVER resizeable */
-	window->flags |= SDL_WINDOW_OPENGL;			/* window is always OpenGL */
-	window->flags |= SDL_WINDOW_FULLSCREEN;		/* window is always fullscreen */
-	window->flags |= SDL_WINDOW_SHOWN;			/* only one window on iPod touch, always shown */
-	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */	
-	
-	/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
-	if (window->flags & SDL_WINDOW_BORDERLESS) {
-		[UIApplication sharedApplication].statusBarHidden = YES;
-	}
-	else {
-		[UIApplication sharedApplication].statusBarHidden = NO;
-	}
-	
-	return 0;
-	
-}
-
-int UIKit_CreateWindow(_THIS, SDL_Window *window) {
-	/* We currently only handle single window applications on iPhone 
-	if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
-		SDL_SetError("Window already exists, no multi-window support.");
-		return -1;
-	}*/
-	
-	// ignore the size user requested, and make a fullscreen window 
-	//UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-	
-	// since we handle the window with a NIB, we don't need the initialization above
-	if (SetupWindowData(_this, window, [SDLUIKitDelegate sharedAppDelegate].uiwindow, SDL_TRUE) < 0) {
-		SDL_SetError("SetupWindowData() failed");
-		//[uiwindow release];
-		return -1;
-	}	
-	
-	// This saves the main window in the app delegate so event callbacks can do stuff on the window.
-	// This assumes a single window application design and needs to be fixed for multiple windows.
-	[SDLUIKitDelegate sharedAppDelegate].window = window;
-
-	//[SDLUIKitDelegate sharedAppDelegate].uiwindow = uiwindow;
-	//[uiwindow release]; /* release the window (the app delegate has retained it) */
-	
-	return 1;
-	
-}
-
-void UIKit_DestroyWindow(_THIS, SDL_Window * window) {
-	/* don't worry, the delegate will automatically release the window */
-	
-	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
-	if (data) {
-		SDL_free( window->driverdata );
-	}
-
-	/* this will also destroy the window */
-	[SDLUIKitDelegate sharedAppDelegate].window = NULL;
-	//[SDLUIKitDelegate sharedAppDelegate].uiwindow = nil;
-
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
--- a/cocoaTouch/otherSrc/UIImageExtra.h	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/otherSrc/UIImageExtra.h	Sun May 16 17:23:30 2010 +0000
@@ -15,5 +15,6 @@
 -(UIImage *)mergeWith:(UIImage *)secondImage atPoint:(CGPoint) secondImagePoint;
 -(UIImage *)mergeWith:(UIImage *)secondImage atPoint:(CGPoint) secondImagePoint atSize:(CGSize) resultingSize;
 -(id) initWithContentsOfFile:(NSString *)path andCutAt:(CGRect) rect;
+-(UIImage *)convertImageToGrayScale:(UIImage *)image;
 
 @end
--- a/cocoaTouch/otherSrc/UIImageExtra.m	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/otherSrc/UIImageExtra.m	Sun May 16 17:23:30 2010 +0000
@@ -77,5 +77,34 @@
         return nil;
     }
 }
+
+-(UIImage *)convertImageToGrayScale:(UIImage *)image {
+  // Create image rectangle with current image width/height
+  CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
+ 
+  // Grayscale color space
+  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
+ 
+  // Create bitmap content with current image size and grayscale colorspace
+  CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone);
+ 
+  // Draw image into current context, with specified rectangle
+  // using previously defined context (with grayscale colorspace)
+  CGContextDrawImage(context, imageRect, [image CGImage]);
+ 
+  // Create bitmap image info from pixel data in current context
+  CGImageRef imageRef = CGBitmapContextCreateImage(context);
+ 
+  // Create a new UIImage object  
+  UIImage *newImage = [UIImage imageWithCGImage:imageRef];
+ 
+  // Release colorspace, context and bitmap information
+  CGColorSpaceRelease(colorSpace);
+  CGContextRelease(context);
+  CFRelease(imageRef);
+ 
+  // Return the new grayscale image
+  return newImage;
+}
  
 @end
--- a/cocoaTouch/xib/GameConfigViewController-iPad.xib	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/xib/GameConfigViewController-iPad.xib	Sun May 16 17:23:30 2010 +0000
@@ -190,7 +190,7 @@
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-					<string>{{252, 106}, {1024, 768}}</string>
+					<string>{{285, -28}, {1024, 768}}</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				</object>
--- a/cocoaTouch/xib/OverlayViewController.xib	Sat May 15 09:21:25 2010 +0000
+++ b/cocoaTouch/xib/OverlayViewController.xib	Sun May 16 17:23:30 2010 +0000
@@ -104,7 +104,7 @@
 						<reference key="NSSuperview" ref="191373211"/>
 						<bool key="IBUIOpaque">NO</bool>
 						<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
-						<int key="IBUITag">6</int>
+						<int key="IBUITag">5</int>
 						<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
 						<int key="IBUIContentHorizontalAlignment">0</int>
 						<int key="IBUIContentVerticalAlignment">0</int>
@@ -127,7 +127,7 @@
 						<reference key="NSSuperview" ref="191373211"/>
 						<bool key="IBUIOpaque">NO</bool>
 						<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
-						<int key="IBUITag">5</int>
+						<int key="IBUITag">6</int>
 						<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
 						<int key="IBUIContentHorizontalAlignment">0</int>
 						<int key="IBUIContentVerticalAlignment">0</int>
--- a/hedgewars/PascalExports.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/PascalExports.pas	Sun May 16 17:23:30 2010 +0000
@@ -13,7 +13,7 @@
 unit PascalExports;
 
 interface
-uses uKeys, uConsole, uStore, GLunit, uMisc, uWorld, hwengine;
+uses uKeys, GLunit, uWorld, hwengine;
 
 {$INCLUDE "config.inc"}
 
@@ -140,23 +140,14 @@
 end;
 
 procedure HW_setLandscape(landscape: boolean); cdecl; export;
-var tmp:LongInt;
 begin
     if landscape then
     begin
-        rotationQt:= -90;
-        uStore.wScreen:= cScreenWidth;
-        uStore.hScreen:= cScreenHeight;
-        uWorld.wScreen:= cScreenWidth;
-        uWorld.hScreen:= cScreenHeight;
+        cOffsetY:= 0;
     end
     else
     begin
-        rotationQt:= 270;
-        uStore.wScreen:= cScreenHeight;
-        uStore.hScreen:= cScreenWidth;
-        uWorld.wScreen:= cScreenHeight;
-        uWorld.hScreen:= cScreenWidth;
+        cOffsetY:= 120;
     end;
 end;
 {$ENDIF}
--- a/hedgewars/SDLh.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/SDLh.pas	Sun May 16 17:23:30 2010 +0000
@@ -113,7 +113,8 @@
     SDL_APPINPUTFOCUS    = 2;
     SDL_BUTTON_WHEELUP   = 4;
     SDL_BUTTON_WHEELDOWN = 5;
-        
+
+
 {*begin SDL_Event binding*}
 
 {$IFDEF SDL13}
@@ -196,7 +197,7 @@
 {$ENDIF}
 
 {$IFDEF SDL13}
-// SDL_WindowFlags (enum)
+    // SDL_WindowFlags (enum)
     SDL_WINDOW_FULLSCREEN = $00000001;         //*< fullscreen window, implies borderless */
     SDL_WINDOW_OPENGL = $00000002;             //*< window usable with OpenGL context */
     SDL_WINDOW_SHOWN = $00000004;              //*< window is visible */
@@ -208,6 +209,22 @@
     SDL_WINDOW_INPUT_FOCUS = $00000200;        //*< window has input focus */
     SDL_WINDOW_MOUSE_FOCUS = $00000400;        //*< window has mouse focus */
     SDL_WINDOW_FOREIGN = $00000800;            //*< window not created by SDL */
+    
+    // SDL_WindowEventID (enum)
+    SDL_WINDOWEVENT_NONE = 0;            //*< Never used
+    SDL_WINDOWEVENT_SHOWN = 1;           //*< Window has been shown
+    SDL_WINDOWEVENT_HIDDEN = 2;          //*< Window has been hidden
+    SDL_WINDOWEVENT_EXPOSED = 3;         //*< Window has been exposed and should be redrawn 
+    SDL_WINDOWEVENT_MOVED = 4;           //*< Window has been moved to data1, data2
+    SDL_WINDOWEVENT_RESIZED = 5;         //*< Window size changed to data1xdata2
+    SDL_WINDOWEVENT_MINIMIZED = 6;       //*< Window has been minimized
+    SDL_WINDOWEVENT_MAXIMIZED = 7;       //*< Window has been maximized
+    SDL_WINDOWEVENT_RESTORED = 8;        //*< Window has been restored to normal size and position
+    SDL_WINDOWEVENT_ENTER = 9;           //*< Window has gained mouse focus
+    SDL_WINDOWEVENT_LEAVE = 10;          //*< Window has lost mouse focus
+    SDL_WINDOWEVENT_FOCUS_GAINED = 11;   //*< Window has gained keyboard focus
+    SDL_WINDOWEVENT_FOCUS_LOST = 12;     //*< Window has lost keyboard focus
+    SDL_WINDOWEVENT_CLOSE = 13;          //*< The window manager requests that the window be closed */
 {$ENDIF}
 
     {* SDL_mixer *}
@@ -336,13 +353,6 @@
             2: (unknown: TUnknown);
             end;
 
-    TSDL_KeySym = record
-        scancode: Byte;
-        sym: Longword;
-        modifier: Longword;
-        unicode: Word;
-        end;
-
 
 {* SDL_Event type definition *}
 
@@ -357,9 +367,23 @@
         padding1, padding2, padding3: byte;
         data1, data2: LongInt;
         end;
+        
+    TSDL_KeySym = record
+        scancode,
+        sym,
+        modifier,
+        unicode: LongInt;
+        end;
 
 // implement SDL_TextEditingEvent + SDL_TextInputEvent for sdl13
 {$ELSE}
+    TSDL_KeySym = record
+        scancode: Byte;
+        sym: Longword;
+        modifier: Longword;
+        unicode: Word;
+        end;
+
     // these two are present in sdl1.3 but only for backward compatibility
     // and in 1.3 type_ is LongInt, not byte
     TSDL_ActiveEvent = record
@@ -404,7 +428,6 @@
         end;
 
     TSDL_MouseButtonEvent = record
-
 {$IFDEF SDL13}
         _type: LongInt;
         windowID: LongInt;
@@ -432,7 +455,11 @@
 {$ENDIF}
 
     TSDL_JoyAxisEvent = record
+{$IFDEF SDL13}
+        type_: LongInt;
+{$ELSE}
         type_: Byte;
+{$ENDIF}
         which: Byte;
         axis: Byte;
 {$IFDEF SDL13}
@@ -486,11 +513,11 @@
 
     PSDL_Event = ^TSDL_Event;
     TSDL_Event = record
-        case Byte of
 {$IFDEF SDL13}
-            SDL_FIRSTEVENT: (type_: byte);
+        case LongInt of
+            SDL_FIRSTEVENT: (type_: LongInt);
             SDL_QUITEV: (quit: TSDL_QuitEvent);
-            SDL_WINDOWEVENT: (active: TSDL_WindowEvent);
+            SDL_WINDOWEVENT: (wevent: TSDL_WindowEvent);
             SDL_KEYDOWN,
             SDL_KEYUP: (key: TSDL_KeyboardEvent);
             SDL_TEXTEDITING,
@@ -505,6 +532,7 @@
             SDL_JOYBUTTONDOWN,
             SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
 {$ELSE}
+        case Byte of
             SDL_NOEVENT: (type_: byte);
             SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent);
             SDL_KEYDOWN,
--- a/hedgewars/hwengine.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/hwengine.pas	Sun May 16 17:23:30 2010 +0000
@@ -178,12 +178,11 @@
 ///////////////////
 procedure MainLoop; 
 var PrevTime, CurrTime: Longword;
-    {$IFNDEF IPHONEOS}event: TSDL_Event;{$ENDIF}
+    event: TSDL_Event;
 begin
     PrevTime:= SDL_GetTicks;
     while isTerminated = false do
     begin
-{$IFNDEF IPHONEOS}
 // have to remove this cycle because otherwise it segfaults at exit
         while SDL_PollEvent(@event) <> 0 do
         begin
@@ -191,22 +190,26 @@
                 SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
 {$IFDEF SDL13}
                 SDL_WINDOWEVENT:
+                    if event.wevent.event = SDL_WINDOWEVENT_SHOWN then
+                        cHasFocus:= true;
 {$ELSE}
                 SDL_ACTIVEEVENT:
-{$ENDIF}
                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
                         cHasFocus:= event.active.gain = 1;
+{$ENDIF}
+{$IFNDEF IPHONEOS}
                 //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
+{$ENDIF}
                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
                 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
                 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
                 SDL_QUITEV: isTerminated:= true
-            end; // end case event.type_ of
-        end; // end while SDL_PollEvent(@event) <> 0 do
-{$ENDIF}
+            end; // end case event.type_
+        end; // end while SDL_PollEvent(@event) <> 0
+
         if isTerminated = false then
         begin
             CurrTime:= SDL_GetTicks;
@@ -402,7 +405,6 @@
     uScript.freeModule;
     // uMisc closes the debug log.
     uMisc.freeModule;
-
 end;
 
 /////////////////////////
--- a/hedgewars/uGame.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/uGame.pas	Sun May 16 17:23:30 2010 +0000
@@ -26,7 +26,7 @@
 ////////////////////
    implementation
 ////////////////////
-uses uMisc, uConsts, uKeys, uTeams, uIO, uAI, uGears, uScript;
+uses uMisc, uConsts, uTeams, uIO, uAI, uGears, uScript;
 
 procedure DoGameTick(Lag: LongInt);
 var i: LongInt;
--- a/hedgewars/uLand.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/uLand.pas	Sun May 16 17:23:30 2010 +0000
@@ -1212,15 +1212,19 @@
 procedure GenMap;
 var x, y, w, c: Longword;
 begin
-hasBorder:= false;
+    hasBorder:= false;
 
-LoadThemeConfig;
-isMap:= false;
-if (GameFlags and gfForts) = 0 then
-   if Pathz[ptMapCurrent] <> '' then LoadMap
-                                else GenLandSurface
-                               else MakeFortsMap;
-AddProgress;
+    LoadThemeConfig;
+    isMap:= false;
+    if (GameFlags and gfForts) = 0 then
+        if Pathz[ptMapCurrent] <> '' then
+            LoadMap
+        else
+            GenLandSurface
+    else
+        MakeFortsMap;
+
+    AddProgress;
 
 {$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF}
 
--- a/hedgewars/uLandObjects.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/uLandObjects.pas	Sun May 16 17:23:30 2010 +0000
@@ -518,18 +518,19 @@
 
 procedure LoadThemeConfig;
 begin
-ReadThemeInfo(ThemeObjects, SprayObjects)
+    ReadThemeInfo(ThemeObjects, SprayObjects)
 end;
 
 procedure FreeLandObjects();
 var i: Longword;
 begin
-for i:= 0 to Pred(MAXTHEMEOBJECTS) do
-    if ThemeObjects.objs[i].Surf <> nil then
-        SDL_FreeSurface(ThemeObjects.objs[i].Surf);
-for i:= 0 to Pred(MAXTHEMEOBJECTS) do
-    if SprayObjects.objs[i].Surf <> nil then
-        SDL_FreeSurface(SprayObjects.objs[i].Surf);
+    for i:= 0 to Pred(MAXTHEMEOBJECTS) do
+    begin
+        if ThemeObjects.objs[i].Surf <> nil then
+            SDL_FreeSurface(ThemeObjects.objs[i].Surf);
+        if SprayObjects.objs[i].Surf <> nil then
+            SDL_FreeSurface(SprayObjects.objs[i].Surf);
+    end;
 end;
 
 end.
--- a/hedgewars/uMisc.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/uMisc.pas	Sun May 16 17:23:30 2010 +0000
@@ -170,7 +170,7 @@
 {$ENDIF}
 
 implementation
-uses Math, uConsole, uStore, uIO, uSound, typinfo;
+uses Math, uConsole, uStore, uIO, typinfo;
 
 var KBnum: Longword;
 {$IFDEF DEBUGFILE}
--- a/hedgewars/uStore.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/uStore.pas	Sun May 16 17:23:30 2010 +0000
@@ -84,7 +84,7 @@
 procedure Tint(c: Longword); inline;
 
 implementation
-uses uMisc, uConsole, uLocale{$IFDEF IPHONEOS}, PascalExports{$ENDIF};
+uses uMisc, uConsole, uLocale;
 
 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
 
--- a/hedgewars/uWorld.pas	Sat May 15 09:21:25 2010 +0000
+++ b/hedgewars/uWorld.pas	Sun May 16 17:23:30 2010 +0000
@@ -37,8 +37,7 @@
 {$IFDEF COUNTTICKS}
     cntTicks: LongWord;
 {$ENDIF}
-    wScreen: LongInt;
-    hScreen: LongInt;
+    cOffsetY: LongInt;
     
 procedure initModule;
 procedure freeModule;
@@ -97,12 +96,6 @@
     end;
 begin
     missionTimer:= 0;
-    // initialized here because when initModule is called cScreenWidth/Height are not yet set
-    if (uWorld.wScreen = 0) and (uWorld.hScreen = 0) then
-    begin
-        uWorld.wScreen:= cScreenWidth; 
-        uWorld.hScreen:= cScreenHeight;
-    end;
 
 if (GameFlags and gfRandomOrder) <> 0 then  // shuffle them up a bit
    begin
@@ -241,7 +234,8 @@
 
 {$IFDEF IPHONEOS}
 Slot:= cMaxSlotIndex;
-y:= AMyOffset;
+x:= x - cOffsetY;
+y:= AMyOffset + 123;
 dec(y, BORDERSIZE);
 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 0);
 for i:= 0 to cMaxSlotAmmoIndex do
@@ -403,12 +397,12 @@
     WaterColorArray[2].a := Alpha;
     WaterColorArray[3].a := Alpha;
 
-    lw:= wScreen / cScaleFactor;
-    lh:= trunc(hScreen / cScaleFactor) + hScreen div 2 + 16;
+    lw:= cScreenWidth / cScaleFactor;
+    lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
     
     // Water
     r.y:= OffsetY + WorldDy + cWaterLine;
-    if WorldDy < trunc(hScreen / cScaleFactor) + hScreen div 2 - cWaterLine then
+    if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
     begin
         if r.y < 0 then
             r.y:= 0;
@@ -443,7 +437,7 @@
 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
     lw, waves, shift: GLfloat;
 begin
-lw:= wScreen / cScaleFactor;
+lw:= cScreenWidth / cScaleFactor;
 waves:= lw * 2 / cWaveWidth;
 
 Tint(LongInt(tnt) * WaterColorArray[2].r div 255 + 255 - tnt,
@@ -667,20 +661,21 @@
 {$ELSE}
 offsetX:= 48;
 {$ENDIF}
+offsetY:= cOffsetY;
 if TurnTimeLeft <> 0 then
    begin
    i:= Succ(Pred(TurnTimeLeft) div 1000);
    if i>99 then t:= 112
       else if i>9 then t:= 96
                   else t:= 80;
-   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t, cScreenHeight - offsetX, 1);
+   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1);
    while i > 0 do
          begin
          dec(t, 32);
-         DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t, cScreenHeight - offsetX, i mod 10);
+         DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10);
          i:= i div 10
          end;
-   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4, cScreenHeight - offsetX, 0);
+   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
    end;
 
 {$IFNDEF IPHONEOS}
@@ -856,10 +851,11 @@
 
 // fps
 {$IFDEF IPHONEOS}
-offset:= 8;
+offsetX:= 8;
 {$ELSE}
-offset:= 10;
+offsetX:= 10;
 {$ENDIF}
+offsetY:= cOffsetY;
 inc(Frames);
 
 if cShowFPS or (GameType = gmtDemo) then inc(CountTicks, Lag);
@@ -883,7 +879,7 @@
    end;
 
 if timeTexture <> nil then
-   DrawTexture((cScreenWidth shr 1) - 10 - timeTexture^.w, offset + timeTexture^.h+5, timeTexture);
+   DrawTexture((cScreenWidth shr 1) - 20 - timeTexture^.w - offsetY, offsetX + timeTexture^.h+5, timeTexture);
 
 if cShowFPS then
    begin
@@ -900,7 +896,7 @@
       SDL_FreeSurface(tmpSurface)
       end;
    if fpsTexture <> nil then
-      DrawTexture((cScreenWidth shr 1) - 50, offset, fpsTexture);
+      DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture);
    end;
 
 if CountTicks >= 1000 then CountTicks:= 0;
@@ -1025,17 +1021,17 @@
 
 if AMxShift < AMWidth then
     begin
-    {$IFDEF IPHONEOS}
+{$IFDEF IPHONEOS}
     if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth;
     if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
     if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize;
     if CursorPoint.Y > cScreenHeight - AMyOffset then CursorPoint.Y:= cScreenHeight - AMyOffset;
-    {$ELSE}
+{$ELSE}
     if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize;
     if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
     if CursorPoint.Y > AMyOffset + (SlotsNum + 1) * AMSlotSize then CursorPoint.Y:= AMyOffset + (SlotsNum + 1) * AMSlotSize;
     if CursorPoint.Y < AMyOffset + AMSlotSize then CursorPoint.Y:= AMyOffset + AMSlotSize;
-    {$ENDIF}
+{$ENDIF}
     prevPoint:= CursorPoint;
     if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
     exit
@@ -1140,10 +1136,6 @@
     WorldDx:= -512;
     WorldDy:= -256;
     
-    // really initalized in initWorld
-    uWorld.wScreen:= 0; 
-    uWorld.hScreen:= 0;
-    
     FPS:= 0;
     CountTicks:= 0;
     SoundTimerTicks:= 0;
@@ -1151,6 +1143,7 @@
     prevPoint.Y:= 0;
     missionTimer:= 0;
     missionTex:= nil;
+    cOffsetY:= 0;
     
     FillChar(Captions, sizeof(Captions), 0)
 end;
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sat May 15 09:21:25 2010 +0000
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sun May 16 17:23:30 2010 +0000
@@ -78,7 +78,6 @@
 		6179883D114AA34C00BA94A9 /* uWorld.pas in Sources */ = {isa = PBXBuildFile; fileRef = 6179880F114AA34C00BA94A9 /* uWorld.pas */; };
 		6179885C114AA48A00BA94A9 /* CGPointUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 61798856114AA48A00BA94A9 /* CGPointUtils.c */; };
 		61798869114AA4AA00BA94A9 /* SDL_uikitappdelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 61798864114AA4AA00BA94A9 /* SDL_uikitappdelegate.m */; };
-		6179886B114AA4AA00BA94A9 /* SDL_uikitwindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 61798868114AA4AA00BA94A9 /* SDL_uikitwindow.m */; };
 		6179887D114AA4D000BA94A9 /* MainMenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6179886F114AA4D000BA94A9 /* MainMenuViewController.m */; };
 		61798889114AA4E600BA94A9 /* GameSetup.m in Sources */ = {isa = PBXBuildFile; fileRef = 61798888114AA4E600BA94A9 /* GameSetup.m */; };
 		617988DB114AAA4200BA94A9 /* libSDLiPhoneOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 617988DA114AAA3900BA94A9 /* libSDLiPhoneOS.a */; };
@@ -1076,7 +1075,6 @@
 				6179883D114AA34C00BA94A9 /* uWorld.pas in Sources */,
 				6179885C114AA48A00BA94A9 /* CGPointUtils.c in Sources */,
 				61798869114AA4AA00BA94A9 /* SDL_uikitappdelegate.m in Sources */,
-				6179886B114AA4AA00BA94A9 /* SDL_uikitwindow.m in Sources */,
 				6179887D114AA4D000BA94A9 /* MainMenuViewController.m in Sources */,
 				61798889114AA4E600BA94A9 /* GameSetup.m in Sources */,
 				61CE250D115E749A0098C467 /* OverlayViewController.m in Sources */,