Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Windows:

 FullScreen, UserResize, Scaling (Scaling might be not fully functional though)
 MouseMovement


git-svn-id: https://xnatouch.svn.codeplex.com/svn@59072 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
commit d5524e2dc861d3551605303b00a69d6bc9f4eb0e 1 parent f9157cd
SND\taskbit_cp authored
View
4 MonoGame.Framework/MonoGame.Framework.Windows.csproj
@@ -44,6 +44,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System.Drawing" />
@@ -197,6 +198,9 @@
<Folder Include="GamerServices\" />
<Folder Include="Net\" />
</ItemGroup>
+ <ItemGroup>
+ <WCFMetadata Include="Service References\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
44 MonoGame.Framework/Windows/Graphics/GraphicsDevice.cs
@@ -52,11 +52,12 @@ public class GraphicsDevice : IDisposable
private All _preferedFilter;
private int _activeTexture = -1;
private Viewport _viewport;
- private GraphicsDevice2D _spriteDevice;
+ internal GraphicsDevice2D spriteDevice;
private bool _isDisposed = false;
- private readonly DisplayMode _displayMode;
+ private DisplayMode _displayMode;
private RenderState _renderState;
-
+ internal GraphicsDeviceManager mngr;
+
internal All PreferedFilter
{
get
@@ -90,7 +91,21 @@ public bool IsDisposed
}
}
- internal GraphicsDevice(int width, int height)
+ internal GraphicsDevice(GraphicsDeviceManager mngr)
+ {
+ this.mngr = mngr;
+ _displayMode = new DisplayMode(this.mngr.PreferredBackBufferWidth, this.mngr.PreferredBackBufferHeight);
+
+ // Create the Sprite Rendering engine
+ spriteDevice = new GraphicsDevice2D(this);
+
+ // Init RenderState
+ _renderState = new RenderState();
+
+ SizeChanged(this.mngr.PreferredBackBufferWidth, this.mngr.PreferredBackBufferHeight);
+ }
+
+ internal void SizeChanged(int width, int height)
{
_displayMode = new DisplayMode(width, height);
@@ -102,15 +117,12 @@ internal GraphicsDevice(int width, int height)
_viewport.Height = DisplayMode.Height;
_viewport.TitleSafeArea = new Rectangle(0, 0, DisplayMode.Width, DisplayMode.Height);
- // Create the Sprite Rendering engine
- _spriteDevice = new GraphicsDevice2D(this);
-
- // Init RenderState
- _renderState = new RenderState();
- }
+ if (PresentationParameters != null) {
+ PresentationParameters.BackBufferWidth = width;
+ PresentationParameters.BackBufferHeight = height;
+ }
- public GraphicsDevice() :this(500, 500)
- {
+ spriteDevice.SizeChanged();
}
public void Clear(Color color)
@@ -229,17 +241,17 @@ public Microsoft.Xna.Framework.Graphics.GraphicsProfile GraphicsProfile
internal void StartSpriteBatch(SpriteBlendMode blendMode, SpriteSortMode sortMode)
{
- _spriteDevice.StartSpriteBatch(blendMode,sortMode);
+ spriteDevice.StartSpriteBatch(blendMode,sortMode);
}
internal void EndSpriteBatch()
{
- _spriteDevice.EndSpriteBatch();
+ spriteDevice.EndSpriteBatch();
}
internal void AddToSpriteBuffer(SpriteBatchRenderItem sbItem)
{
- _spriteDevice.AddToSpriteBuffer(sbItem);
+ spriteDevice.AddToSpriteBuffer(sbItem);
}
internal void RenderSprites(Vector2 point, float[] texCoords, float[] quadVertices, RenderMode renderMode)
@@ -250,6 +262,8 @@ internal void RenderSprites(Vector2 point, float[] texCoords, float[] quadVertic
// Enable Texture_2D
GL.Enable(EnableCap.Texture2D);
+
+ spriteDevice.ApplyScale();
// Set the glColor to apply alpha to the image
Vector4 color = renderMode.FilterColor.ToEAGLColor();
View
51 MonoGame.Framework/Windows/Graphics/GraphicsDevice2D.cs
@@ -42,7 +42,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-
+using System.Windows.Forms;
using OpenTK.Graphics.OpenGL;
namespace Microsoft.Xna.Framework.Graphics
@@ -141,25 +141,48 @@ internal class GraphicsDevice2D
private GraphicsDevice _device;
private readonly List<SpriteBatchRenderItem> _sprites = new List<SpriteBatchRenderItem>();
private SpriteBlendMode _actualBlendMode;
- private SpriteSortMode _actualSortMode = SpriteSortMode.Deferred;
-
+ private SpriteSortMode _actualSortMode = SpriteSortMode.Deferred;
+
public GraphicsDevice2D (GraphicsDevice Device)
{
_device = Device;
-
- // TODO Initialise2DOpenGL();
}
-
+
+ public void SizeChanged()
+ {
+ // Set up OpenGL projection matrix
+ GL.MatrixMode(MatrixMode.Projection);
+ GL.LoadIdentity();
+ GL.Ortho(0, _device.DisplayMode.Width, _device.DisplayMode.Height, 0, -1, 1);
+
+ GL.MatrixMode(MatrixMode.Modelview);
+ GL.Viewport(0, 0, _device.DisplayMode.Width, _device.DisplayMode.Height);
+ }
+
+ public void ApplyScale()
+ {
+ GL.Scale(ScaleW, ScaleH, 1);
+ }
+
+ public float ScaleH
+ {
+ get
+ {
+ //GL.Scale(scaleW, scaleH, 1);
+ return _device.DisplayMode.Height / _device.mngr.PreferredBackBufferHeight;
+ }
+ }
+
+ public float ScaleW
+ {
+ get
+ {
+ return _device.DisplayMode.Width/_device.mngr.PreferredBackBufferWidth;
+ }
+ }
+
public void Initialise2DOpenGL()
{
- // Set up OpenGL projection matrix
- GL.MatrixMode(MatrixMode.Projection);
- GL.LoadIdentity();
- GL.Ortho(0, _device.DisplayMode.Width, _device.DisplayMode.Height, 0, -1, 1);
-
- GL.MatrixMode(MatrixMode.Modelview);
- GL.Viewport(0, 0, _device.DisplayMode.Width, _device.DisplayMode.Height);
-
// Initialize OpenGL states
GL.Disable(EnableCap.DepthTest);
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode,(int) All.BlendSrc);
View
31 MonoGame.Framework/Windows/Graphics/GraphicsDeviceManager.cs
@@ -39,7 +39,9 @@ 1. Definitions
#endregion License
using System;
-
+using System.Drawing;
+using System.Windows.Forms;
+using OpenTK;
using OpenTK.Graphics.OpenGL;
using Microsoft.Xna.Framework.Graphics;
@@ -117,16 +119,15 @@ public void Dispose()
public void ApplyChanges()
{
+ (_game.Window as WindowsGameWindow).OpenTkGameWindow.ClientSize = new Size(PreferredBackBufferWidth, PreferredBackBufferHeight);
}
private void Initialize()
{
- _graphicsDevice = new GraphicsDevice(_preferredBackBufferWidth, _preferredBackBufferHeight);
+ _graphicsDevice = new GraphicsDevice(this);
_graphicsDevice.PresentationParameters = new PresentationParameters();
- // Set "full screen" as default
- _graphicsDevice.PresentationParameters.IsFullScreen = true;
-
+
if (_preferMultiSampling)
{
_graphicsDevice.PreferedFilter = All.Linear;
@@ -135,6 +136,7 @@ private void Initialize()
{
_graphicsDevice.PreferedFilter = All.Nearest;
}
+
}
public void ToggleFullScreen()
@@ -158,7 +160,23 @@ public bool IsFullScreen
}
set
{
- _graphicsDevice.PresentationParameters.IsFullScreen = value;
+ if (IsFullScreen != value)
+ {
+ _graphicsDevice.PresentationParameters.IsFullScreen = value;
+ var wGameWindow = _game.Window as WindowsGameWindow;
+
+ if (IsFullScreen)
+ {
+ wGameWindow.OpenTkGameWindow.WindowBorder = WindowBorder.Hidden;
+ wGameWindow.OpenTkGameWindow.WindowState = OpenTK.WindowState.Fullscreen;
+ _graphicsDevice.SizeChanged(wGameWindow.OpenTkGameWindow.ClientRectangle.Width, wGameWindow.OpenTkGameWindow.ClientRectangle.Height);
+ }
+ else {
+ wGameWindow.OpenTkGameWindow.WindowState = OpenTK.WindowState.Normal;
+ wGameWindow.OpenTkGameWindow.WindowBorder = WindowBorder.Resizable;
+ _graphicsDevice.SizeChanged(wGameWindow.OpenTkGameWindow.ClientRectangle.Width, wGameWindow.OpenTkGameWindow.ClientRectangle.Height);
+ }
+ }
}
}
@@ -202,6 +220,7 @@ public int PreferredBackBufferHeight
set
{
_preferredBackBufferHeight = value;
+
}
}
View
13 MonoGame.Framework/Windows/Graphics/PresentationParameters.cs
@@ -133,16 +133,9 @@ public int FullScreenRefreshRateInHz
{
get { return fullScreenRefreshRateInHz; }
set { fullScreenRefreshRateInHz = value; }
- }
-
- public bool IsFullScreen
- {
- get { return true; }
- set
- {
- //TODO: How to access Activity.requestWindowFeature() ?
- }
- }
+ }
+
+ public bool IsFullScreen { get; set; }
public int MultiSampleQuality
{
View
8 MonoGame.Framework/Windows/Graphics/SpriteBatch.cs
@@ -33,9 +33,9 @@ public SpriteBatch ( GraphicsDevice graphicsDevice )
throw new ArgumentException("graphicsDevice");
}
- _graphicsDevice = graphicsDevice;
-
- _batcher = new SpriteBatcher();
+ _graphicsDevice = graphicsDevice;
+
+ _batcher = new SpriteBatcher(_graphicsDevice);
}
public void Begin()
@@ -570,6 +570,8 @@ float depth
{
throw new ArgumentException("spriteFont");
}
+
+
Vector2 p = new Vector2(-origin.X,-origin.Y);
View
12 MonoGame.Framework/Windows/Graphics/SpriteBatcher.cs
@@ -47,8 +47,9 @@
namespace Microsoft.Xna.Framework.Graphics
{
- internal class SpriteBatcher
- {
+ internal class SpriteBatcher
+ {
+ GraphicsDevice _graphicsDevice;
List<SpriteBatchItem> _batchItemList;
Queue<SpriteBatchItem> _freeBatchItemQueue;
VertexPosition2ColorTexture[] _vertexArray;
@@ -56,8 +57,9 @@ internal class SpriteBatcher
GCHandle _vertexHandle;
GCHandle _indexHandle;
- public SpriteBatcher ()
- {
+ public SpriteBatcher(GraphicsDevice graphicsDevice)
+ {
+ _graphicsDevice = graphicsDevice;
_batchItemList = new List<SpriteBatchItem>(256);
_freeBatchItemQueue = new Queue<SpriteBatchItem>(256);
@@ -103,6 +105,8 @@ public void DrawBatch ( SpriteSortMode sortMode )
// nothing to do
if ( _batchItemList.Count == 0 )
return;
+
+ _graphicsDevice.spriteDevice.ApplyScale();
// sort the batch items
switch ( sortMode )
View
50 MonoGame.Framework/Windows/WindowsGameWindow.cs
@@ -40,9 +40,12 @@ 1. Definitions
#region Using Statements
using System;
+using System.Windows.Forms;
+using Microsoft.Xna.Framework.Input;
using OpenTK;
using OpenTK.Graphics;
+
#endregion Using Statements
namespace Microsoft.Xna.Framework
@@ -68,6 +71,7 @@ private void Initialize()
OpenTkGameWindow = new OpenTK.GameWindow();
OpenTkGameWindow.RenderFrame += OnRenderFrame;
OpenTkGameWindow.UpdateFrame += OnUpdateFrame;
+ OpenTkGameWindow.Resize += OnResize;
clientBounds = new Rectangle(0, 0, OpenTkGameWindow.Width, OpenTkGameWindow.Height);
// Initialize GameTime
@@ -76,10 +80,19 @@ private void Initialize()
// Initialize _lastUpdate
_lastUpdate = DateTime.Now;
+
+ //Default no resizing
+ AllowUserResizing = false;
}
#region GameWindow Methods
+ private void OnResize(object sender, EventArgs e)
+ {
+ Game.GraphicsDevice.SizeChanged(OpenTkGameWindow.ClientRectangle.Width, OpenTkGameWindow.ClientRectangle.Height);
+ OnClientSizeChanged();
+ }
+
private void OnRenderFrame(object sender, FrameEventArgs e)
{
if (GraphicsContext.CurrentContext == null || GraphicsContext.CurrentContext.IsDisposed)
@@ -100,13 +113,20 @@ private void OnRenderFrame(object sender, FrameEventArgs e)
private void OnUpdateFrame(object sender, FrameEventArgs e)
{
- if (Game != null )
- {
- _now = DateTime.Now;
+ if (Game != null ) {
+
+ HandleInput();
+
+ _now = DateTime.Now;
_updateGameTime.Update(_now - _lastUpdate);
Game.DoUpdate(_updateGameTime);
}
}
+
+ private void HandleInput()
+ {
+ Mouse.SetPosition(OpenTkGameWindow.Mouse.X, OpenTkGameWindow.Mouse.Y);
+ }
#endregion
@@ -139,17 +159,19 @@ public new string Title
set { SetTitle(value); }
}
- public override bool AllowUserResizing
- {
- get
- {
- return false;
- }
- set
- {
- // Do nothing; Ignore rather than raising and exception
- }
- }
+ private bool _allowUserResizing;
+ public override bool AllowUserResizing
+ {
+ get { return _allowUserResizing; }
+ set
+ {
+ _allowUserResizing = value;
+
+ if (_allowUserResizing)
+ OpenTkGameWindow.WindowBorder = WindowBorder.Resizable;
+ else OpenTkGameWindow.WindowBorder = WindowBorder.Fixed;
+ }
+ }
private DisplayOrientation _currentOrientation;
public override DisplayOrientation CurrentOrientation
Please sign in to comment.
Something went wrong with that request. Please try again.