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

Commit

Permalink
Generate resize event when the status bar changes size (e.g. call in …
Browse files Browse the repository at this point in the history
…progress, etc.)
  • Loading branch information
slouken committed Sep 19, 2012
1 parent a0a38b3 commit 2f4c14e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/video/uikit/SDL_uikitviewcontroller.h
Expand Up @@ -31,8 +31,10 @@
@property (readwrite) SDL_Window *window;

- (id)initWithSDLWindow:(SDL_Window *)_window;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
- (void)loadView;
- (void)statusBarFrameChanged:(NSNotification*)notification;
- (void)onWindowSizeChanged;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

@end
49 changes: 33 additions & 16 deletions src/video/uikit/SDL_uikitviewcontroller.m
Expand Up @@ -43,9 +43,39 @@ - (id)initWithSDLWindow:(SDL_Window *)_window
return nil;
}
self.window = _window;

// Register for notification when the status bar size changes
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];

return self;
}

- (void)loadView
{
// do nothing.
}

- (void)statusBarFrameChanged:(NSNotification*)notification
{
[self onWindowSizeChanged];
}

- (void)onWindowSizeChanged
{
if (self->window->flags & SDL_WINDOW_RESIZABLE) {
SDL_WindowData *data = self->window->driverdata;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(self->window);
SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
const CGSize size = data->view.bounds.size;
int w, h;

w = (int)(size.width * displaymodedata->scale);
h = (int)(size.height * displaymodedata->scale);

SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
}
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
{
// Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation
Expand Down Expand Up @@ -108,27 +138,14 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
return NO; // Nothing else is acceptable.
}

- (void)loadView
{
// do nothing.
}

// Send a resized event when the orientation changes.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
SDL_WindowData *data = self->window->driverdata;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(self->window);
SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
const CGSize size = data->view.bounds.size;
int w, h;

w = (int)(size.width * displaymodedata->scale);
h = (int)(size.height * displaymodedata->scale);

SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
[self onWindowSizeChanged];
}

#endif /* SDL_VIDEO_DRIVER_UIKIT */

@end

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 2f4c14e

Please sign in to comment.