Add extension methods to Rectangle/RectangleF, remove a pile of ToPoint()'s.
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -95,5 +96,15 @@ namespace OpenRA
|
|||||||
else
|
else
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool Contains(this Rectangle r, int2 p)
|
||||||
|
{
|
||||||
|
return r.Contains(p.ToPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Contains(this RectangleF r, int2 p)
|
||||||
|
{
|
||||||
|
return r.Contains(p.ToPointF());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
case MouseInputEvent.Down:
|
case MouseInputEvent.Down:
|
||||||
{
|
{
|
||||||
if (thumbRect.Contains(mi.Location.ToPoint()))
|
if (thumbRect.Contains(mi.Location))
|
||||||
{
|
{
|
||||||
isMoving = true;
|
isMoving = true;
|
||||||
lastMouseLocation = mi.Location;
|
lastMouseLocation = mi.Location;
|
||||||
@@ -103,7 +103,7 @@ namespace OpenRA.Widgets
|
|||||||
: Math.Floor((pos - delta) * (Ticks - 1)));
|
: Math.Floor((pos - delta) * (Ticks - 1)));
|
||||||
OnChange(targetTick / (Ticks - 1));
|
OnChange(targetTick / (Ticks - 1));
|
||||||
|
|
||||||
if (thumbRect.Contains(mi.Location.ToPoint()))
|
if (thumbRect.Contains(mi.Location))
|
||||||
{
|
{
|
||||||
isMoving = true;
|
isMoving = true;
|
||||||
lastMouseLocation = mi.Location;
|
lastMouseLocation = mi.Location;
|
||||||
@@ -119,7 +119,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
OnChange(newOffset);
|
OnChange(newOffset);
|
||||||
|
|
||||||
if (thumbRect.Contains(mi.Location.ToPoint()))
|
if (thumbRect.Contains(mi.Location))
|
||||||
{
|
{
|
||||||
isMoving = true;
|
isMoving = true;
|
||||||
lastMouseLocation = mi.Location;
|
lastMouseLocation = mi.Location;
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ namespace OpenRA.Widgets
|
|||||||
public string GetCursorOuter(int2 pos)
|
public string GetCursorOuter(int2 pos)
|
||||||
{
|
{
|
||||||
// Is the cursor on top of us?
|
// Is the cursor on top of us?
|
||||||
if (!(IsVisible() && GetEventBounds().Contains(pos.ToPoint())))
|
if (!(IsVisible() && GetEventBounds().Contains(pos)))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Do any of our children specify a cursor?
|
// Do any of our children specify a cursor?
|
||||||
@@ -191,7 +191,7 @@ namespace OpenRA.Widgets
|
|||||||
return cc;
|
return cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EventBounds.Contains(pos.ToPoint()) ? GetCursor(pos) : null;
|
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HandleInput(MouseInput mi)
|
public static bool HandleInput(MouseInput mi)
|
||||||
|
|||||||
@@ -162,10 +162,10 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
if (mi.Event != MouseInputEvent.Down)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var action = tabs.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
var action = tabs.Where(a => a.First.Contains(mi.Location))
|
||||||
.Select(a => a.Second).FirstOrDefault();
|
.Select(a => a.Second).FirstOrDefault();
|
||||||
if (action == null && paletteOpen)
|
if (action == null && paletteOpen)
|
||||||
action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
action = buttons.Where(a => a.First.Contains(mi.Location))
|
||||||
.Select(a => a.Second).FirstOrDefault();
|
.Select(a => a.Second).FirstOrDefault();
|
||||||
|
|
||||||
if (action == null)
|
if (action == null)
|
||||||
@@ -223,7 +223,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
|
|
||||||
var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);
|
var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);
|
||||||
|
|
||||||
if (rect.Contains(Viewport.LastMousePos.ToPoint()))
|
if (rect.Contains(Viewport.LastMousePos))
|
||||||
tooltipItem = item.Name;
|
tooltipItem = item.Name;
|
||||||
|
|
||||||
var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2);
|
var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2);
|
||||||
@@ -412,7 +412,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight);
|
var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight);
|
||||||
tabs.Add(Pair.New(rect, HandleTabClick(queue, world)));
|
tabs.Add(Pair.New(rect, HandleTabClick(queue, world)));
|
||||||
|
|
||||||
if (rect.Contains(Viewport.LastMousePos.ToPoint()))
|
if (rect.Contains(Viewport.LastMousePos))
|
||||||
{
|
{
|
||||||
var text = queue.Info.Type;
|
var text = queue.Info.Type;
|
||||||
var sz = Game.Renderer.BoldFont.Measure(text);
|
var sz = Game.Renderer.BoldFont.Measure(text);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
var image = ChromeProvider.GetImage(Image + "-button", GetImage());
|
var image = ChromeProvider.GetImage(Image + "-button", GetImage());
|
||||||
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);
|
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);
|
||||||
|
|
||||||
if (rect.Contains(Viewport.LastMousePos.ToPoint()))
|
if (rect.Contains(Viewport.LastMousePos))
|
||||||
{
|
{
|
||||||
rect = rect.InflateBy(3, 3, 3, 3);
|
rect = rect.InflateBy(3, 3, 3, 3);
|
||||||
var pos = new int2(rect.Left, rect.Top);
|
var pos = new int2(rect.Left, rect.Top);
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
{
|
{
|
||||||
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
||||||
|
|
||||||
if (!mapRect.Contains(mi.Location.ToPointF()))
|
if (!mapRect.Contains(mi.Location))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var loc = MinimapPixelToCell(mi.Location);
|
var loc = MinimapPixelToCell(mi.Location);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Down)
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
var action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
var action = buttons.Where(a => a.First.Contains(mi.Location))
|
||||||
.Select(a => a.Second).FirstOrDefault();
|
.Select(a => a.Second).FirstOrDefault();
|
||||||
if (action == null)
|
if (action == null)
|
||||||
return false;
|
return false;
|
||||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
var drawPos = new float2(rectBounds.X + 5, y);
|
var drawPos = new float2(rectBounds.X + 5, y);
|
||||||
var rect = new Rectangle(rectBounds.X + 5, y, 64, 48);
|
var rect = new Rectangle(rectBounds.X + 5, y, 64, 48);
|
||||||
|
|
||||||
if (rect.Contains(Viewport.LastMousePos.ToPoint()))
|
if (rect.Contains(Viewport.LastMousePos))
|
||||||
{
|
{
|
||||||
var pos = drawPos.ToInt2();
|
var pos = drawPos.ToInt2();
|
||||||
var tl = new int2(pos.X-3,pos.Y-3);
|
var tl = new int2(pos.X-3,pos.Y-3);
|
||||||
|
|||||||
Reference in New Issue
Block a user