From a47ec71bc274cbedeca7846cbdd8f62aeba1671b Mon Sep 17 00:00:00 2001 From: "nathan@daedalus" Date: Fri, 23 Mar 2012 23:54:58 -0500 Subject: [PATCH] Fixing issue with UI objects and collision with mouse pointer --- axios/Engine/AxiosGameScreen.cs | 11 +++++++---- axios/Engine/Structures/AxiosPoint.cs | 2 +- axios/Engine/Structures/AxiosRectangle.cs | 6 +++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/axios/Engine/AxiosGameScreen.cs b/axios/Engine/AxiosGameScreen.cs index 4b725be..223f7ca 100644 --- a/axios/Engine/AxiosGameScreen.cs +++ b/axios/Engine/AxiosGameScreen.cs @@ -20,6 +20,7 @@ using Axios.Engine.UI; using Axios.Engine.Log; using Axios.Engine.File; using System.IO; +using Axios.Engine.Structures; namespace Axios.Engine { @@ -280,19 +281,21 @@ namespace Axios.Engine } Vector2 uiobjpos; - Rectangle uirect; + //Rectangle uirect; + AxiosRectangle uirect; bool foundobject = false; - Vector2 mousepos = ConvertUnits.ToSimUnits(input.Cursor); + Vector2 mousepos = this.Camera.ConvertScreenToWorld(input.Cursor); //Vector2 objpos; //System.Diagnostics.Debugger.Break(); + AxiosRectangle mousrect = new AxiosRectangle(mousepos.X, mousepos.Y, ConvertUnits.ToSimUnits(25), ConvertUnits.ToSimUnits(25)); foreach(AxiosUIObject uiobject in _uiobjects) { uiobjpos = uiobject.Position; //objpos = this.Camera.ConvertScreenToWorld(uiobjpos); - uirect = new Rectangle((int)uiobjpos.X, (int)uiobjpos.Y, (int)Math.Ceiling(ConvertUnits.ToSimUnits(uiobject.Width)), (int)Math.Ceiling(ConvertUnits.ToSimUnits(uiobject.Height) + 1)); + uirect = new AxiosRectangle(uiobjpos.X, uiobjpos.Y, ConvertUnits.ToSimUnits(uiobject.Width), ConvertUnits.ToSimUnits(uiobject.Height)); - if (uirect.Contains((int)position.X, (int)position.Y)) + if (uirect.Intersect(mousrect)) { if (input.IsNewMouseButtonPress(MouseButtons.LeftButton)) diff --git a/axios/Engine/Structures/AxiosPoint.cs b/axios/Engine/Structures/AxiosPoint.cs index 60aeefc..f0dc5a4 100644 --- a/axios/Engine/Structures/AxiosPoint.cs +++ b/axios/Engine/Structures/AxiosPoint.cs @@ -5,7 +5,7 @@ using System.Text; namespace Axios.Engine.Structures { - class AxiosPoint + public class AxiosPoint { private float _x; private float _y; diff --git a/axios/Engine/Structures/AxiosRectangle.cs b/axios/Engine/Structures/AxiosRectangle.cs index 2a07fa3..c97fce8 100644 --- a/axios/Engine/Structures/AxiosRectangle.cs +++ b/axios/Engine/Structures/AxiosRectangle.cs @@ -5,7 +5,7 @@ using System.Text; namespace Axios.Engine.Structures { - class AxiosRectangle + public class AxiosRectangle { private AxiosPoint _point; @@ -73,6 +73,10 @@ namespace Axios.Engine.Structures _point = new AxiosPoint(X, Y); } + public override string ToString() + { + return String.Format("{{X:{0} Y:{1} Width:{2} Height:{3}}}", _point.X, _point.Y, Width, Height); + } } }