Skip to content

Commit

Permalink
Application: move deviceOrientation getter implementation into backends
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Jan 29, 2025
1 parent 98cdb15 commit daa8cf1
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 40 deletions.
18 changes: 18 additions & 0 deletions src/lime/_internal/backend/air/AIRApplication.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import flash.desktop.SystemIdleMode;
import flash.events.Event;
import lime._internal.backend.flash.FlashApplication;
import lime.app.Application;
import lime.system.Orientation;
import lime.system.System;

class AIRApplication extends FlashApplication
Expand Down Expand Up @@ -32,4 +33,21 @@ class AIRApplication extends FlashApplication
{
// TODO: Remove event handlers?
}

override public function getDeviceOrientation():Orientation
{
switch (parent.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;
}
}
}
6 changes: 6 additions & 0 deletions src/lime/_internal/backend/flash/FlashApplication.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import flash.ui.MultitouchInputMode;
import flash.ui.Multitouch;
import lime.app.Application;
import lime.media.AudioManager;
import lime.system.Orientation;
import lime.ui.Window;

@:access(lime.app.Application)
Expand Down Expand Up @@ -34,4 +35,9 @@ class FlashApplication
}

public function exit():Void {}

public function getDeviceOrientation():Orientation
{
return UNKNOWN;
}
}
22 changes: 22 additions & 0 deletions src/lime/_internal/backend/html5/HTML5Application.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import js.html.KeyboardEvent;
import js.Browser;
import lime.app.Application;
import lime.media.AudioManager;
import lime.system.Orientation;
import lime.system.Sensor;
import lime.system.SensorType;
import lime.ui.GamepadAxis;
Expand Down Expand Up @@ -350,6 +351,27 @@ class HTML5Application

public function exit():Void {}

public function getDeviceOrientation():Orientation
{
if (Browser.window.screen.orientation != null)
{
switch (Browser.window.screen.orientation.type)
{
case PORTRAIT_PRIMARY:
return PORTRAIT;
case PORTRAIT_SECONDARY:
return PORTRAIT_FLIPPED;
case LANDSCAPE_PRIMARY:
return LANDSCAPE;
case LANDSCAPE_SECONDARY:
return LANDSCAPE_FLIPPED;
default:
// fall through to unknown
}
}
return UNKNOWN;
}

private function handleApplicationEvent(?__):Void
{
// TODO: Support independent window frame rates
Expand Down
7 changes: 7 additions & 0 deletions src/lime/_internal/backend/native/NativeApplication.hx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ class NativeApplication
#end
}

public function getDeviceOrientation():Orientation
{
#if (!macro && lime_cffi)
return cast NativeCFFI.lime_system_get_device_orientation();
#end
}

private function handleApplicationEvent():Void
{
switch (applicationEventInfo.type)
Expand Down
41 changes: 1 addition & 40 deletions src/lime/app/Application.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import lime.ui.Touch;
import lime.ui.Window;
import lime.ui.WindowAttributes;
import lime.utils.Preloader;
import lime._internal.backend.native.NativeCFFI;
#if (js && html5)
import js.Browser;
#end

/**
The Application class forms the foundation for most Lime projects.
Expand All @@ -32,7 +28,6 @@ import js.Browser;
@:noDebug
#end
@:access(lime.ui.Window)
@:access(lime._internal.backend.native.NativeCFFI)
class Application extends Module
{
/**
Expand Down Expand Up @@ -659,41 +654,7 @@ class Application extends Module

@:noCompletion private function get_deviceOrientation():Orientation
{
#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)
{
switch (Browser.window.screen.orientation.type)
{
case PORTRAIT_PRIMARY:
return PORTRAIT;
case PORTRAIT_SECONDARY:
return PORTRAIT_FLIPPED;
case LANDSCAPE_PRIMARY:
return LANDSCAPE;
case LANDSCAPE_SECONDARY:
return LANDSCAPE_FLIPPED;
default:
return UNKNOWN;
}
}
#end
return UNKNOWN;
return __backend.getDeviceOrientation();
}
}

Expand Down

0 comments on commit daa8cf1

Please sign in to comment.