Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Simplied the code a bit in uikit/SDL_uikitvideo.m
Browse files Browse the repository at this point in the history
  • Loading branch information
keestux committed Sep 28, 2011
1 parent 9518567 commit 0fb4ee9
Showing 1 changed file with 11 additions and 44 deletions.
55 changes: 11 additions & 44 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -118,32 +118,6 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
*/

static CGSize
UIKit_ForcePortrait(const CGSize size)
{
CGSize retval;
if (size.width < size.height) { // portrait
retval = size;
} else { // landscape
retval.width = size.height;
retval.height = size.width;
}
return retval;
}

static CGSize
UIKit_ForceLandscape(const CGSize size)
{
CGSize retval;
if (size.width > size.height) { // landscape
retval = size;
} else { // portrait
retval.width = size.height;
retval.height = size.width;
}
return retval;
}

static void
UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
Expand All @@ -156,18 +130,19 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
if (!SDL_UIKit_supports_multiple_displays) {
const CGRect rect = [uiscreen bounds];
mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.w = (int) rect.size.width;
mode.h = (int) rect.size.height;
mode.refresh_rate = 0;
mode.driverdata = NULL;

mode.w = (int) rect.size.width;
mode.h = (int) rect.size.height;
SDL_AddDisplayMode(display, &mode);

mode.w = (int) rect.size.height; // swap the orientation, add again.
mode.h = (int) rect.size.width;
SDL_AddDisplayMode(display, &mode);
return;
}

const BOOL ismain = (uiscreen == [UIScreen mainScreen]);
const NSArray *modes = [uiscreen availableModes];
for (UIScreenMode *uimode in [uiscreen availableModes]) {
CGSize size = [uimode size];
Expand All @@ -177,20 +152,12 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
mode.w = (int) size.width;
mode.h = (int) size.height;
if (SDL_AddDisplayMode(display, &mode))
[uimode retain];

if (ismain) {
// Add the mode twice, flipped to portrait and landscape.
// SDL_AddDisplayMode() will ignore duplicates.
size = UIKit_ForcePortrait([uimode size]);
mode.w = (int) size.width;
mode.h = (int) size.height;
if (SDL_AddDisplayMode(display, &mode))
[uimode retain];
[uimode retain]; // retain is needed because of mode.driverdata

size = UIKit_ForceLandscape(size);
mode.w = (int) size.width;
mode.h = (int) size.height;
if (uiscreen == [UIScreen mainScreen]) {
// Add the mode with swapped width/height
mode.w = (int) size.height;
mode.h = (int) size.width;
if (SDL_AddDisplayMode(display, &mode))
[uimode retain];
}
Expand Down Expand Up @@ -239,8 +206,8 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
// Just give 'em the whole main screen.
UIScreen *uiscreen = [UIScreen mainScreen];
UIScreenMode *uiscreenmode = [uiscreen currentMode];
const CGRect rect = [uiscreen bounds];
UIKit_AddDisplay(uiscreen, uiscreenmode, (int)rect.size.width, (int)rect.size.height);
const CGSize size = [uiscreen bounds].size;
UIKit_AddDisplay(uiscreen, uiscreenmode, (int)size.width, (int)size.height);
} else {
for (UIScreen *uiscreen in [UIScreen screens]) {
// the main screen is the first element in the array.
Expand Down

0 comments on commit 0fb4ee9

Please sign in to comment.