2012-08-09 09:45:04 +00:00
|
|
|
#region Using Statements
|
2011-11-08 00:37:48 +00:00
|
|
|
using System;
|
|
|
|
using ANX.Framework.Graphics;
|
2012-08-29 12:46:08 +00:00
|
|
|
using ANX.Framework.NonXNA.Development;
|
2011-11-08 00:37:48 +00:00
|
|
|
|
|
|
|
#endregion // Using Statements
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-11-08 00:37:48 +00:00
|
|
|
|
2012-12-04 09:40:37 +00:00
|
|
|
#region Patch-Log
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 12/03/2012 #13365 clcrutch
|
|
|
|
|
|
|
|
*/
|
|
|
|
#endregion
|
|
|
|
|
2011-11-08 00:37:48 +00:00
|
|
|
namespace ANX.Framework
|
|
|
|
{
|
2012-08-29 12:46:08 +00:00
|
|
|
[PercentageComplete(100)]
|
|
|
|
[TestState(TestStateAttribute.TestState.Untested)]
|
2012-08-29 13:14:00 +00:00
|
|
|
[Developer("Glatzemann")]
|
2011-11-08 00:37:48 +00:00
|
|
|
public class DrawableGameComponent : GameComponent, IDrawable
|
|
|
|
{
|
2012-08-29 12:46:08 +00:00
|
|
|
#region Private Members
|
2011-11-08 00:37:48 +00:00
|
|
|
private bool isInitialized;
|
|
|
|
private IGraphicsDeviceService device;
|
2012-08-29 12:46:08 +00:00
|
|
|
private int drawOrder;
|
|
|
|
private bool visible = true;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
public event EventHandler<EventArgs> DrawOrderChanged;
|
|
|
|
public event EventHandler<EventArgs> VisibleChanged;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
public DrawableGameComponent(Game game)
|
|
|
|
: base(game)
|
|
|
|
{
|
|
|
|
}
|
2011-11-08 00:37:48 +00:00
|
|
|
|
|
|
|
public GraphicsDevice GraphicsDevice
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (this.device == null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Component is not initialized");
|
|
|
|
}
|
|
|
|
return this.device.GraphicsDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int DrawOrder
|
|
|
|
{
|
|
|
|
get { return drawOrder; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (drawOrder != value)
|
|
|
|
{
|
|
|
|
drawOrder = value;
|
|
|
|
OnDrawOrderChanged(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Visible
|
|
|
|
{
|
|
|
|
get { return visible; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (visible != value)
|
|
|
|
{
|
|
|
|
visible = value;
|
|
|
|
OnVisibleChanged(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnDrawOrderChanged(object sender, EventArgs arg)
|
|
|
|
{
|
|
|
|
if (DrawOrderChanged != null)
|
|
|
|
{
|
|
|
|
DrawOrderChanged(sender, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnVisibleChanged(object sender, EventArgs arg)
|
|
|
|
{
|
|
|
|
if (VisibleChanged != null)
|
|
|
|
{
|
|
|
|
VisibleChanged(sender, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
{
|
|
|
|
base.Initialize();
|
|
|
|
if (!isInitialized)
|
|
|
|
{
|
|
|
|
this.device = base.Game.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
|
|
|
|
if (this.device == null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Service not found: IGraphicsDeviceService");
|
|
|
|
}
|
|
|
|
this.device.DeviceCreated += OnDeviceCreated;
|
two commits were missing, both by KorsarNek:
"Removed the SupportedPlatformsImpl classes and replaced them with a new SupportedPlatforms attribute on the assembly level.
Removed a few class constructors which could cause problems when loading a game.
Made ResetElapsedTime in the game class reset to 0 instead of TimeSpan.MinValue.
Removed the restriction in the InputDeviceFactory for which InputDevices are supported.
Added a Logger for Metro which works with the current Logger implementation.
Changed that when a platform is recognized that is higher than Windows 8, it gets treated like Windows 8, not like Windows 7.
Due to the SupportedPlatforms change, the assembly loader is now faster in finding out which assemblies contains addIns. For not Metro system, it's also added that a warning gets written if an AddIn references a different ANX version than that of the running assembly.
OpenGL and DirectX have been updated to the newest versions.
XAudio system uses now the same SharpDX version as all the other systems.
ParameterBuffer for WindowsMetro gets now correctly created by considering the size constraints for constant buffers.
Fixed an erroneous finalizer in the xaudio system.
Made the metro projects convert to Windows 8.1, as Windows 8.0 is not supported by the newer SharpDX versions. It's now also necessary to use at least Visual Studio 2013 to build the Metro versions.
Made the samples work again on Windows."
"Fixed the creation of the swap chain for windows metro and removed the dependency of the Metro Rendersystem onto the Metro Platformsytem.
All occurrences of WindowHandles have been replaced with a custom WindowHandle type which should work out of the box in most cases, but does still represent a breaking change to XNA.
The ProjectConverter for Metro was adjusted so that with just changing the way the application is initialized, most projects that worked with ANX before should now work under win rt. The sample SimpleNoContent does now work out of the box for win rt, after a project conversion.
The application name for win rt apps is now a guid, the display name stayed the same though. That's to be more compliant with the way win rt apps are normally created.
The default namespace and namespace of the classes for the Sample "SimpleNoContent" is renamed from "SimpleModernUI" to "SimpleNoContent".
With the new way win rt apps are initialized for ANX, it's necessary to first create the WindowsGameHost for WinRT with a handler how to create the game instance and give that to the CoreApplication object to run it.
Also took care of a few annoying bugs when working with win rt and ANX where no InputDevices could be created on the first frame (Issue #1164 ) and that it wasn't possible to use the localfolder of the application on the first update and all the other stuff for which an instance of the Application class was necessary."
2015-03-29 13:48:33 +02:00
|
|
|
this.device.DeviceReset += OnDeviceReset;
|
2011-11-08 00:37:48 +00:00
|
|
|
this.device.DeviceDisposing += OnDeviceDisposing;
|
2012-12-03 08:17:09 +00:00
|
|
|
|
|
|
|
if (this.device.GraphicsDevice != null)
|
|
|
|
{
|
|
|
|
LoadContent();
|
|
|
|
}
|
2011-11-08 00:37:48 +00:00
|
|
|
}
|
|
|
|
isInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
if (disposing)
|
|
|
|
{
|
|
|
|
this.UnloadContent();
|
|
|
|
if (this.device != null)
|
|
|
|
{
|
|
|
|
this.device.DeviceCreated -= OnDeviceCreated;
|
two commits were missing, both by KorsarNek:
"Removed the SupportedPlatformsImpl classes and replaced them with a new SupportedPlatforms attribute on the assembly level.
Removed a few class constructors which could cause problems when loading a game.
Made ResetElapsedTime in the game class reset to 0 instead of TimeSpan.MinValue.
Removed the restriction in the InputDeviceFactory for which InputDevices are supported.
Added a Logger for Metro which works with the current Logger implementation.
Changed that when a platform is recognized that is higher than Windows 8, it gets treated like Windows 8, not like Windows 7.
Due to the SupportedPlatforms change, the assembly loader is now faster in finding out which assemblies contains addIns. For not Metro system, it's also added that a warning gets written if an AddIn references a different ANX version than that of the running assembly.
OpenGL and DirectX have been updated to the newest versions.
XAudio system uses now the same SharpDX version as all the other systems.
ParameterBuffer for WindowsMetro gets now correctly created by considering the size constraints for constant buffers.
Fixed an erroneous finalizer in the xaudio system.
Made the metro projects convert to Windows 8.1, as Windows 8.0 is not supported by the newer SharpDX versions. It's now also necessary to use at least Visual Studio 2013 to build the Metro versions.
Made the samples work again on Windows."
"Fixed the creation of the swap chain for windows metro and removed the dependency of the Metro Rendersystem onto the Metro Platformsytem.
All occurrences of WindowHandles have been replaced with a custom WindowHandle type which should work out of the box in most cases, but does still represent a breaking change to XNA.
The ProjectConverter for Metro was adjusted so that with just changing the way the application is initialized, most projects that worked with ANX before should now work under win rt. The sample SimpleNoContent does now work out of the box for win rt, after a project conversion.
The application name for win rt apps is now a guid, the display name stayed the same though. That's to be more compliant with the way win rt apps are normally created.
The default namespace and namespace of the classes for the Sample "SimpleNoContent" is renamed from "SimpleModernUI" to "SimpleNoContent".
With the new way win rt apps are initialized for ANX, it's necessary to first create the WindowsGameHost for WinRT with a handler how to create the game instance and give that to the CoreApplication object to run it.
Also took care of a few annoying bugs when working with win rt and ANX where no InputDevices could be created on the first frame (Issue #1164 ) and that it wasn't possible to use the localfolder of the application on the first update and all the other stuff for which an instance of the Application class was necessary."
2015-03-29 13:48:33 +02:00
|
|
|
this.device.DeviceReset -= OnDeviceReset;
|
2011-11-08 00:37:48 +00:00
|
|
|
this.device.DeviceDisposing -= OnDeviceDisposing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
base.Dispose(disposing);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void LoadContent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void UnloadContent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-10 13:24:34 +00:00
|
|
|
public virtual void Draw(GameTime gameTime)
|
2011-11-08 00:37:48 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDeviceCreated(object sender, EventArgs arg)
|
|
|
|
{
|
|
|
|
this.LoadContent();
|
|
|
|
}
|
|
|
|
|
2012-12-03 08:17:09 +00:00
|
|
|
private void OnDeviceReset(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
this.LoadContent();
|
|
|
|
}
|
|
|
|
|
2011-11-08 00:37:48 +00:00
|
|
|
private void OnDeviceDisposing(object sender, EventArgs arg)
|
|
|
|
{
|
|
|
|
this.UnloadContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|