src/video/uikit/SDL_uikitvideo.m
changeset 5518 f84dd424d514
parent 5262 b530ef003506
child 5535 96594ac5fd1a
     1.1 --- a/src/video/uikit/SDL_uikitvideo.m	Sat Mar 26 21:28:17 2011 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Sun Mar 27 01:35:19 2011 -0400
     1.3 @@ -119,6 +119,32 @@
     1.4  
     1.5  */
     1.6  
     1.7 +static CGSize
     1.8 +UIKit_ForcePortrait(const CGSize size)
     1.9 +{
    1.10 +    CGSize retval;
    1.11 +    if (size.width < size.height) { // portrait
    1.12 +        retval = size;
    1.13 +    } else {  // landscape
    1.14 +        retval.width = size.height;
    1.15 +        retval.height = size.width;
    1.16 +    }
    1.17 +    return retval;
    1.18 +}
    1.19 +
    1.20 +static CGSize
    1.21 +UIKit_ForceLandscape(const CGSize size)
    1.22 +{
    1.23 +    CGSize retval;
    1.24 +    if (size.width > size.height) { // landscape
    1.25 +        retval = size;
    1.26 +    } else {  // portrait
    1.27 +        retval.width = size.height;
    1.28 +        retval.height = size.width;
    1.29 +    }
    1.30 +    return retval;
    1.31 +}
    1.32 +
    1.33  static void
    1.34  UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
    1.35  {
    1.36 @@ -136,22 +162,42 @@
    1.37          mode.refresh_rate = 0;
    1.38          mode.driverdata = NULL;
    1.39          SDL_AddDisplayMode(display, &mode);
    1.40 +        mode.w = (int) rect.size.height;  // swap the orientation, add again.
    1.41 +        mode.h = (int) rect.size.width;
    1.42 +        SDL_AddDisplayMode(display, &mode);
    1.43          return;
    1.44      }
    1.45  
    1.46 +    const int ismain = (uiscreen == [UIScreen mainScreen]);
    1.47      const NSArray *modes = [uiscreen availableModes];
    1.48      const NSUInteger mode_count = [modes count];
    1.49      NSUInteger i;
    1.50      for (i = 0; i < mode_count; i++) {
    1.51          UIScreenMode *uimode = (UIScreenMode *) [modes objectAtIndex:i];
    1.52 -        const CGSize size = [uimode size];
    1.53 +        CGSize size = [uimode size];
    1.54          mode.format = SDL_PIXELFORMAT_ABGR8888;
    1.55 +        mode.refresh_rate = 0;
    1.56 +        mode.driverdata = uimode;
    1.57          mode.w = (int) size.width;
    1.58          mode.h = (int) size.height;
    1.59 -        mode.refresh_rate = 0;
    1.60 -        mode.driverdata = uimode;
    1.61 -        [uimode retain];
    1.62 -        SDL_AddDisplayMode(display, &mode);
    1.63 +        if (SDL_AddDisplayMode(display, &mode))
    1.64 +            [uimode retain];
    1.65 +
    1.66 +        if (ismain) {
    1.67 +            // Add the mode twice, flipped to portrait and landscape.
    1.68 +            //  SDL_AddDisplayMode() will ignore duplicates.
    1.69 +            size = UIKit_ForcePortrait([uimode size]);
    1.70 +            mode.w = (int) size.width;
    1.71 +            mode.h = (int) size.height;
    1.72 +            if (SDL_AddDisplayMode(display, &mode))
    1.73 +                [uimode retain];
    1.74 +
    1.75 +            size = UIKit_ForceLandscape(size);
    1.76 +            mode.w = (int) size.width;
    1.77 +            mode.h = (int) size.height;
    1.78 +            if (SDL_AddDisplayMode(display, &mode))
    1.79 +                [uimode retain];
    1.80 +        }
    1.81      }
    1.82  }
    1.83