diff --git a/src/lime/_internal/backend/air/AIRWindow.hx b/src/lime/_internal/backend/air/AIRWindow.hx index 3dccc8264..f4d9fdccd 100644 --- a/src/lime/_internal/backend/air/AIRWindow.hx +++ b/src/lime/_internal/backend/air/AIRWindow.hx @@ -8,11 +8,13 @@ import flash.display.NativeWindowSystemChrome; import flash.geom.Point; import flash.events.Event; import flash.events.NativeWindowBoundsEvent; +import flash.events.StageOrientationEvent; import flash.html.HTMLLoader; import flash.Lib; import lime._internal.backend.flash.FlashApplication; import lime._internal.backend.flash.FlashWindow; import lime.app.Application; +import lime.system.Orientation; import lime.ui.Window; @:access(lime._internal.backend.flash.FlashApplication) @@ -168,6 +170,8 @@ class AIRWindow extends FlashWindow parent.context.attributes.depth = true; parent.context.attributes.stencil = true; } + + parent.stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, handleStageOrientationChangeEvent); } public override function focus():Void @@ -178,6 +182,41 @@ class AIRWindow extends FlashWindow } } + private function handleStageOrientationChangeEvent(event:StageOrientationEvent):Void + { + if (parent.application.window == parent) + { + var newDeviceOrientation:Orientation = UNKNOWN; + switch (parent.stage.deviceOrientation) { + case DEFAULT: + newDeviceOrientation = PORTRAIT; + case UPSIDE_DOWN: + newDeviceOrientation = PORTRAIT_FLIPPED; + case ROTATED_LEFT: + newDeviceOrientation = LANDSCAPE; + case ROTATED_RIGHT: + newDeviceOrientation = LANDSCAPE_FLIPPED; + default: + newDeviceOrientation = UNKNOWN; + } + parent.application.onDeviceOrientationChange.dispatch(newDeviceOrientation); + } + var newDisplayOrientation:Orientation = UNKNOWN; + switch (event.afterOrientation) { + case DEFAULT: + newDisplayOrientation = PORTRAIT; + case UPSIDE_DOWN: + newDisplayOrientation = PORTRAIT_FLIPPED; + case ROTATED_LEFT: + newDisplayOrientation = LANDSCAPE_FLIPPED; + case ROTATED_RIGHT: + newDisplayOrientation = LANDSCAPE; + default: + newDisplayOrientation = UNKNOWN; + } + parent.application.onDisplayOrientationChange.dispatch(parent.display.id, newDisplayOrientation); + } + private function handleNativeWindowEvent(event:Event):Void { switch (event.type) diff --git a/src/lime/app/Application.hx b/src/lime/app/Application.hx index 89ae58d08..13ca9ecea 100644 --- a/src/lime/app/Application.hx +++ b/src/lime/app/Application.hx @@ -661,6 +661,20 @@ class Application extends Module { #if (lime_cffi && !macro) return cast NativeCFFI.lime_system_get_device_orientation(); + #elseif air + switch (__window.stage.deviceOrientation) + { + case DEFAULT: + return PORTRAIT; + case UPSIDE_DOWN: + return PORTRAIT_FLIPPED; + case ROTATED_LEFT: + return LANDSCAPE; + case ROTATED_RIGHT: + return LANDSCAPE_FLIPPED; + default: + return UNKNOWN; + } #elseif (js && html5) if (Browser.window.screen.orientation != null) { diff --git a/src/lime/system/System.hx b/src/lime/system/System.hx index 11778c991..8737e1f40 100644 --- a/src/lime/system/System.hx +++ b/src/lime/system/System.hx @@ -310,6 +310,23 @@ class System #if flash display.dpi = Capabilities.screenDPI; display.currentMode = new DisplayMode(Std.int(Capabilities.screenResolutionX), Std.int(Capabilities.screenResolutionY), 60, ARGB32); + #if air + switch (flash.Lib.current.stage.orientation) { + case DEFAULT: + display.orientation = PORTRAIT; + case UPSIDE_DOWN: + display.orientation = PORTRAIT_FLIPPED; + case ROTATED_LEFT: + display.orientation = LANDSCAPE_FLIPPED; + case ROTATED_RIGHT: + display.orientation = LANDSCAPE; + default: + display.orientation = UNKNOWN; + } + + #else + display.orientation = UNKNOWN; + #end #elseif (js && html5) // var div = Browser.document.createElement ("div"); // div.style.width = "1in";