Skip to content

Commit

Permalink
Revert "Replaced MonoGame.Framework with a submodule."
Browse files Browse the repository at this point in the history
This reverts commit 8f808f5.
  • Loading branch information
William Hutama committed Jan 7, 2022
1 parent 8f808f5 commit 5e7d031
Show file tree
Hide file tree
Showing 722 changed files with 133,483 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ url=https://github.com/MrHelmut/NVorbis.git
[submodule "ThirdParty/SDL_GameControllerDB"]
path = ThirdParty/SDL_GameControllerDB
url = https://github.com/gabomdq/SDL_GameControllerDB.git
[submodule "MonoGame.Framework"]
path = MonoGame.Framework
url = https://github.com/wihu/MonoGame.Framework.git
1 change: 0 additions & 1 deletion MonoGame.Framework
Submodule MonoGame.Framework deleted from 73e51e
110 changes: 110 additions & 0 deletions MonoGame.Framework/Android/AndroidCompatibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System;
using System.Linq;
using Android.App;
using Android.Content.Res;
using Android.OS;
using Android.Views;

namespace Microsoft.Xna.Framework
{
/// <summary>
/// Properties that change from how XNA works by default
/// </summary>
public static class AndroidCompatibility
{
/// <summary>
/// Because the Kindle Fire devices default orientation is fliped by 180 degrees from all the other android devices
/// on the market we need to do some special processing to make sure that LandscapeLeft is the correct way round.
/// This list contains all the Build.Model strings of the effected devices, it should be added to if and when
/// more devices exhibit the same issues.
/// </summary>
private static readonly string[] Kindles = new[] { "KFTT", "KFJWI", "KFJWA", "KFSOWI", "KFTHWA", "KFTHWI", "KFAPWA", "KFAPWI" };

public static bool FlipLandscape { get; private set; }
public static Lazy<Orientation> NaturalOrientation { get; private set; }

static AndroidCompatibility()
{
FlipLandscape = Kindles.Contains(Build.Model);
NaturalOrientation = new Lazy<Orientation>(GetDeviceNaturalOrientation);
}

private static Orientation GetDeviceNaturalOrientation()
{
var orientation = Game.Activity.Resources.Configuration.Orientation;
SurfaceOrientation rotation = Game.Activity.WindowManager.DefaultDisplay.Rotation;

if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) &&
orientation == Orientation.Landscape)
|| ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) &&
orientation == Orientation.Portrait))
{
return Orientation.Landscape;
}
else
{
return Orientation.Portrait;
}
}

internal static DisplayOrientation GetAbsoluteOrientation(int orientation)
{
// Orientation is reported by the device in degrees compared to the natural orientation
// Some tablets have a natural landscape orientation, which we need to account for
if (NaturalOrientation.Value == Orientation.Landscape)
orientation += 270;

// Round orientation into one of 4 positions, either 0, 90, 180, 270.
int ort = ((orientation + 45) / 90 * 90) % 360;

// Surprisingly 90 degree is landscape right, except on Kindle devices
var disporientation = DisplayOrientation.Unknown;
switch (ort)
{
case 90: disporientation = FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight;
break;
case 270: disporientation = FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft;
break;
case 0: disporientation = DisplayOrientation.Portrait;
break;
case 180: disporientation = DisplayOrientation.PortraitDown;
break;
default:
disporientation = DisplayOrientation.LandscapeLeft;
break;
}

return disporientation;
}

/// <summary>
/// Get the absolute orientation of the device, accounting for platform differences.
/// </summary>
/// <returns></returns>
public static DisplayOrientation GetAbsoluteOrientation()
{
var orientation = Game.Activity.WindowManager.DefaultDisplay.Rotation;

// Landscape degrees (provided by the OrientationListener) are swapped by default
// Since we use the code used by OrientationListener, we have to swap manually
int degrees;
switch (orientation)
{
case SurfaceOrientation.Rotation90:
degrees = 270;
break;
case SurfaceOrientation.Rotation180:
degrees = 180;
break;
case SurfaceOrientation.Rotation270:
degrees = 90;
break;
default:
degrees = 0;
break;
}

return GetAbsoluteOrientation(degrees);
}
}
}
110 changes: 110 additions & 0 deletions MonoGame.Framework/Android/AndroidGameActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;

namespace Microsoft.Xna.Framework
{
[CLSCompliant(false)]
public class AndroidGameActivity : Activity
{
internal Game Game { private get; set; }

private ScreenReceiver screenReceiver;
private OrientationListener _orientationListener;

public bool AutoPauseAndResumeMediaPlayer = true;
public bool RenderOnUIThread = true;

/// <summary>
/// OnCreate called when the activity is launched from cold or after the app
/// has been killed due to a higher priority app needing the memory
/// </summary>
/// <param name='savedInstanceState'>
/// Saved instance state.
/// </param>
protected override void OnCreate (Bundle savedInstanceState)
{
RequestWindowFeature(WindowFeatures.NoTitle);
base.OnCreate(savedInstanceState);

IntentFilter filter = new IntentFilter();
filter.AddAction(Intent.ActionScreenOff);
filter.AddAction(Intent.ActionScreenOn);
filter.AddAction(Intent.ActionUserPresent);

screenReceiver = new ScreenReceiver();
RegisterReceiver(screenReceiver, filter);

_orientationListener = new OrientationListener(this);

Game.Activity = this;
}

public static event EventHandler Paused;

public override void OnConfigurationChanged (Android.Content.Res.Configuration newConfig)
{
// we need to refresh the viewport here.
base.OnConfigurationChanged (newConfig);
}

protected override void OnPause()
{
base.OnPause();
EventHelpers.Raise(this, Paused, EventArgs.Empty);

if (_orientationListener.CanDetectOrientation())
_orientationListener.Disable();
}

public static event EventHandler Resumed;
protected override void OnResume()
{
base.OnResume();
EventHelpers.Raise(this, Resumed, EventArgs.Empty);

if (Game != null)
{
var deviceManager = (IGraphicsDeviceManager)Game.Services.GetService(typeof(IGraphicsDeviceManager));
if (deviceManager == null)
return;
((GraphicsDeviceManager)deviceManager).ForceSetFullScreen();
((AndroidGameWindow)Game.Window).GameView.RequestFocus();
if (_orientationListener.CanDetectOrientation())
_orientationListener.Enable();
}
}

protected override void OnDestroy ()
{
UnregisterReceiver(screenReceiver);
ScreenReceiver.ScreenLocked = false;
_orientationListener = null;
if (Game != null)
Game.Dispose();
Game = null;
base.OnDestroy ();
}
}

[CLSCompliant(false)]
public static class ActivityExtensions
{
public static ActivityAttribute GetActivityAttribute(this AndroidGameActivity obj)
{
var attr = obj.GetType().GetCustomAttributes(typeof(ActivityAttribute), true);
if (attr != null)
{
return ((ActivityAttribute)attr[0]);
}
return null;
}
}

}
Loading

0 comments on commit 5e7d031

Please sign in to comment.