Browse Source

Hack fix for window size on iOS 8. Fix screen joysticks not resizing along with the screen. Note that there may still be other iOS 8 orientation bugs, for example related to the screen keyboard. These are pending a proper fix from SDL. Closes #553.

Lasse Öörni 11 years ago
parent
commit
f1545328b3

+ 10 - 1
Source/ThirdParty/SDL/src/video/uikit/SDL_uikitwindow.h

@@ -18,6 +18,9 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+
+// Modified by Lasse Oorni for Urho3D
+
 #ifndef _SDL_uikitwindow_h
 #define _SDL_uikitwindow_h
 
@@ -39,9 +42,15 @@ extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
 
 @class UIWindow;
 
+// Urho3D: subclass for iOS 8 window size hack
+@interface SDL_uikitwindow : UIWindow
+
+@end
+
 struct SDL_WindowData
 {
-    UIWindow *uiwindow;
+    // Urho3D: subclass for iOS 8 window size hack
+    SDL_uikitwindow *uiwindow;
     SDL_uikitopenglview *view;
     SDL_uikitviewcontroller *viewcontroller;
 };

+ 19 - 2
Source/ThirdParty/SDL/src/video/uikit/SDL_uikitwindow.m

@@ -18,6 +18,9 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+
+// Modified by Lasse Oorni for Urho3D
+
 #include "../../SDL_internal.h"
 
 #if SDL_VIDEO_DRIVER_UIKIT
@@ -41,10 +44,23 @@
 
 #include <Foundation/Foundation.h>
 
+// Urho3D: iOS 8 window size hack based on work of Alex Szpakowski
+// https://bitbucket.org/slime73/sdl-experiments
+@implementation SDL_uikitwindow
 
+- (void)layoutSubviews
+{
+    [super layoutSubviews];
 
+    // Forcibly set window frame based on screen bounds, which follow the orientation on iOS 8
+    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
+        self.frame = self.screen.bounds;
+    }
+}
+@end
 
-static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
+// Urho3D: use subclass for iOS 8 window size hack
+static int SetupWindowData(_THIS, SDL_Window *window, SDL_uikitwindow *uiwindow, SDL_bool created)
 {
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
@@ -193,7 +209,8 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
 
     /* ignore the size user requested, and make a fullscreen window */
     /* !!! FIXME: can we have a smaller view? */
-    UIWindow *uiwindow = [UIWindow alloc];
+    // Urho3D: create subclass for iOS 8 window size hack
+    SDL_uikitwindow *uiwindow = [SDL_uikitwindow alloc];
     uiwindow = [uiwindow initWithFrame:[data->uiscreen bounds]];
 
     /* put the window on an external display if appropriate. This implicitly

+ 8 - 0
Source/Urho3D/Input/Input.cpp

@@ -1725,6 +1725,14 @@ void Input::HandleScreenMode(StringHash eventType, VariantMap& eventData)
         lastMousePosition_ = center;
     }
 
+    // Resize screen joysticks to new screen size
+    for (HashMap<SDL_JoystickID, JoystickState>::Iterator i = joysticks_.Begin(); i != joysticks_.End(); ++i)
+    {
+        UIElement* screenjoystick = i->second_.screenJoystick_;
+        if (screenjoystick)
+            screenjoystick->SetSize(graphics_->GetWidth(), graphics_->GetHeight());
+    }
+    
     focusedThisFrame_ = true;
 
     // After setting a new screen mode we should not be minimized