app: plumb through iOS orientation

Change-Id: I9cfaf23219a8e7e15727bd7338503b9fbc4634a2
Reviewed-on: https://go-review.googlesource.com/13444
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
David Crawshaw 2015-08-10 10:15:43 -04:00
parent a1723d5d95
commit d382b23901
2 changed files with 20 additions and 5 deletions

View File

@ -13,6 +13,7 @@ package app
#include <sys/utsname.h>
#include <stdint.h>
#include <pthread.h>
#include <UIKit/UIDevice.h>
extern struct utsname sysInfo;
@ -97,15 +98,23 @@ func setScreen(scale int) {
}
//export updateConfig
func updateConfig(width, height int) {
widthPx := screenScale * width
heightPx := screenScale * height
func updateConfig(width, height, orientation int32) {
o := config.OrientationUnknown
switch orientation {
case C.UIDeviceOrientationPortrait, C.UIDeviceOrientationPortraitUpsideDown:
o = config.OrientationPortrait
case C.UIDeviceOrientationLandscapeLeft, C.UIDeviceOrientationLandscapeRight:
o = config.OrientationLandscape
}
widthPx := screenScale * int(width)
heightPx := screenScale * int(height)
eventsIn <- config.Event{
WidthPx: widthPx,
HeightPx: heightPx,
WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt),
HeightPt: geom.Pt(float32(heightPx) / pixelsPerPt),
PixelsPerPt: pixelsPerPt,
Orientation: o,
}
}

View File

@ -54,11 +54,17 @@ struct utsname sysInfo;
setScreen(scale);
CGSize size = [UIScreen mainScreen].bounds.size;
updateConfig((int)size.width, (int)size.height);
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
updateConfig((int)size.width, (int)size.height, orientation);
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
updateConfig((int)size.width, (int)size.height);
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// TODO(crawshaw): come up with a plan to handle animations.
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
updateConfig((int)size.width, (int)size.height, orientation);
}];
}
- (void)update {