Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Android support

Basic Rendering (Only Texture2D/Spritefront)
Excluded IOS specific files and included android specific files from MonoGame.Framework\Android
Xna's Audio, GamerServices, Media and Net Namespaces are currently not implemented


git-svn-id: https://xnatouch.svn.codeplex.com/svn@58005 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
commit 03c8ca0f74c7c793dd2834916fc4312288a47322 1 parent 373b384
SND\taskbit_cp authored
View
26 MonoGame.Android.sln
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Android", "MonoGame.Framework\MonoGame.Framework.Android.csproj", "{BA9476CF-99BA-4D03-92F2-73D2C5E58883}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {BA9476CF-99BA-4D03-92F2-73D2C5E58883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BA9476CF-99BA-4D03-92F2-73D2C5E58883}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BA9476CF-99BA-4D03-92F2-73D2C5E58883}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BA9476CF-99BA-4D03-92F2-73D2C5E58883}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0902473D-5624-4151-A84F-7A16DF01C178}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0902473D-5624-4151-A84F-7A16DF01C178}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0902473D-5624-4151-A84F-7A16DF01C178}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {0902473D-5624-4151-A84F-7A16DF01C178}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0902473D-5624-4151-A84F-7A16DF01C178}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0902473D-5624-4151-A84F-7A16DF01C178}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
201 MonoGame.Framework/Android/Content/ContentManager.cs
@@ -0,0 +1,201 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Text;
+using Android.Content.Res;
+using Android.Graphics;
+using Microsoft.Xna.Framework.Graphics;
+using Path = System.IO.Path;
+
+
+namespace Microsoft.Xna.Framework.Content
+{
+ public class ContentManager : IDisposable
+ {
+ private string _rootDirectory;
+ private IServiceProvider serviceProvider;
+ private IGraphicsDeviceService graphicsDeviceService;
+
+ public ContentManager(IServiceProvider serviceProvider)
+ {
+ if (serviceProvider == null)
+ {
+ throw new ArgumentNullException("serviceProvider");
+ }
+ this.serviceProvider = serviceProvider;
+ }
+
+ public ContentManager(IServiceProvider serviceProvider, string rootDirectory)
+ {
+ if (serviceProvider == null)
+ {
+ throw new ArgumentNullException("serviceProvider");
+ }
+ if (rootDirectory == null)
+ {
+ throw new ArgumentNullException("rootDirectory");
+ }
+ this.RootDirectory = rootDirectory;
+ this.serviceProvider = serviceProvider;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public T Load<T>(string assetName)
+ {
+ string originalAssetName = assetName;
+ object result = null;
+
+ if (this.graphicsDeviceService == null)
+ {
+ this.graphicsDeviceService = serviceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
+ if (this.graphicsDeviceService == null)
+ {
+ throw new InvalidOperationException("No Graphics Device Service");
+ }
+ }
+
+ // Check for windows-style directory separator character
+ //Lowercase assetName (monodroid specification all assests are lowercase)
+ assetName = assetName.ToLower().Replace('\\',Path.DirectorySeparatorChar);
+
+ // Get the real file name
+ if ((typeof(T) == typeof(Texture2D)))
+ {
+ assetName = Texture2DReader.Normalize(assetName);
+ }
+ else if ((typeof(T) == typeof(SpriteFont)))
+ {
+ assetName = SpriteFontReader.Normalize(assetName);
+ }
+ else if ((typeof(T) == typeof(Effect)))
+ {
+ assetName = Effect.Normalize(assetName);
+ }
+ else {
+ throw new NotSupportedException("Format not supported");
+ }
+
+ if (string.IsNullOrEmpty(assetName))
+ {
+ throw new ContentLoadException("Could not load " + originalAssetName + " asset!");
+ }
+
+ if (Path.GetExtension(assetName).ToUpper() !=".XNB")
+ {
+ if ((typeof(T) == typeof(Texture2D))) {
+ //Basically the same as Texture2D.FromFile but loading from the assets instead of a filePath
+ Stream assetStream = Game.contextInstance.Assets.Open(assetName);
+ Bitmap image = BitmapFactory.DecodeStream(assetStream);
+ ESImage theTexture = new ESImage(image, graphicsDeviceService.GraphicsDevice.PreferedFilter);
+ result = new Texture2D(theTexture) { Name = Path.GetFileNameWithoutExtension(assetName) };
+ }
+ if ((typeof(T) == typeof(SpriteFont)))
+ {
+ //result = new SpriteFont(Texture2D.FromFile(graphicsDeviceService.GraphicsDevice,assetName), null, null, null, 0, 0.0f, null, null);
+ throw new NotImplementedException();
+ }
+ }
+ else
+ {
+ // Load a XNB file
+ //Loads from Assets directory + /assetName
+ Stream assetStream = Game.contextInstance.Assets.Open(assetName);
+
+ ContentReader reader = new ContentReader(this, assetStream, this.graphicsDeviceService.GraphicsDevice);
+ ContentTypeReaderManager typeManager = new ContentTypeReaderManager(reader);
+ reader.TypeReaders = typeManager.LoadAssetReaders(reader);
+ foreach (ContentTypeReader r in reader.TypeReaders)
+ {
+ r.Initialize(typeManager);
+ }
+ // we need to read a byte here for things to work out, not sure why
+ reader.ReadByte();
+
+ // Get the 1-based index of the typereader we should use to start decoding with
+ int index = reader.ReadByte();
+ ContentTypeReader contentReader = reader.TypeReaders[index - 1];
+ result = reader.ReadObject<T>(contentReader);
+
+ reader.Close();
+ assetStream.Close();
+ }
+
+ if (result == null)
+ {
+ throw new ContentLoadException("Could not load " + originalAssetName + " asset!");
+ }
+
+ return (T) result;
+ }
+
+
+ public virtual void Unload()
+ {
+ }
+
+ public string RootDirectory
+ {
+ get
+ {
+ return _rootDirectory;
+ }
+ set
+ {
+ _rootDirectory = value;
+ }
+ }
+
+ public IServiceProvider ServiceProvider
+ {
+ get
+ {
+ return this.serviceProvider;
+ }
+ }
+ }
+}
+
View
100 MonoGame.Framework/Android/Content/ContentReaders/SpriteFontReader.cs
@@ -0,0 +1,100 @@
+#region License
+/*
+MIT License
+Copyright © 2006 The Mono.Xna Team
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+#endregion License
+
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+using System.IO;
+
+namespace Microsoft.Xna.Framework.Content
+{
+ internal class SpriteFontReader : ContentTypeReader<SpriteFont>
+ {
+ internal SpriteFontReader()
+ {
+ }
+
+ public static string Normalize(string FileName)
+ {
+ int index = FileName.LastIndexOf(Path.DirectorySeparatorChar);
+ string path = string.Empty;
+ string file = FileName;
+ if (index >= 0)
+ {
+ file = FileName.Substring(index + 1, FileName.Length - index - 1);
+ path = FileName.Substring(0, index);
+ }
+ string[] files = Game.contextInstance.Assets.List(path);
+
+ if (Contains(file, files))
+ return FileName;
+
+ // Check the file extension
+ if (!string.IsNullOrEmpty(Path.GetExtension(FileName)))
+ {
+ return null;
+ }
+
+ // Concat the file name with valid extensions
+ if (Contains(file + ".xnb", files))
+ return FileName+".xnb";
+
+ // Concat the file name with valid extensions
+ if (Contains(file + ".spritefont", files))
+ return FileName+".spritefont";
+
+ return null;
+ }
+
+ private static bool Contains(string search, string[] arr)
+ {
+ return arr.Any(s => s == search);
+ }
+
+ protected internal override SpriteFont Read(ContentReader input, SpriteFont existingInstance)
+ {
+ Texture2D texture = input.ReadObject<Texture2D>();
+ texture.IsSpriteFontTexture = true;
+ List<Rectangle> glyphs = input.ReadObject<List<Rectangle>>();
+ List<Rectangle> cropping = input.ReadObject<List<Rectangle>>();
+ List<char> charMap = input.ReadObject<List<char>>();
+ int lineSpacing = input.ReadInt32();
+ float spacing = input.ReadSingle();
+ List<Vector3> kerning = input.ReadObject<List<Vector3>>();
+ char? defaultCharacter = null;
+ if (input.ReadBoolean())
+ {
+ defaultCharacter = new char?(input.ReadChar());
+ }
+ return new SpriteFont(texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultCharacter);
+ }
+ }
+}
View
129 MonoGame.Framework/Android/Content/ContentReaders/Texture2DReader.cs
@@ -0,0 +1,129 @@
+#region License
+/*
+MIT License
+Copyright © 2006 The Mono.Xna Team
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+#endregion License
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Drawing;
+using Android.Util;
+using OpenTK.Graphics.ES11;
+
+using Microsoft.Xna;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace Microsoft.Xna.Framework.Content
+{
+ internal class Texture2DReader : ContentTypeReader<Texture2D>
+ {
+ internal Texture2DReader()
+ {
+ // Do nothing
+ }
+
+ public static string Normalize(string FileName)
+ {
+ int index = FileName.LastIndexOf(Path.DirectorySeparatorChar);
+ string path = string.Empty;
+ string file = FileName;
+ if (index >= 0) {
+ file = FileName.Substring(index + 1, FileName.Length - index - 1);
+ path = FileName.Substring(0, index);
+ }
+ string[] files = Game.contextInstance.Assets.List(path);
+
+ if (Contains(file, files))
+ return FileName;
+
+ // Check the file extension
+ if (!string.IsNullOrEmpty(Path.GetExtension(FileName)))
+ {
+ return null;
+ }
+
+ // Concat the file name with valid extensions
+ if (Contains(file + ".xnb", files))
+ return FileName+".xnb";
+ if (Contains(file + ".jpg", files))
+ return FileName+".jpg";
+ if (Contains(file + ".bmp", files))
+ return FileName+".bmp";
+ if (Contains(file + ".jpeg", files))
+ return FileName+".jpeg";
+ if (Contains(file + ".png", files))
+ return FileName+".png";
+ if (Contains(file + ".gif", files))
+ return FileName+".gif";
+ if (Contains(file + ".pict", files))
+ return FileName+".pict";
+
+ return null;
+ }
+
+ private static bool Contains(string search, string[] arr)
+ {
+ return arr.Any(s => s == search);
+ }
+
+ protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance)
+ {
+ Texture2D texture = null;
+
+ SurfaceFormat surfaceFormat = (SurfaceFormat)reader.ReadInt32 ();
+ int width = (reader.ReadInt32 ());
+ int height = (reader.ReadInt32 ());
+ int levelCount = (reader.ReadInt32 ());
+ SetDataOptions compressionType = (SetDataOptions)reader.ReadInt32 ();
+ int imageLength = width * height * 4;
+
+ if (surfaceFormat == SurfaceFormat.Dxt3)
+ {
+ ESTexture2D temp = ESTexture2D.InitiFromDxt3File(reader,imageLength,width,height);
+ texture = new Texture2D (new ESImage (temp));
+ }
+ else {
+ byte[] imageBytes = reader.ReadBytes (imageLength);
+ IntPtr ptr = Marshal.AllocHGlobal (imageLength);
+ try
+ {
+ Marshal.Copy (imageBytes, 0, ptr, imageLength);
+ ESTexture2D temp = new ESTexture2D (ptr, SurfaceFormat.Rgba32, width, height, new Size (width, height), All.Linear);
+ texture = new Texture2D (new ESImage (temp));
+ }
+ finally
+ {
+ Marshal.FreeHGlobal (ptr);
+ }
+ }
+
+ return texture;
+ }
+ }
+}
View
485 MonoGame.Framework/Android/Game.cs
@@ -0,0 +1,485 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+XnaTouch - Copyright © 2009 The XnaTouch Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using System.IO;
+using Android.App;
+using Android.Content;
+using Android.Content.Res;
+using Android.Views;
+using OpenTK.Graphics;
+
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework.Input.Touch;
+
+namespace Microsoft.Xna.Framework
+{
+ public class Game : IDisposable
+ {
+ private const float FramesPerSecond = 60.0f; // ~60 frames per second
+
+ private GameTime _updateGameTime;
+ private GameTime _drawGameTime;
+ private DateTime _lastUpdate;
+ private bool _initialized = false;
+ private bool _initializing = false;
+ private bool _isActive = true;
+ private GameComponentCollection _gameComponentCollection;
+ public GameServiceContainer _services;
+ private ContentManager _content;
+ private GameWindow _view;
+ private bool _isFixedTimeStep = true;
+ private TimeSpan _targetElapsedTime = TimeSpan.FromSeconds(1 / FramesPerSecond);
+
+ private IGraphicsDeviceManager graphicsDeviceManager;
+ private IGraphicsDeviceService graphicsDeviceService;
+ private bool _devicesLoaded;
+
+ internal static bool _playingVideo = false;
+ private SpriteBatch spriteBatch;
+ private Texture2D splashScreen;
+
+ delegate void InitialiseGameComponentsDelegate();
+
+ //TODO: Can we really use a static contextInstance?!
+ internal static Context contextInstance;
+
+ public Game(Context context)
+ {
+ contextInstance = context;
+
+ // Initialize collections
+ _services = new GameServiceContainer();
+ _gameComponentCollection = new GameComponentCollection();
+
+ _view = new GameWindow(contextInstance);
+ _view.game = this;
+
+ // Initialize GameTime
+ _updateGameTime = new GameTime();
+ _drawGameTime = new GameTime();
+ }
+
+ ~Game()
+ {
+
+ }
+
+ public void Dispose ()
+ {
+ // do nothing
+ }
+
+ private void ObserveDeviceRotation()
+ {
+ /*
+ switch (contextInstance.Resources.Configuration.Orientation) {
+
+ case Orientation.Portrait:
+ if ((graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations ==
+ DisplayOrientation.Portrait) {
+ _view.CurrentOrientation = DisplayOrientation.Portrait;
+ GraphicsDevice.PresentationParameters.DisplayOrientation = DisplayOrientation.Portrait;
+ TouchPanel.DisplayOrientation = DisplayOrientation.Portrait;
+ }
+ break;
+ case Orientation.Landscape:
+ DisplayOrientation orientation = DisplayOrientation.Unknown;
+ if ((graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.LandscapeLeft)
+ orientation = DisplayOrientation.LandscapeLeft;
+ else if ((graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations == DisplayOrientation.LandscapeRight)
+ orientation = DisplayOrientation.LandscapeRight;
+ if (orientation != DisplayOrientation.Unknown) {
+ _view.CurrentOrientation = orientation;
+ GraphicsDevice.PresentationParameters.DisplayOrientation = orientation;
+ TouchPanel.DisplayOrientation = orientation;
+ }
+ break;
+
+ case Orientation.Undefined:
+ if ((graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations ==
+ DisplayOrientation.Unknown) {
+ _view.CurrentOrientation = DisplayOrientation.Unknown;
+ TouchPanel.DisplayOrientation = DisplayOrientation.Unknown;
+ }
+ break;
+ default:
+ if ((graphicsDeviceManager as GraphicsDeviceManager).SupportedOrientations ==
+ DisplayOrientation.Default) {
+ _view.CurrentOrientation = DisplayOrientation.Default;
+ TouchPanel.DisplayOrientation = DisplayOrientation.Default;
+ }
+ break;
+ }
+ */
+ }
+
+ public bool IsActive
+ {
+ get
+ {
+ return _isActive;
+ }
+ protected set
+ {
+ if (_isActive != value )
+ {
+ _isActive = value;
+ }
+ }
+ }
+
+ public bool IsMouseVisible
+ {
+ get
+ {
+ return false;
+ }
+ set
+ {
+ // do nothing; ignore
+ }
+ }
+
+ public TimeSpan TargetElapsedTime
+ {
+ get
+ {
+ return _targetElapsedTime;
+ }
+ set
+ {
+ _targetElapsedTime = value;
+ if(_initialized) {
+ throw new NotSupportedException();
+ }
+ }
+ }
+
+ public void Run()
+ {
+ _lastUpdate = DateTime.Now;
+
+ _view.Run( FramesPerSecond / ( FramesPerSecond * TargetElapsedTime.TotalSeconds ) );
+
+
+ // Get the Accelerometer going
+ Accelerometer.SetupAccelerometer();
+
+ //Need to execute this on the rendering thread
+ _view.RenderFrame += delegate
+ {
+ if (!_devicesLoaded)
+ {
+ Initialize();
+ _devicesLoaded = true;
+ }
+ };
+
+ // Listen out for rotation changes
+ ObserveDeviceRotation();
+ }
+
+ internal void DoUpdate(GameTime aGameTime)
+ {
+ if (_isActive)
+ {
+ Update(aGameTime);
+ }
+ }
+
+ internal void DoDraw(GameTime aGameTime)
+ {
+ if (_isActive)
+ {
+ Draw(aGameTime);
+ }
+ }
+
+ internal void DoStep()
+ {
+ var timeNow = DateTime.Now;
+
+ // Update the game
+ _updateGameTime.Update(timeNow - _lastUpdate);
+ Update(_updateGameTime);
+
+ // Draw the screen
+ _drawGameTime.Update(timeNow - _lastUpdate);
+ _lastUpdate = timeNow;
+ Draw(_drawGameTime);
+ }
+
+ public bool IsFixedTimeStep
+ {
+ get
+ {
+ return _isFixedTimeStep;
+ }
+ set
+ {
+ _isFixedTimeStep = value;
+ }
+ }
+
+ public GameWindow Window
+ {
+ get
+ {
+ return _view;
+ }
+ }
+
+ public void ResetElapsedTime()
+ {
+ _lastUpdate = DateTime.Now;
+ }
+
+
+ public GameServiceContainer Services
+ {
+ get
+ {
+ return _services;
+ }
+ }
+
+ public ContentManager Content
+ {
+ get
+ {
+ if (_content == null)
+ {
+ _content = new ContentManager(_services);
+ }
+ return _content;
+ }
+ }
+
+ public GraphicsDevice GraphicsDevice
+ {
+ get
+ {
+ if (this.graphicsDeviceService == null)
+ {
+ this.graphicsDeviceService = this.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
+ if (this.graphicsDeviceService == null)
+ {
+ throw new InvalidOperationException("No Graphics Device Service");
+ }
+ }
+ return this.graphicsDeviceService.GraphicsDevice;
+ }
+ }
+
+ public void EnterBackground()
+ {
+ _isActive = false;
+ if (Deactivated != null)
+ Deactivated.Invoke(this, null);
+ }
+
+ public void EnterForeground()
+ {
+ _isActive = true;
+ if (Activated != null)
+ Activated.Invoke(this, null);
+ }
+
+ protected virtual bool BeginDraw()
+ {
+ return true;
+ }
+
+ protected virtual void EndDraw()
+ {
+
+ }
+
+ protected virtual void LoadContent()
+ {
+ string DefaultPath = "Default.png";
+ if (File.Exists(DefaultPath))
+ {
+ // Store the RootDir for later
+ string backup = Content.RootDirectory;
+
+ try
+ {
+ // Clear the RootDirectory for this operation
+ Content.RootDirectory = string.Empty;
+
+ spriteBatch = new SpriteBatch(GraphicsDevice);
+ splashScreen = Content.Load<Texture2D>(DefaultPath);
+ }
+ finally
+ {
+ // Reset RootDir
+ Content.RootDirectory = backup;
+ }
+
+ }
+ else
+ {
+ spriteBatch = null;
+ splashScreen = null;
+ }
+ }
+
+ protected virtual void UnloadContent()
+ {
+ // do nothing
+ }
+
+ protected virtual void Initialize()
+ {
+ this.graphicsDeviceManager = this.Services.GetService(typeof(IGraphicsDeviceManager)) as IGraphicsDeviceManager;
+ this.graphicsDeviceService = this.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
+
+ if ((this.graphicsDeviceService != null) && (this.graphicsDeviceService.GraphicsDevice != null))
+ {
+ LoadContent();
+ }
+ }
+
+ private void InitializeGameComponents()
+ {
+ foreach (GameComponent gc in _gameComponentCollection)
+ {
+ gc.Initialize();
+ }
+ }
+
+ protected virtual void Update(GameTime gameTime)
+ {
+ if ( _initialized)
+ {
+ foreach (GameComponent gc in _gameComponentCollection)
+ {
+ if (gc.Enabled)
+ {
+ gc.Update(gameTime);
+ }
+ }
+ }
+ else
+ {
+ if (!_initializing)
+ {
+ _initializing = true;
+
+ // Use OpenGLES context switching as described here
+ // http://developer.apple.com/iphone/library/qa/qa2010/qa1612.html
+ InitialiseGameComponentsDelegate initD = new InitialiseGameComponentsDelegate(InitializeGameComponents);
+
+ // Invoke on thread from the pool
+ initD.BeginInvoke(
+ delegate (IAsyncResult iar)
+ {
+ // We must have finished initialising, so set our flag appropriately
+ // So that we enter the Update loop
+ _initialized = true;
+ _initializing = false;
+ },
+ initD);
+ }
+ }
+ }
+
+ protected virtual void Draw(GameTime gameTime)
+ {
+ if ( _initializing )
+ {
+ if ( spriteBatch != null )
+ {
+ spriteBatch.Begin();
+
+ // We need to turn this into a progress bar or animation to give better user feedback
+ spriteBatch.Draw(splashScreen, new Vector2(0, 0), Color.White );
+ spriteBatch.End();
+ }
+ }
+ else
+ {
+ if (!_playingVideo)
+ {
+ foreach (GameComponent gc in _gameComponentCollection)
+ {
+ if (gc.Enabled && gc is DrawableGameComponent)
+ {
+ DrawableGameComponent dc = gc as DrawableGameComponent;
+ if (dc.Visible)
+ {
+ dc.Draw(gameTime);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public void Exit()
+ {
+ //TODO: Fix this
+ AlertDialog dialog = new AlertDialog.Builder(Game.contextInstance).Create();
+ dialog.SetTitle("Game Exit");
+ dialog.SetMessage("Hit Home Button to Exit");
+ dialog.Show();
+ }
+
+ public GameComponentCollection Components
+ {
+ get
+ {
+ return _gameComponentCollection;
+ }
+ }
+
+ #region Events
+ public event EventHandler Activated;
+ public event EventHandler Deactivated;
+ public event EventHandler Disposed;
+ public event EventHandler Exiting;
+ #endregion
+ }
+}
+
View
366 MonoGame.Framework/Android/GameWindow.cs
@@ -0,0 +1,366 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+XnaTouch - Copyright © 2009 The XnaTouch Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+#region Using Statements
+using System;
+using System.Drawing;
+using System.Collections.Generic;
+using Android.Content;
+using OpenTK.Platform.Android;
+
+using OpenTK;
+using OpenTK.Platform;
+using OpenTK.Graphics;
+using OpenTK.Graphics.ES11;
+using OpenTK.Graphics.ES20;
+
+using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework.Input.Touch;
+#endregion Using Statements
+
+namespace Microsoft.Xna.Framework
+{
+ public class GameWindow : AndroidGameView
+ {
+ private Rectangle clientBounds;
+ internal Game game;
+ private GameTime _updateGameTime;
+ private GameTime _drawGameTime;
+ private DateTime _lastUpdate;
+ private DateTime _now;
+
+ public GameWindow(Context context) : base(context)
+ {
+ Initialize();
+ }
+
+ private void Initialize()
+ {
+ clientBounds = new Rectangle(0, 0, Context.Resources.DisplayMetrics.WidthPixels, Context.Resources.DisplayMetrics.HeightPixels);
+
+ // Initialize GameTime
+ _updateGameTime = new GameTime();
+ _drawGameTime = new GameTime();
+
+ // Initialize _lastUpdate
+ _lastUpdate = DateTime.Now;
+ }
+
+ ~GameWindow()
+ {
+ //
+ }
+
+ protected override void CreateFrameBuffer()
+ {
+ try
+ {
+ // TODO this.GLContextVersion = GLContextVersion.Gles2_0;
+ this.GLContextVersion = GLContextVersion.Gles1_1;
+ base.CreateFrameBuffer();
+ }
+ catch (Exception)
+ {
+ // device doesn't support OpenGLES 2.0; retry with 1.1:
+ this.GLContextVersion = GLContextVersion.Gles1_1;
+ base.CreateFrameBuffer();
+ }
+ }
+
+
+ #region AndroidGameView Methods
+
+ protected override void OnClosed(EventArgs e)
+ {
+ base.OnClosed(e);
+ }
+
+ protected override void OnDisposed(EventArgs e)
+ {
+ base.OnDisposed(e);
+ }
+
+ protected override void OnLoad (EventArgs e)
+ {
+ base.OnLoad(e);
+ }
+
+ protected override void OnRenderFrame(FrameEventArgs e)
+ {
+ base.OnRenderFrame(e);
+
+ MakeCurrent();
+
+ // This code was commented to make the code base more iPhone like.
+ // More speed testing is required, to see if this is worse or better
+ // game.DoStep();
+
+ if (game != null )
+ {
+ _drawGameTime.Update(_now - _lastUpdate);
+ _lastUpdate = _now;
+ game.DoDraw(_drawGameTime);
+ }
+
+ SwapBuffers();
+ }
+
+ protected override void OnResize(EventArgs e)
+ {
+ base.OnResize(e);
+ }
+
+ protected override void OnTitleChanged(EventArgs e)
+ {
+ base.OnTitleChanged(e);
+ }
+
+ protected override void OnUnload(EventArgs e)
+ {
+ base.OnUnload(e);
+ }
+
+ protected override void OnUpdateFrame(FrameEventArgs e)
+ {
+ base.OnUpdateFrame(e);
+
+ if (game != null )
+ {
+ _now = DateTime.Now;
+ _updateGameTime.Update(_now - _lastUpdate);
+ game.DoUpdate(_updateGameTime);
+ }
+ }
+
+ protected override void OnVisibleChanged(EventArgs e)
+ {
+ base.OnVisibleChanged(e);
+ }
+
+ protected override void OnWindowStateChanged(EventArgs e)
+ {
+ base.OnWindowStateChanged(e);
+ }
+
+ #endregion
+
+ /*
+
+ private readonly Dictionary<IntPtr, TouchLocation> previousTouches = new Dictionary<IntPtr, TouchLocation>();
+
+ private void FillTouchCollection(NSSet touches)
+ {
+ UITouch []touchesArray = touches.ToArray<UITouch>();
+
+ TouchPanel.Collection.Clear();
+ TouchPanel.Collection.Capacity = touchesArray.Length;
+
+ for (int i=0; i<touchesArray.Length;i++)
+ {
+ TouchLocationState state;
+ UITouch touch = touchesArray[i];
+ switch (touch.Phase)
+ {
+ case UITouchPhase.Began :
+ state = TouchLocationState.Pressed;
+ break;
+ case UITouchPhase.Cancelled :
+ case UITouchPhase.Ended :
+ state = TouchLocationState.Released;
+ break;
+ default :
+ state = TouchLocationState.Moved;
+ break;
+ }
+
+ TouchLocation tlocation;
+ TouchLocation previousTouch;
+ if (state != TouchLocationState.Pressed && previousTouches.TryGetValue (touch.Handle, out previousTouch))
+ {
+ Vector2 position = new Vector2 (touch.LocationInView (touch.View));
+ Vector2 translatedPosition = position;
+
+ switch (CurrentOrientation)
+ {
+ case DisplayOrientation.Portrait :
+ {
+ break;
+ }
+
+ case DisplayOrientation.LandscapeRight :
+ {
+ translatedPosition = new Vector2( ClientBounds.Height - position.Y, position.X );
+ break;
+ }
+
+ case DisplayOrientation.LandscapeLeft :
+ {
+ translatedPosition = new Vector2( position.Y, ClientBounds.Width - position.X );
+ break;
+ }
+
+ case DisplayOrientation.PortraitUpsideDown :
+ {
+ translatedPosition = new Vector2( ClientBounds.Width - position.X, ClientBounds.Height - position.Y );
+ break;
+ }
+ }
+ tlocation = new TouchLocation(touch.Handle.ToInt32(), state, translatedPosition, 1.0f, previousTouch.State, previousTouch.Position, previousTouch.Pressure);
+ }
+ else
+ {
+ Vector2 position = new Vector2 (touch.LocationInView (touch.View));
+ Vector2 translatedPosition = position;
+
+ switch (CurrentOrientation)
+ {
+ case DisplayOrientation.Portrait :
+ {
+ break;
+ }
+
+ case DisplayOrientation.LandscapeRight :
+ {
+ translatedPosition = new Vector2( ClientBounds.Height - position.Y, position.X );
+ break;
+ }
+
+ case DisplayOrientation.LandscapeLeft :
+ {
+ translatedPosition = new Vector2( position.Y, ClientBounds.Width - position.X );
+ break;
+ }
+
+ case DisplayOrientation.PortraitUpsideDown :
+ {
+ translatedPosition = new Vector2( ClientBounds.Width - position.X, ClientBounds.Height - position.Y );
+ break;
+ }
+ }
+ tlocation = new TouchLocation(touch.Handle.ToInt32(), state, translatedPosition, 1.0f);
+ }
+
+ TouchPanel.Collection.Add (tlocation);
+
+ if (state != TouchLocationState.Released)
+ previousTouches[touch.Handle] = tlocation;
+ else
+ previousTouches.Remove(touch.Handle);
+ }
+ }
+
+ public override void TouchesBegan (NSSet touches, UIEvent evt)
+ {
+ base.TouchesBegan (touches, evt);
+
+ FillTouchCollection(touches);
+
+ GamePad.Instance.TouchesBegan(touches,evt);
+ }
+
+ public override void TouchesEnded (NSSet touches, UIEvent evt)
+ {
+ base.TouchesEnded (touches, evt);
+
+ FillTouchCollection(touches);
+
+ GamePad.Instance.TouchesEnded(touches,evt);
+ }
+
+ public override void TouchesMoved (NSSet touches, UIEvent evt)
+ {
+ base.TouchesMoved (touches, evt);
+
+ FillTouchCollection(touches);
+
+ GamePad.Instance.TouchesMoved(touches,evt);
+ }
+
+ public override void TouchesCancelled (NSSet touches, UIEvent evt)
+ {
+ base.TouchesCancelled (touches, evt);
+
+ FillTouchCollection(touches);
+
+ GamePad.Instance.TouchesCancelled(touches,evt);
+ }*/
+
+
+
+ public string ScreenDeviceName
+ {
+ get
+ {
+ throw new System.NotImplementedException ();
+ }
+ }
+
+ public Rectangle ClientBounds
+ {
+ get
+ {
+ return clientBounds;
+ }
+ }
+
+ public bool AllowUserResizing
+ {
+ get
+ {
+ return false;
+ }
+ set
+ {
+ // Do nothing; Ignore rather than raising and exception
+ }
+ }
+
+ public DisplayOrientation CurrentOrientation
+ {
+ get;
+ set;
+ }
+
+
+ public event EventHandler ClientSizeChanged;
+ public event EventHandler ScreenDeviceNameChanged;
+ }
+}
+
View
71 MonoGame.Framework/Android/Graphics/DisplayMode.cs
@@ -0,0 +1,71 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ public struct DisplayMode
+ {
+ public float AspectRatio
+ {
+ get
+ {
+ return Width / Height;
+ }
+ }
+
+ public int Width
+ {
+ get
+ {
+ return (int)Game.contextInstance.Resources.DisplayMetrics.WidthPixels;
+ }
+ }
+
+ public int Height
+ {
+ get
+ {
+ return (int)Game.contextInstance.Resources.DisplayMetrics.HeightPixels;
+ }
+ }
+ }
+}
View
227 MonoGame.Framework/Android/Graphics/ESImage.cs
@@ -0,0 +1,227 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using Android.Graphics;
+using OpenTK.Graphics.ES11;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ internal class ESImage
+ {
+ // The OpenGL texture to be used for this image
+ private ESTexture2D texture;
+ // The width of the image
+ private int imageWidth;
+ // The height of the image
+ private int imageHeight;
+ // The texture coordinate width to use to find the image
+ private int textureWidth;
+ // The texture coordinate height to use to find the image
+ private int textureHeight;
+ // The texture width to pixel ratio
+ private float texWidthRatio;
+ // The texture height to pixel ratio
+ private float texHeightRatio;
+ // The X offset to use when looking for our image
+ private int textureOffsetX;
+ // The Y offset to use when looking for our image
+ private int textureOffsetY;
+
+ public ESImage ()
+ {
+ imageWidth = 0;
+ imageHeight = 0;
+ textureWidth = 0;
+ textureHeight = 0;
+ texWidthRatio = 0.0f;
+ texHeightRatio = 0.0f;
+ textureOffsetX = 0;
+ textureOffsetY = 0;
+ }
+
+ private void Initialize( float scale )
+ {
+ imageWidth = texture.ContentSize.Width;
+ imageHeight = texture.ContentSize.Height;
+ textureWidth = (int)(texture.PixelsWide/scale);
+ textureHeight = (int)(texture.PixelsHigh/scale);
+ texWidthRatio = 1.0f / (float)textureWidth;
+ texHeightRatio = 1.0f / (float)textureHeight;
+ textureOffsetX = 0;
+ textureOffsetY = 0;
+ }
+
+ public ESImage(ESTexture2D tex)
+ {
+ texture = tex;
+ Initialize(1.0f);
+ }
+
+ public ESImage(ESTexture2D tex, float imageScale)
+ {
+ texture = tex;
+ Initialize(1.0f);
+ }
+
+ public ESImage(Bitmap image)
+ {
+ // By default set the scale to 1.0f and the filtering to GL_NEAREST
+ texture = new ESTexture2D(image,All.Nearest);
+ Initialize(1.0f);
+ }
+
+ public ESImage(Bitmap image, All filter)
+ {
+ // By default set the scale to 1.0f
+ texture = new ESTexture2D(image,filter);
+ Initialize(1.0f);
+ }
+
+ public ESImage(Bitmap image, float imageScale, All filter)
+ {
+ texture = new ESTexture2D(image,filter);
+ Initialize(imageScale);
+ }
+
+
+ public int TextureOffsetX
+ {
+ get
+ {
+ return textureOffsetX;
+ }
+ set
+ {
+ textureOffsetX = value;
+ }
+ }
+
+ public int TextureOffsetY
+ {
+ get
+ {
+ return textureOffsetY;
+ }
+ set
+ {
+ textureOffsetY = value;
+ }
+ }
+
+ public int ImageWidth
+ {
+ get
+ {
+ return imageWidth;
+ }
+ set
+ {
+ imageWidth = value;
+ }
+ }
+
+ public int ImageHeight
+ {
+ get
+ {
+ return imageHeight;
+ }
+ set
+ {
+ imageHeight = value;
+ }
+ }
+
+ public ESImage GetSubImageAtPoint(Vector2 point, int subImageWidth, int subImageHeight, float subImageScale)
+ {
+ //Create a new Image instance using the texture which has been assigned to the current instance
+ ESImage subImage = new ESImage(texture,subImageScale);
+ // Define the offset of the subimage we want using the point provided
+ subImage.TextureOffsetX = (int) point.X;
+ subImage.TextureOffsetY = (int) point.Y;
+
+ // Set the width and the height of the subimage
+ subImage.ImageWidth = subImageWidth;
+ subImage.ImageHeight = subImageHeight;
+
+ return subImage;
+ }
+ public Vector2 GetTextureCoord ( int x, int y )
+ {
+ return new Vector2(x*texWidthRatio,y*texHeightRatio);
+ }
+ public Vector2[] GetTextureCoordinates(Rectangle textureRect)
+ {
+ Vector2[] coordinates = new Vector2[4];
+
+ coordinates[0] = new Vector2(texWidthRatio * textureRect.Width + (texWidthRatio * textureRect.Left),texHeightRatio * textureRect.Top);
+ coordinates[1] = new Vector2(texWidthRatio * textureRect.Width + (texWidthRatio * textureRect.Left),texHeightRatio * textureRect.Height + (texHeightRatio * textureRect.Top));
+ coordinates[2] = new Vector2(texWidthRatio * textureRect.Left ,texHeightRatio * textureRect.Top);
+ coordinates[3] = new Vector2(texWidthRatio * textureRect.Left,texHeightRatio * textureRect.Height + (texHeightRatio * textureRect.Top));
+
+ return coordinates;
+ }
+
+ public uint Name
+ {
+ get
+ {
+ return texture.Name;
+ }
+ }
+
+ public byte[] PixelData
+ {
+ get
+ {
+ return texture.PixelData;
+ }
+ }
+
+ public SurfaceFormat Format
+ {
+ get
+ {
+ return texture.PixelFormat;
+ }
+ }
+ }
+}
View
352 MonoGame.Framework/Android/Graphics/ESTexture2D.cs
@@ -0,0 +1,352 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.IO;
+using Android.Graphics;
+using OpenTK.Graphics.ES11;
+
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ internal class ESTexture2D : IDisposable
+ {
+ private uint _name;
+ private Size _size;
+ private int _width,_height;
+ private SurfaceFormat _format;
+ private float _maxS,_maxT;
+ private byte[] _pixelData;
+
+ public ESTexture2D (IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter)
+ {
+ InitWithData(data,pixelFormat,width,height,size, filter);
+ }
+
+ public ESTexture2D(Bitmap image, All filter)
+ {
+ InitWithBitmap(image, filter);
+ }
+
+ public void InitWithBitmap(Bitmap image, All filter)
+ {
+ GL.GenTextures(1, ref _name);
+ GL.BindTexture(All.Texture2D, _name);
+ GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)filter);
+ GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)filter);
+
+ Android.Opengl.GLUtils.TexImage2D((int)All.Texture2D, 0, image, 0);
+
+ _size = new Size(image.Width, image.Height);
+ _width = image.Width;
+ _height = image.Height;
+ _format = SurfaceFormat.Rgb32;
+ _maxS = _size.Width / (float)_width;
+ _maxT = _size.Height / (float)_height;
+ }
+
+ public void InitWithData(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter)
+ {
+ GL.GenTextures(1, ref _name);
+ GL.BindTexture(All.Texture2D, _name);
+ GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)filter);
+ GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)filter);
+
+ int sz = 0;
+
+ switch (pixelFormat) {
+ case SurfaceFormat.Rgba32 /*kTexture2DPixelFormat_RGBA8888*/:
+ case SurfaceFormat.Dxt3:
+ sz = 4;
+ GL.TexImage2D(All.Texture2D, 0, (int) All.Rgba, (int) width, (int) height, 0, All.Rgba, All.UnsignedByte, data);
+ break;
+ case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/:
+ sz = 2;
+ GL.TexImage2D(All.Texture2D, 0, (int)All.Rgba, (int)width, (int)height, 0, All.Rgba, All.UnsignedShort4444, data);
+ break;
+ case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/:
+ sz = 2;
+ GL.TexImage2D(All.Texture2D, 0, (int)All.Rgba, (int)width, (int)height, 0, All.Rgba, All.UnsignedShort5551, data);
+ break;
+ case SurfaceFormat.Rgb32 /*kTexture2DPixelFormat_RGB565*/:
+ sz = 2;
+ GL.TexImage2D(All.Texture2D, 0, (int)All.Rgb, (int)width, (int)height, 0, All.Rgb, All.UnsignedShort565, data);
+ break;
+ case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/:
+ sz = 1;
+ GL.TexImage2D(All.Texture2D, 0, (int)All.Alpha, (int)width, (int)height, 0, All.Alpha, All.UnsignedByte, data);
+ break;
+ default:
+ throw new NotSupportedException("Texture format");
+ break;
+ }
+
+
+ // var image = BitmapFactory.DecodeByteArray(data, 0, data.Length);
+ // Android.Opengl.GLUtils.TexImage2D((int)All.Texture2D, 0, image, 0);
+
+ _size = size;
+ _width = width;
+ _height = height;
+ _format = pixelFormat;
+ _maxS = size.Width / (float)width;
+ _maxT = size.Height / (float)height;
+
+ _pixelData = new byte[width * height * sz];
+ Marshal.Copy(data, _pixelData, 0, width * height * sz);
+ // System.Buffer.BlockCopy(data, 0, _pixelData, 0, data.Length);
+ }
+
+ public void Dispose ()
+ {
+ if(_name != 0)
+ {
+ GL.DeleteTextures(1, ref _name);
+ }
+ }
+
+ private static byte GetBits64(ulong source, int first, int length, int shift)
+ {
+ uint[] bitmasks = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+ uint bitmask = bitmasks[length];
+ source = source >> first;
+ source = source & bitmask;
+ source = source << shift;
+ return (byte)source;
+ }
+
+ private static byte GetBits(uint source, int first, int length, int shift)
+ {
+ uint[] bitmasks = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+
+ uint bitmask = bitmasks[length];
+ source = source >> first;
+ source = source & bitmask;
+ source = source << shift;
+ return (byte)source;
+ }
+
+
+ private static void SetColorFromPacked(byte[] data, int offset, byte alpha, uint packed)
+ {
+ byte r = (byte)(GetBits(packed, 0, 8, 0));
+ byte g = (byte)(GetBits(packed, 8, 8, 0));
+ byte b = (byte)(GetBits(packed, 16, 8, 0));
+ data[offset] = r;
+ data[offset + 1] = g;
+ data[offset + 2] = b;
+ data[offset + 3] = alpha;
+ }
+
+ private static void ColorsFromPacked(uint[] colors, uint c0, uint c1, bool flag)
+ {
+ uint rb0, rb1, rb2, rb3, g0, g1, g2, g3;
+
+ rb0 = (c0 << 3 | c0 << 8) & 0xf800f8;
+ rb1 = (c1 << 3 | c1 << 8) & 0xf800f8;
+ rb0 += (rb0 >> 5) & 0x070007;
+ rb1 += (rb1 >> 5) & 0x070007;
+ g0 = (c0 << 5) & 0x00fc00;
+ g1 = (c1 << 5) & 0x00fc00;
+ g0 += (g0 >> 6) & 0x000300;
+ g1 += (g1 >> 6) & 0x000300;
+
+ colors[0] = rb0 + g0;
+ colors[1] = rb1 + g1;
+
+ if (c0 > c1 || flag)
+ {
+ rb2 = (((2 * rb0 + rb1) * 21) >> 6) & 0xff00ff;
+ rb3 = (((2 * rb1 + rb0) * 21) >> 6) & 0xff00ff;
+ g2 = (((2 * g0 + g1) * 21) >> 6) & 0x00ff00;
+ g3 = (((2 * g1 + g0) * 21) >> 6) & 0x00ff00;
+ colors[3] = rb3 + g3;
+ }
+ else
+ {
+ rb2 = ((rb0 + rb1) >> 1) & 0xff00ff;
+ g2 = ((g0 + g1) >> 1) & 0x00ff00;
+ colors[3] = 0;
+ }
+
+ colors[2] = rb2 + g2;
+ }
+
+ static public ESTexture2D InitiFromDxt3File(BinaryReader rdr, int length, int width, int height)
+ {
+ byte [] b = GetBits (width, length, height, rdr);
+
+ // Copy bits
+ IntPtr pointer = Marshal.AllocHGlobal(length);
+ Marshal.Copy (b, 0, pointer, length);
+ ESTexture2D result = new ESTexture2D(pointer,SurfaceFormat.Dxt3,width,height,new Size(width,height),All.Linear);
+ Marshal.FreeHGlobal(pointer);
+ return result;
+ }
+
+ public static byte[] GetBits (int width, int length, int height, BinaryReader rdr)
+ {
+ int xoffset = 0;
+ int yoffset = 0;
+ int rowLength = width * 4;
+ byte[] b = new byte[length];
+ ulong alpha;
+ ushort c0, c1;
+ uint[] colors = new uint[4];
+ uint lu;
+ for (int y = 0; y < height / 4; y++) {
+ yoffset = y * 4;
+ for (int x = 0; x < width / 4; x++) {
+ xoffset = x * 4;
+ alpha = rdr.ReadUInt64 ();
+ c0 = rdr.ReadUInt16 ();
+ c1 = rdr.ReadUInt16 ();
+ ColorsFromPacked (colors, c0, c1, true);
+ lu = rdr.ReadUInt32 ();
+ for (int i = 0; i < 16; i++) {
+ int idx = GetBits (lu, 30 - i * 2, 2, 0);
+ uint ci = colors[idx];
+ int ii = 15 - i;
+ byte a = (byte)(GetBits64 (alpha, ii * 4, 4, 0));
+ a += (byte)(a << 4);
+ int yy = yoffset + (ii / 4);
+ int xx = xoffset + (ii % 4);
+ int offset = yy * rowLength + xx * 4;
+ SetColorFromPacked (b, offset, a, ci);
+ }
+ }
+ }
+ return b;
+ }
+
+ public void DrawAtPoint(Vector2 point)
+ {
+ float []coordinates = { 0, _maxT, _maxS, _maxT, 0, 0,_maxS, 0 };
+ float width = (float)_width * _maxS;
+ float height = (float)_height * _maxT;
+ float []vertices = { -width / 2.0f + point.X, -height / 2.0f + point.Y, 0.0f,
+ width / 2.0f + point.X, -height / 2.0f + point.Y, 0.0f,
+ -width / 2.0f + point.X, height / 2.0f + point.Y, 0.0f,
+ width / 2.0f + point.X, height / 2.0f + point.Y, 0.0f };
+
+ GL.BindTexture(All.Texture2D, _name);
+ GL.VertexPointer(3, All.Float, 0, vertices);
+ GL.TexCoordPointer(2, All.Float, 0, coordinates);
+ GL.DrawArrays(All.TriangleStrip, 0, 4);
+ }
+
+ public void DrawInRect(Rectangle rect)
+ {
+ float[] coordinates = { 0, _maxT,_maxS, _maxT,0, 0,_maxS, 0 };
+ float[] vertices = { rect.Left, rect.Top, 0.0f, rect.Right, rect.Top,0.0f,rect.Left,rect.Bottom,0.0f,rect.Right,rect.Bottom,0.0f };
+
+ GL.BindTexture(All.Texture2D, _name);
+ GL.VertexPointer(3, All.Float, 0, vertices);
+ GL.TexCoordPointer(2, All.Float, 0, coordinates);
+ GL.DrawArrays(All.TriangleStrip, 0, 4);
+ }
+
+ public Size ContentSize
+ {
+ get
+ {
+ return _size;
+ }
+ }
+
+ public SurfaceFormat PixelFormat
+ {
+ get
+ {
+ return _format;
+ }
+ }
+
+ public int PixelsWide
+ {
+ get
+ {
+ return _width;
+ }
+ }
+
+ public int PixelsHigh
+ {
+ get
+ {
+ return _height;
+ }
+ }
+
+ public uint Name
+ {
+ get
+ {
+ return _name;
+ }
+ }
+
+ public float MaxS
+ {
+ get
+ {
+ return _maxS;
+ }
+ }
+
+ public float MaxT
+ {
+ get
+ {
+ return _maxT;
+ }
+ }
+
+ public byte[] PixelData
+ {
+ get
+ {
+ return _pixelData;
+ }
+ }
+ }
+}
View
238 MonoGame.Framework/Android/Graphics/PresentationParameters.cs
@@ -0,0 +1,238 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using Android.Content;
+using Android.Views;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ public class PresentationParameters : IDisposable
+ {
+ #region Constants
+
+ public const int DefaultPresentRate = 60;
+
+ #endregion Constants
+
+ #region Private Fields
+
+ private DepthFormat autoDepthStencilFormat;
+ private int backBufferCount;
+ private SurfaceFormat backBufferFormat;
+ private int backBufferHeight;
+ private int backBufferWidth;
+ private IntPtr deviceWindowHandle;
+ private bool enableAutoDepthStencil;
+ private int fullScreenRefreshRateInHz;
+ // private bool isFullScreen;
+ private int multiSampleQuality;
+ private MultiSampleType multiSampleType;
+ private SwapEffect swapEffect;
+ private bool disposed;
+
+ #endregion Private Fields
+
+ #region Constructors
+
+ public PresentationParameters()
+ {
+ Clear();
+ }
+
+ ~PresentationParameters()
+ {
+ Dispose(false);
+ }
+
+ #endregion Constructors
+
+
+
+
+ #region Properties
+
+ public DepthFormat AutoDepthStencilFormat
+ {
+ get { return autoDepthStencilFormat; }
+ set { autoDepthStencilFormat = value; }
+ }
+
+ public int BackBufferCount
+ {
+ get { return backBufferCount; }
+ set { backBufferCount = value; }
+ }
+
+ public SurfaceFormat BackBufferFormat
+ {
+ get { return backBufferFormat; }
+ set { backBufferFormat = value; }
+ }
+
+ public int BackBufferHeight
+ {
+ get { return backBufferHeight; }
+ set { backBufferHeight = value; }
+ }
+
+ public int BackBufferWidth
+ {
+ get { return backBufferWidth; }
+ set { backBufferWidth = value; }
+ }
+
+ public IntPtr DeviceWindowHandle
+ {
+ get { return deviceWindowHandle; }
+ set { deviceWindowHandle = value; }
+ }
+
+ public bool EnableAutoDepthStencil
+ {
+ get { return enableAutoDepthStencil; }
+ set { enableAutoDepthStencil = value; }
+ }
+
+ public int FullScreenRefreshRateInHz
+ {
+ get { return fullScreenRefreshRateInHz; }
+ set { fullScreenRefreshRateInHz = value; }
+ }
+
+ public bool IsFullScreen
+ {
+ get { return true; }
+ set
+ {
+ //TODO: How to access Activity.requestWindowFeature() ?
+ }
+ }
+
+ public int MultiSampleQuality
+ {
+ get { return multiSampleQuality; }
+ set { multiSampleQuality = value; }
+ }
+
+ public MultiSampleType MultiSampleType
+ {
+ get { return multiSampleType; }
+ set { multiSampleType = value; }
+ }
+
+ public SwapEffect SwapEffect
+ {
+ get { return swapEffect; }
+ set { swapEffect = value; }
+ }
+
+ public DisplayOrientation DisplayOrientation
+ {
+ get;
+ set;
+ }
+
+ public RenderTargetUsage RenderTargetUsage { get; set; }
+
+ #endregion Properties
+
+
+ #region Methods
+
+ public void Clear()
+ {
+ autoDepthStencilFormat = DepthFormat.Unknown;
+ backBufferCount = 0;
+ backBufferFormat = SurfaceFormat.Unknown;
+ backBufferWidth = 320;
+ backBufferHeight = 480;
+ deviceWindowHandle = IntPtr.Zero;
+ enableAutoDepthStencil = false;
+ fullScreenRefreshRateInHz = 0;
+ // isFullScreen = false;
+ multiSampleQuality = 0;
+ multiSampleType = MultiSampleType.None;
+ swapEffect = SwapEffect.Default;
+ this.DisplayOrientation = DisplayOrientation.Default;
+ }
+
+ public PresentationParameters Clone()
+ {
+ PresentationParameters clone = new PresentationParameters();
+ clone.autoDepthStencilFormat = this.autoDepthStencilFormat;
+ clone.backBufferCount = this.backBufferCount;
+ clone.backBufferFormat = this.backBufferFormat;
+ clone.backBufferHeight = this.backBufferHeight;
+ clone.backBufferWidth = this.backBufferWidth;
+ clone.deviceWindowHandle = this.deviceWindowHandle;
+ clone.disposed = this.disposed;
+ clone.enableAutoDepthStencil = this.enableAutoDepthStencil;
+ clone.fullScreenRefreshRateInHz = this.fullScreenRefreshRateInHz;
+ clone.IsFullScreen = this.IsFullScreen;
+ clone.multiSampleQuality = this.multiSampleQuality;
+ clone.multiSampleType = this.multiSampleType;
+ clone.swapEffect = this.swapEffect;
+ return clone;
+ }
+
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposed)
+ {
+ disposed = true;
+ if (disposing)
+ {
+ // Dispose managed resources
+ }
+ // Dispose unmanaged resources
+ }
+ }
+
+ #endregion Methods
+
+ }
+}
View
261 MonoGame.Framework/Android/Graphics/Texture2D.cs
@@ -0,0 +1,261 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System.IO;
+using System;
+using System.Drawing;
+using Android.Graphics;
+using Microsoft.Xna.Framework.Content;
+using OpenTK.Graphics.ES11;
+using Path = System.IO.Path;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ public class Texture2D
+ {
+ private ESImage texture;
+ private string name;
+
+ internal bool IsSpriteFontTexture {get;set;}
+
+ // my change
+ // --------
+ public uint ID
+ {
+ get
+ {
+ return texture.Name;
+ }
+ }
+ // --------
+ internal ESImage Image
+ {
+ get
+ {
+ return texture;
+ }
+ }
+
+ public Rectangle SourceRect
+ {
+ get
+ {
+ return new Rectangle(0,0,texture.ImageWidth, texture.ImageHeight);
+ }
+ }
+
+ internal Texture2D(ESImage theImage)
+ {
+ texture = theImage;
+ }
+
+ public Texture2D(GraphicsDevice graphicsDevice, int width, int height, int numberLevels, TextureUsage usage, SurfaceFormat format)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Texture2D(Texture2D source, Color color)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Color GetPixel(int x, int y)
+ {
+
+ byte r = texture.PixelData[((y * texture.ImageWidth) + x)];
+ byte g = texture.PixelData[((y * texture.ImageWidth) + x) + 1];
+ byte b = texture.PixelData[((y * texture.ImageWidth) + x) + 2];
+ byte a = texture.PixelData[((y * texture.ImageWidth) + x) + 3];
+
+ return new Color(r, g, b, a);
+ }
+
+ public void SetPixel(int x, int y, byte red, byte green, byte blue, byte alpha)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetData<T>(T[] data)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int Width
+ {
+ get
+ {
+ return texture.ImageWidth;
+ }
+ }
+
+ public int Height
+ {
+ get
+ {
+ return texture.ImageHeight;
+ }
+ }
+
+ public SurfaceFormat Format
+ {
+ get
+ {
+ return texture.Format;
+ }
+ }
+
+ public TextureUsage TextureUsage
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public Object Tag
+ {
+ get { return null; }
+ set { throw new NotImplementedException(); }
+ }
+
+ public string Name
+ {
+ get
+ {
+ return name;
+ }
+ set
+ {
+ name = value;
+ }
+ }
+
+ public static Texture2D FromFile(GraphicsDevice graphicsDevice, Stream textureStream)
+ {
+ Bitmap image = BitmapFactory.DecodeStream(textureStream);
+
+ if (image == null)
+ {
+ throw new ContentLoadException("Error loading Texture2D Stream");
+ }
+
+ ESImage theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
+ Texture2D result = new Texture2D(theTexture);
+
+ return result;
+ }
+
+ public static Texture2D FromFile(GraphicsDevice graphicsDevice, Stream textureStream, int numberBytes)
+ {
+ throw new NotImplementedException();
+ }
+
+ public static Texture2D FromFile(GraphicsDevice graphicsDevice, string filename, int width, int height)
+ {
+ throw new NotImplementedException();
+
+ // return FromFile( graphicsDevice, filename);
+ // Resizing texture before returning it, not yet implemented
+ }
+
+ public static Texture2D FromFile(GraphicsDevice graphicsDevice, string filename)
+ {
+ Bitmap image = BitmapFactory.DecodeFile(filename);
+ if (image == null)
+ {
+ throw new ContentLoadException("Error loading file: " + filename);
+ }
+
+ ESImage theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
+ Texture2D result = new Texture2D(theTexture);
+ result.Name = Path.GetFileNameWithoutExtension(filename);
+ return result;
+ }
+
+ public void SetData<T>(T[] data, int startIndex, int elementCount, SetDataOptions options)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount, SetDataOptions options)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void GetData<T>(ref T[] data)
+ {
+ if (data == null )
+ {
+ throw new ArgumentException("data cannot be null");
+ }
+
+ int mult = (this.Format == SurfaceFormat.Alpha8) ? 1 : 4;
+
+ if (data.Length < Width * Height * mult)
+ {
+ throw new ArgumentException("data is the wrong length for Pixel Format");
+ }
+
+ // Get the Color values
+ if ((typeof(T) == typeof(Color)))
+ {
+ int i = 0;
+
+ while (i < data.Length)
+ {
+ var d = (Color)(object)data[i];
+ d = new Color(texture.PixelData[i], texture.PixelData[i+1], texture.PixelData[i+2], texture.PixelData[i+3]);
+ i += 4;
+ }
+ }
+ }
+
+ public void GetData<T>(T[] data, int startIndex, int elementCount)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void GetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
+
View
95 MonoGame.Framework/Android/Input/Accelerometer.cs
@@ -0,0 +1,95 @@
+// #region License
+// /*
+// Microsoft Public License (Ms-PL)
+// MonoGame - Copyright © 2009 The MonoGame Team
+//
+// All rights reserved.
+//
+// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+// accept the license, do not use the software.
+//
+// 1. Definitions
+// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+// U.S. copyright law.
+//
+// A "contribution" is the original software, or any additions or changes to the software.
+// A "contributor" is any person that distributes its contribution under this license.
+// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
+//
+// 2. Grant of Rights
+// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+//
+// 3. Conditions and Limitations
+// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+// your patent license from such contributor to the software ends automatically.
+// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+// notices that are present in the software.
+// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+// code form, you may only do so under a license that complies with this license.
+// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+// permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+// purpose and non-infringement.
+// */
+// #endregion License
+//
+
+using System;
+using Android.Content;
+using Android.Hardware;
+
+
+namespace Microsoft.Xna.Framework.Input
+{
+ public static class Accelerometer
+ {
+ private static AccelerometerState _state;
+ private static AccelerometerCapabilities _capabilities = new AccelerometerCapabilities();
+ private static SensorManager _sensorManger;
+ private static Sensor _sensor;
+
+ static Accelerometer()
+ {
+ _sensorManger = (SensorManager)Game.contextInstance.GetSystemService(Context.SensorService);
+ _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer);
+ }
+
+ public static void SetupAccelerometer()
+ {
+ _sensorManger.RegisterListener(new SensorListener(), _sensor, SensorDelay.Game);
+ }
+
+ public static AccelerometerCapabilities GetCapabilities()
+ {
+ return _capabilities;
+ }
+
+ public static AccelerometerState GetState()
+ {
+ return _state;
+ }
+
+ private class SensorListener : ISensorEventListener
+ {
+ public IntPtr Handle
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public void OnAccuracyChanged(Sensor sensor, int accuracy)
+ {
+ //do nothing
+ }
+
+ public void OnSensorChanged(SensorEvent e)
+ {
+ _state.Acceleration = new Vector3(e.Values[0], e.Values[1], e.Values[2]);
+ }
+ }
+ }
+}
View
100 MonoGame.Framework/Android/Input/AccelerometerCapabilities.cs
@@ -0,0 +1,100 @@
+// #region License
+// /*
+// Microsoft Public License (Ms-PL)
+// MonoGame - Copyright © 2009 The MonoGame Team
+//
+// All rights reserved.
+//
+// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+// accept the license, do not use the software.
+//
+// 1. Definitions
+// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+// U.S. copyright law.
+//
+// A "contribution" is the original software, or any additions or changes to the software.
+// A "contributor" is any person that distributes its contribution un