From 506adf4d0bbc024b24c74d6522727c59312080cf Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 31 Jul 2014 01:42:58 +0800 Subject: [PATCH] Improved Manager for software cursor support Added ShowSoftwareCursor property, and automatic cursor loading if required. --- Manager.cs | 80 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/Manager.cs b/Manager.cs index 669c23e..24fc0d8 100644 --- a/Manager.cs +++ b/Manager.cs @@ -6,15 +6,16 @@ // // // File: Manager.cs // // // -// Version: 0.7 // +// Version: 0.8 // // // -// Date: 11/09/2010 // +// Date: 05/07/2014 // // // -// Author: Tom Shane // +// Author: Nathan 'Grimston' Pipes // // // //////////////////////////////////////////////////////////////// // // -// Copyright (c) by Tom Shane // +// Copyright (c) by Tom Shane 2010 // +// Copyright (c) by Nathan Pipes 2014 // // // //////////////////////////////////////////////////////////////// @@ -118,8 +119,8 @@ private struct ControlStates private bool autoUnfocus = true; private bool autoCreateRenderTarget = true; private Cursor cursor = null; + private bool softwareCursor = false; - //////////////////////////////////////////////////////////////////////////// #endregion @@ -144,6 +145,15 @@ public Cursor Cursor get { return cursor; } set { cursor = value; } } + + /// + /// Should a software cursor be drawn? Very handy on a PC build. + /// + public bool ShowSoftwareCursor + { + get { return softwareCursor; } + set { softwareCursor = value; } + } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -1150,47 +1160,47 @@ public override void Draw(GameTime gameTime) //if (targetFrames == 0 || (ms == 0 || ms >= (1000f / targetFrames))) //{ - TimeSpan span = TimeSpan.FromTicks(drawTime); - gameTime = new GameTime(gameTime.TotalGameTime, span); - drawTime = 0; + TimeSpan span = TimeSpan.FromTicks(drawTime); + gameTime = new GameTime(gameTime.TotalGameTime, span); + drawTime = 0; - if ((controls != null)) - { - ControlsList list = new ControlsList(); - list.AddRange(controls); + if ((controls != null)) + { + ControlsList list = new ControlsList(); + list.AddRange(controls); - foreach (Control c in list) - { - c.PrepareTexture(renderer, gameTime); - } + foreach (Control c in list) + { + c.PrepareTexture(renderer, gameTime); + } - GraphicsDevice.SetRenderTarget(renderTarget); - GraphicsDevice.Clear(Color.Transparent); + GraphicsDevice.SetRenderTarget(renderTarget); + GraphicsDevice.Clear(Color.Transparent); - if (renderer != null) + if (renderer != null) + { + foreach (Control c in list) { - foreach (Control c in list) - { - c.Render(renderer, gameTime); - } + c.Render(renderer, gameTime); } } + } - if (Cursor != null) + if (softwareCursor && Cursor != null) + { + if (this.cursor.CursorTexture == null) { - if (this.cursor.CursorTexture == null) - { - this.cursor.CursorTexture = Texture2D.FromStream(GraphicsDevice, new FileStream( - this.cursor.cursorPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)); - } - renderer.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); - MouseState mstate = Mouse.GetState(); - Rectangle rect = new Rectangle(mstate.X, mstate.Y, Cursor.Width, Cursor.Height); - renderer.SpriteBatch.Draw(Cursor.CursorTexture, rect, null, Color.White, 0f, Cursor.HotSpot, SpriteEffects.None, 0f); - renderer.SpriteBatch.End(); + this.cursor.CursorTexture = Texture2D.FromStream(GraphicsDevice, new FileStream( + this.cursor.cursorPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)); } + renderer.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); + MouseState mstate = Mouse.GetState(); + Rectangle rect = new Rectangle(mstate.X, mstate.Y, Cursor.Width, Cursor.Height); + renderer.SpriteBatch.Draw(Cursor.CursorTexture, rect, null, Color.White, 0f, Cursor.HotSpot, SpriteEffects.None, 0f); + renderer.SpriteBatch.End(); + } - GraphicsDevice.SetRenderTarget(null); + GraphicsDevice.SetRenderTarget(null); //} } else