Skip to content

Commit

Permalink
IOS: Fixes rotation and event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Bénony committed Jan 6, 2016
1 parent 6260641 commit 39b98c1
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 268 deletions.
8 changes: 7 additions & 1 deletion backends/platform/iphone/iphone_common.h
Expand Up @@ -36,7 +36,8 @@ enum InputEvent {
kInputKeyPressed,
kInputApplicationSuspended,
kInputApplicationResumed,
kInputSwipe
kInputSwipe,
kInputTap
};

enum ScreenOrientation {
Expand All @@ -52,6 +53,11 @@ enum UIViewSwipeDirection {
kUIViewSwipeRight = 8
};

enum UIViewTapDescription {
kUIViewTapSingle = 1,
kUIViewTapDouble = 2,
};

enum GraphicsModes {
kGraphicsModeLinear = 0,
kGraphicsModeNone = 1
Expand Down
36 changes: 24 additions & 12 deletions backends/platform/iphone/iphone_main.mm
Expand Up @@ -30,8 +30,21 @@

void iphone_main(int argc, char *argv[]);

@interface ScummVMViewController : UIViewController

@end

@implementation ScummVMViewController

- (BOOL)prefersStatusBarHidden {
return YES;
}

@end

@interface iPhoneMain : UIApplication {
UIWindow *_window;
ScummVMViewController *_controller;
iPhoneView *_view;
}

Expand Down Expand Up @@ -80,19 +93,24 @@ - (iPhoneView *)getView {
- (void)applicationDidFinishLaunching:(UIApplication *)application {
CGRect rect = [[UIScreen mainScreen] bounds];

// hide the status bar
[application setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
[application setStatusBarHidden:YES animated:YES];
// Create the directory for savegames
NSFileManager *fm = [NSFileManager defaultManager];
NSString *documentPath = [NSString stringWithUTF8String:iPhone_getDocumentsDir()];
NSString *savePath = [documentPath stringByAppendingPathComponent:@"savegames"];
if (![fm fileExistsAtPath:savePath]) {
[fm createDirectoryAtPath:savePath withIntermediateDirectories:YES attributes:nil error:nil];
}

_window = [[UIWindow alloc] initWithFrame:rect];
[_window retain];

_controller = [[ScummVMViewController alloc] init];

_view = [[iPhoneView alloc] initWithFrame:rect];
_view.multipleTouchEnabled = YES;
_controller.view = _view;

[_window setContentView:_view];

[_window addSubview:_view];
[_window setRootViewController:_controller];
[_window makeKeyAndVisible];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Expand Down Expand Up @@ -120,12 +138,6 @@ - (void)applicationSuspend:(struct __GSEvent *)event {

- (void)applicationResume:(struct __GSEvent *)event {
[_view applicationResume];

// Workaround, need to "hide" and unhide the statusbar to properly remove it,
// since the Springboard has put it back without apparently flagging our application.
[self setStatusBarHidden:YES animated:YES];
[self setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
[self setStatusBarHidden:YES animated:YES];
}

- (void)didRotate:(NSNotification *)notification {
Expand Down
4 changes: 0 additions & 4 deletions backends/platform/iphone/iphone_video.h
Expand Up @@ -50,8 +50,6 @@
GLuint _overlayTexture;
GLuint _mouseCursorTexture;

UIDeviceOrientation _orientation;

GLint _renderBufferWidth;
GLint _renderBufferHeight;

Expand Down Expand Up @@ -80,8 +78,6 @@

- (VideoContext *)getVideoContext;

- (void)drawRect:(CGRect)frame;

- (void)createScreenTexture;
- (void)initSurface;
- (void)setViewTransformation;
Expand Down

0 comments on commit 39b98c1

Please sign in to comment.