Navigation Menu

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

Commit

Permalink
Work in progress fixing support for rotated video modes
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 10, 2011
1 parent 67b764d commit fff9e01
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -238,6 +238,13 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
} else {
UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
[uiscreen setCurrentMode:uimode];

CGSize size = [uimode size];
if (size.width >= size.height) {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
} else {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
}

return 0;
Expand Down
10 changes: 5 additions & 5 deletions src/video/uikit/SDL_uikitviewcontroller.m
Expand Up @@ -111,15 +111,11 @@ - (void)loadView
// Send a resized event when the orientation changes.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if ((self->window->flags & SDL_WINDOW_RESIZABLE) == 0) {
return; // don't care, we're just flipping over in this case.
}

const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
SDL_WindowData *data = self->window->driverdata;
UIWindow *uiwindow = data->uiwindow;
UIScreen *uiscreen = [uiwindow screen];
const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
const int noborder = (self->window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS));
CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
const CGSize size = frame.size;
int w, h;
Expand All @@ -142,6 +138,10 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
return;
}

if (w == frame.size.width && h == frame.size.height) {
return;
}

frame.size.width = w;
frame.size.height = h;
frame.origin.x = 0;
Expand Down
44 changes: 42 additions & 2 deletions src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -63,8 +63,27 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
{
window->x = 0;
window->y = 0;
window->w = (int)uiwindow.frame.size.width;
window->h = (int)uiwindow.frame.size.height;

/* We can pick either width or height here and we'll rotate the
screen to match, so we pick the closest to what we wanted.
*/
if (window->w >= window->h) {
if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
window->w = (int)uiwindow.frame.size.width;
window->h = (int)uiwindow.frame.size.height;
} else {
window->w = (int)uiwindow.frame.size.height;
window->h = (int)uiwindow.frame.size.width;
}
} else {
if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
window->w = (int)uiwindow.frame.size.height;
window->h = (int)uiwindow.frame.size.width;
} else {
window->w = (int)uiwindow.frame.size.width;
window->h = (int)uiwindow.frame.size.height;
}
}
}

window->driverdata = data;
Expand Down Expand Up @@ -199,6 +218,27 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
[UIApplication sharedApplication].statusBarHidden = NO;
uiwindow.frame = [uiscreen applicationFrame];
}

/* We can pick either width or height here and we'll rotate the
screen to match, so we pick the closest to what we wanted.
*/
if (window->w >= window->h) {
if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
window->w = (int)uiwindow.frame.size.width;
window->h = (int)uiwindow.frame.size.height;
} else {
window->w = (int)uiwindow.frame.size.height;
window->h = (int)uiwindow.frame.size.width;
}
} else {
if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
window->w = (int)uiwindow.frame.size.height;
window->h = (int)uiwindow.frame.size.width;
} else {
window->w = (int)uiwindow.frame.size.width;
window->h = (int)uiwindow.frame.size.height;
}
}
}

void
Expand Down

0 comments on commit fff9e01

Please sign in to comment.