Work in progress fixing support for rotated video modes
authorSam Lantinga <slouken@libsdl.org>
Thu, 10 Nov 2011 03:48:59 -0500
changeset 6077ee00e4b80f79
parent 6076 e69b1bd26e0b
child 6078 718b49ec039e
Work in progress fixing support for rotated video modes
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitviewcontroller.m
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/src/video/uikit/SDL_uikitvideo.m	Thu Nov 10 00:22:44 2011 -0500
     1.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Thu Nov 10 03:48:59 2011 -0500
     1.3 @@ -238,6 +238,13 @@
     1.4      } else {
     1.5          UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
     1.6          [uiscreen setCurrentMode:uimode];
     1.7 +
     1.8 +        CGSize size = [uimode size];
     1.9 +        if (size.width >= size.height) {
    1.10 +            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
    1.11 +        } else {
    1.12 +            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    1.13 +        }
    1.14      }
    1.15  
    1.16      return 0;
     2.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Thu Nov 10 00:22:44 2011 -0500
     2.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Thu Nov 10 03:48:59 2011 -0500
     2.3 @@ -111,15 +111,11 @@
     2.4  // Send a resized event when the orientation changes.
     2.5  - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
     2.6  {
     2.7 -    if ((self->window->flags & SDL_WINDOW_RESIZABLE) == 0) {
     2.8 -        return;   // don't care, we're just flipping over in this case.
     2.9 -    }
    2.10 -
    2.11      const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
    2.12      SDL_WindowData *data = self->window->driverdata;
    2.13      UIWindow *uiwindow = data->uiwindow;
    2.14      UIScreen *uiscreen = [uiwindow screen];
    2.15 -    const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
    2.16 +    const int noborder = (self->window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS));
    2.17      CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
    2.18      const CGSize size = frame.size;
    2.19      int w, h;
    2.20 @@ -142,6 +138,10 @@
    2.21              return;
    2.22      }
    2.23  
    2.24 +    if (w == frame.size.width && h == frame.size.height) {
    2.25 +        return;
    2.26 +    }
    2.27 +
    2.28      frame.size.width = w;
    2.29      frame.size.height = h;
    2.30      frame.origin.x = 0;
     3.1 --- a/src/video/uikit/SDL_uikitwindow.m	Thu Nov 10 00:22:44 2011 -0500
     3.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Thu Nov 10 03:48:59 2011 -0500
     3.3 @@ -63,8 +63,27 @@
     3.4      {
     3.5          window->x = 0;
     3.6          window->y = 0;
     3.7 -        window->w = (int)uiwindow.frame.size.width;
     3.8 -        window->h = (int)uiwindow.frame.size.height;
     3.9 +
    3.10 +        /* We can pick either width or height here and we'll rotate the
    3.11 +           screen to match, so we pick the closest to what we wanted.
    3.12 +         */
    3.13 +        if (window->w >= window->h) {
    3.14 +            if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
    3.15 +                window->w = (int)uiwindow.frame.size.width;
    3.16 +                window->h = (int)uiwindow.frame.size.height;
    3.17 +            } else {
    3.18 +                window->w = (int)uiwindow.frame.size.height;
    3.19 +                window->h = (int)uiwindow.frame.size.width;
    3.20 +            }
    3.21 +        } else {
    3.22 +            if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
    3.23 +                window->w = (int)uiwindow.frame.size.height;
    3.24 +                window->h = (int)uiwindow.frame.size.width;
    3.25 +            } else {
    3.26 +                window->w = (int)uiwindow.frame.size.width;
    3.27 +                window->h = (int)uiwindow.frame.size.height;
    3.28 +            }
    3.29 +        }
    3.30      }
    3.31  
    3.32      window->driverdata = data;
    3.33 @@ -199,6 +218,27 @@
    3.34          [UIApplication sharedApplication].statusBarHidden = NO;
    3.35          uiwindow.frame = [uiscreen applicationFrame];
    3.36      }
    3.37 +
    3.38 +    /* We can pick either width or height here and we'll rotate the
    3.39 +       screen to match, so we pick the closest to what we wanted.
    3.40 +     */
    3.41 +    if (window->w >= window->h) {
    3.42 +        if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
    3.43 +            window->w = (int)uiwindow.frame.size.width;
    3.44 +            window->h = (int)uiwindow.frame.size.height;
    3.45 +        } else {
    3.46 +            window->w = (int)uiwindow.frame.size.height;
    3.47 +            window->h = (int)uiwindow.frame.size.width;
    3.48 +        }
    3.49 +    } else {
    3.50 +        if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
    3.51 +            window->w = (int)uiwindow.frame.size.height;
    3.52 +            window->h = (int)uiwindow.frame.size.width;
    3.53 +        } else {
    3.54 +            window->w = (int)uiwindow.frame.size.width;
    3.55 +            window->h = (int)uiwindow.frame.size.height;
    3.56 +        }
    3.57 +    }
    3.58  }
    3.59  
    3.60  void