move objc overlay creation after sdlwindow has been created
authorkoda
Wed, 02 Nov 2011 09:24:18 +0100
changeset 6259 02765411a912
parent 6258 ba9defb98a70
child 6260 025d50a6aeb0
move objc overlay creation after sdlwindow has been created
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/ObjcExports.m
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/SDL-50560ca58f80.patch
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h	Mon Oct 31 21:04:18 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h	Wed Nov 02 09:24:18 2011 +0100
@@ -26,7 +26,6 @@
 
 @interface GameInterfaceBridge : NSObject <EngineProtocolDelegate> {
     UIViewController *parentController;
-    OverlayViewController *overlayController;
 
     NSString *savePath;
     EngineProtocolNetwork *engineProtocol;
@@ -37,7 +36,6 @@
 @property (assign) UIViewController *parentController;
 @property (nonatomic,retain) NSString *savePath;
 
-@property (nonatomic,retain) OverlayViewController *overlayController;
 @property (nonatomic,retain) EngineProtocolNetwork *engineProtocol;
 
 @property (assign) NSInteger ipcPort;
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Mon Oct 31 21:04:18 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Wed Nov 02 09:24:18 2011 +0100
@@ -27,7 +27,7 @@
 #import "ObjcExports.h"
 
 @implementation GameInterfaceBridge
-@synthesize parentController, savePath, overlayController, engineProtocol, ipcPort;
+@synthesize parentController, savePath, engineProtocol, ipcPort;
 
 -(id) initWithController:(id) viewController {
     if (self = [super init]) {
@@ -36,8 +36,6 @@
 
         self.parentController = (UIViewController *)viewController;
         self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
-
-        self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
     }
     return self;
 }
@@ -45,19 +43,10 @@
 -(void) dealloc {
     releaseAndNil(engineProtocol);
     releaseAndNil(savePath);
-    releaseAndNil(overlayController);
     [super dealloc];
 }
 
 #pragma mark -
-// overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created
--(void) displayOverlayLater:(id) object {
-    // in order to get rotation events we have to insert the view inside the first view of the second window
-    // when multihead we have to make sure that overlay is displayed in the touch-enabled window
-    UIView *injected = (IS_DUALHEAD() ? self.parentController.view : UIVIEW_HW_SDLVIEW);
-    [injected addSubview:self.overlayController.view];
-}
-
 // main routine for calling the actual game engine
 -(void) engineLaunch {
     const char *gameArgs[11];
@@ -143,9 +132,6 @@
     } else
         blackView.alpha = 1;
 
-    // prepare options for overlay and add it to the future sdl uiwindow
-    [self performSelector:@selector(displayOverlayLater:) withObject:nil afterDelay:3];
-
     // keep track of uncompleted games
     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
     [userDefaults setObject:self.savePath forKey:@"savedGamePath"];
@@ -171,7 +157,7 @@
     [blackView release];
 
     // the overlay is not needed any more and can be removed
-    [self.overlayController removeOverlay];
+    [[OverlayViewController mainOverlay] removeOverlay];
 
     // warn our host that it's going to be visible again
     [self.parentController viewWillAppear:YES];
--- a/project_files/HedgewarsMobile/Classes/ObjcExports.m	Mon Oct 31 21:04:18 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/ObjcExports.m	Wed Nov 02 09:24:18 2011 +0100
@@ -23,6 +23,8 @@
 #import "OverlayViewController.h"
 #import "AmmoMenuViewController.h"
 
+//FIXME: add a proper #import when this is exposed in SDL
+extern UIView *SDL_getUikitView(void *);
 
 // cache the grenade time
 static NSInteger grenadeTime;
@@ -50,7 +52,10 @@
 
 void startLoadingIndicator() {
     // this is the first ojbc function called by engine, so we have to initialize some variables here
-    overlay_instance = [OverlayViewController mainOverlay];
+    overlay_instance = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
+    // in order to get rotation events we have to insert the view inside the first view of the second window
+    //TODO: when multihead make sure that overlay is displayed in the touch-enabled window
+    [SDL_getUikitView(HW_getSDLWindow()) addSubview:overlay_instance.view];
     grenadeTime = 2;
 
     if ([HWUtils gameType] == gtSave) {
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Mon Oct 31 21:04:18 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Wed Nov 02 09:24:18 2011 +0100
@@ -204,6 +204,7 @@
     [self.popupMenu performSelectorOnMainThread:@selector(dismiss) withObject:nil waitUntilDone:YES];
     [self.popoverController performSelectorOnMainThread:@selector(dismissPopoverAnimated:) withObject:nil waitUntilDone:YES];
     [self.view performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:YES];
+    [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES];
 }
 
 #pragma mark -
--- a/project_files/HedgewarsMobile/SDL-50560ca58f80.patch	Mon Oct 31 21:04:18 2011 +0100
+++ b/project_files/HedgewarsMobile/SDL-50560ca58f80.patch	Wed Nov 02 09:24:18 2011 +0100
@@ -1,6 +1,6 @@
 diff -r 50560ca58f80 Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Mon Oct 24 23:18:53 2011 -0400
-+++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Tue Oct 25 22:13:19 2011 +0200
++++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Wed Nov 02 09:22:08 2011 +0100
 @@ -1596,9 +1596,12 @@
  				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
  				GCC_C_LANGUAGE_STANDARD = c99;
@@ -31,7 +31,7 @@
  				TARGETED_DEVICE_FAMILY = "1,2";
 diff -r 50560ca58f80 include/SDL_config_iphoneos.h
 --- a/include/SDL_config_iphoneos.h	Mon Oct 24 23:18:53 2011 -0400
-+++ b/include/SDL_config_iphoneos.h	Tue Oct 25 22:13:19 2011 +0200
++++ b/include/SDL_config_iphoneos.h	Wed Nov 02 09:22:08 2011 +0100
 @@ -106,7 +106,7 @@
  /* enable iPhone version of Core Audio driver */
  #define SDL_AUDIO_DRIVER_COREAUDIO 1
@@ -63,7 +63,7 @@
     See src/joystick/uikit/SDLUIAccelerationDelegate.m for notes on why this is needed
 diff -r 50560ca58f80 src/video/uikit/SDL_uikitopenglview.m
 --- a/src/video/uikit/SDL_uikitopenglview.m	Mon Oct 24 23:18:53 2011 -0400
-+++ b/src/video/uikit/SDL_uikitopenglview.m	Tue Oct 25 22:13:19 2011 +0200
++++ b/src/video/uikit/SDL_uikitopenglview.m	Wed Nov 02 09:22:08 2011 +0100
 @@ -114,8 +114,8 @@
  
          // !!! FIXME: use the screen this is on!
@@ -86,15 +86,176 @@
  }
  
  - (void)setCurrentContext
+diff -r 50560ca58f80 src/video/uikit/SDL_uikitvideo.m
+--- a/src/video/uikit/SDL_uikitvideo.m	Mon Oct 24 23:18:53 2011 -0400
++++ b/src/video/uikit/SDL_uikitvideo.m	Wed Nov 02 09:22:08 2011 +0100
+@@ -178,7 +178,7 @@
+ 
+     // UIScreenMode showed up in 3.2 (the iPad and later). We're
+     //  misusing this supports_multiple_displays flag here for that.
+-    if (!SDL_UIKit_supports_multiple_displays) {
++    if (SDL_UIKit_supports_multiple_displays) {
+         UIScreenMode *uimode = [uiscreen currentMode];
+         [uimode retain];  // once for the desktop_mode
+         [uimode retain];  // once for the current_mode
+@@ -200,10 +200,8 @@
+ {
+     _this->gl_config.driver_loaded = 1;
+ 
+-    NSString *reqSysVer = @"3.2";
+-    NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
+-    if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
+-        SDL_UIKit_supports_multiple_displays = YES;
++    // this tells us whether we are running on ios >= 3.2
++    SDL_UIKit_supports_multiple_displays = [UIScreen instancesRespondToSelector:@selector(currentMode)];
+ 
+     // Add the main screen.
+     UIScreen *uiscreen = [UIScreen mainScreen];
+diff -r 50560ca58f80 src/video/uikit/SDL_uikitview.m
+--- a/src/video/uikit/SDL_uikitview.m	Mon Oct 24 23:18:53 2011 -0400
++++ b/src/video/uikit/SDL_uikitview.m	Wed Nov 02 09:22:08 2011 +0100
+@@ -311,7 +311,7 @@
+ /* iPhone keyboard addition functions */
+ #if SDL_IPHONE_KEYBOARD
+ 
+-SDL_uikitview * getWindowView(SDL_Window * window)
++SDL_uikitview *SDL_getUikitView(SDL_Window *window)
+ {
+     if (window == NULL) {
+         SDL_SetError("Window does not exist");
+@@ -328,9 +328,9 @@
+     return view;
+ }
+ 
+-int SDL_iPhoneKeyboardShow(SDL_Window * window)
++int SDL_iPhoneKeyboardShow(SDL_Window *window)
+ {
+-    SDL_uikitview *view = getWindowView(window);
++    SDL_uikitview *view = SDL_getUikitView(window);
+     if (view == nil) {
+         return -1;
+     }
+@@ -339,9 +339,9 @@
+     return 0;
+ }
+ 
+-int SDL_iPhoneKeyboardHide(SDL_Window * window)
++int SDL_iPhoneKeyboardHide(SDL_Window *window)
+ {
+-    SDL_uikitview *view = getWindowView(window);
++    SDL_uikitview *view = SDL_getUikitView(window);
+     if (view == nil) {
+         return -1;
+     }
+@@ -350,9 +350,9 @@
+     return 0;
+ }
+ 
+-SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window)
++SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window *window)
+ {
+-    SDL_uikitview *view = getWindowView(window);
++    SDL_uikitview *view = SDL_getUikitView(window);
+     if (view == nil) {
+         return 0;
+     }
+@@ -360,9 +360,9 @@
+     return view.keyboardVisible;
+ }
+ 
+-int SDL_iPhoneKeyboardToggle(SDL_Window * window)
++int SDL_iPhoneKeyboardToggle(SDL_Window *window)
+ {
+-    SDL_uikitview *view = getWindowView(window);
++    SDL_uikitview *view = SDL_getUikitView(window);
+     if (view == nil) {
+         return -1;
+     }
+@@ -380,24 +380,24 @@
+ 
+ /* stubs, used if compiled without keyboard support */
+ 
+-int SDL_iPhoneKeyboardShow(SDL_Window * window)
++int SDL_iPhoneKeyboardShow(SDL_Window *window)
+ {
+     SDL_SetError("Not compiled with keyboard support");
+     return -1;
+ }
+ 
+-int SDL_iPhoneKeyboardHide(SDL_Window * window)
++int SDL_iPhoneKeyboardHide(SDL_Window *window)
+ {
+     SDL_SetError("Not compiled with keyboard support");
+     return -1;
+ }
+ 
+-SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window)
++SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window *window)
+ {
+     return 0;
+ }
+ 
+-int SDL_iPhoneKeyboardToggle(SDL_Window * window)
++int SDL_iPhoneKeyboardToggle(SDL_Window *window)
+ {
+     SDL_SetError("Not compiled with keyboard support");
+     return -1;
 diff -r 50560ca58f80 src/video/uikit/SDL_uikitviewcontroller.m
 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Mon Oct 24 23:18:53 2011 -0400
-+++ b/src/video/uikit/SDL_uikitviewcontroller.m	Tue Oct 25 22:13:19 2011 +0200
-@@ -145,7 +145,7 @@
-     frame.origin.x = 0;
-     frame.origin.y = 0;
++++ b/src/video/uikit/SDL_uikitviewcontroller.m	Wed Nov 02 09:22:08 2011 +0100
+@@ -28,8 +28,8 @@
+ 
+ #include "SDL_uikitwindow.h"
+ 
+-#import "SDL_uikitviewcontroller.h"
+-
++#include "SDL_uikitviewcontroller.h"
++#include "SDL_uikitvideo.h"
+ 
+ @implementation SDL_uikitviewcontroller
  
--    [uiwindow setFrame:frame];
-+    [uiwindow setFrame:[[UIScreen mainScreen] bounds]];
+@@ -116,38 +116,17 @@
+     const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
+     SDL_WindowData *data = self->window->driverdata;
+     UIWindow *uiwindow = data->uiwindow;
+-    UIScreen *uiscreen = [uiwindow screen];
++    UIScreen *uiscreen;
++    if (SDL_UIKit_supports_multiple_displays)
++        uiscreen = [uiwindow screen];
++    else
++        uiscreen = [UIScreen mainScreen];
+     const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
+     CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
+-    const CGSize size = frame.size;
+-    int w, h;
+-
+-    switch (toInterfaceOrientation) {
+-        case UIInterfaceOrientationPortrait:
+-        case UIInterfaceOrientationPortraitUpsideDown:
+-            w = (size.width < size.height) ? size.width : size.height;
+-            h = (size.width > size.height) ? size.width : size.height;
+-            break;
+-
+-        case UIInterfaceOrientationLandscapeLeft:
+-        case UIInterfaceOrientationLandscapeRight:
+-            w = (size.width > size.height) ? size.width : size.height;
+-            h = (size.width < size.height) ? size.width : size.height;
+-            break;
+-
+-        default:
+-            SDL_assert(0 && "Unexpected interface orientation!");
+-            return;
+-    }
+-
+-    frame.size.width = w;
+-    frame.size.height = h;
+-    frame.origin.x = 0;
+-    frame.origin.y = 0;
+ 
+     [uiwindow setFrame:frame];
      [data->view updateFrame];
-     SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
+-    SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
++    SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, frame.size.width, frame.size.height);
  }
+ 
+ @end