get rid of premature optimization (bounds caching all the way up the tree); hide that dialog; it actually works now

This commit is contained in:
Chris Forbes
2010-03-16 20:27:25 +13:00
parent 22be9597ca
commit d4993778e1
3 changed files with 15 additions and 24 deletions

View File

@@ -1066,11 +1066,8 @@ namespace OpenRA
public bool HitTest(int2 mousePos)
{
if (Game.orderManager.Connection.ConnectionState == ConnectionState.PreConnecting)
if (rootWidget.EventBounds.Contains(mousePos.X, mousePos.Y))
return true;
return buttons.Any(a => a.First.Contains(mousePos.ToPoint()));
return rootWidget.GetEventBounds().Contains(mousePos.X, mousePos.Y)
|| buttons.Any(a => a.First.Contains(mousePos.ToPoint()));
}
void DrawRightAligned(string text, int2 pos, Color c)

View File

@@ -36,7 +36,8 @@ namespace OpenRA.Widgets.Delegates
}
if (w.Id == "CREATESERVER_BUTTON_START")
{
{
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
Game.CreateServer();
return true;
}
@@ -75,7 +76,6 @@ namespace OpenRA.Widgets.Delegates
b.GetType().GetField("Text").SetValue( b, "{0} ({1})".F(game.Name, game.Address));
b.GetType().GetField("Delegate").SetValue( b, "ServerBrowserDelegate");
b.EventBounds = b.Bounds;
bg.AddChild(b);
GameButtons.Add(b);

View File

@@ -2,7 +2,8 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Widgets.Delegates;
using OpenRA.Widgets.Delegates;
using System.Linq;
namespace OpenRA.Widgets
{
@@ -23,7 +24,6 @@ namespace OpenRA.Widgets
// Calculated internally
public Rectangle Bounds;
public Rectangle EventBounds;
public Widget Parent = null;
public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); }
@@ -49,13 +49,16 @@ namespace OpenRA.Widgets
width,
height);
// Calculate the region that we accept mouse events in
EventBounds = Bounds;
foreach (var child in Children)
{
child.Initialize();
EventBounds = Rectangle.Union(EventBounds, child.EventBounds);
}
}
public Rectangle GetEventBounds()
{
return Children
.Where(c => c.Visible)
.Select(c => c.GetEventBounds())
.Aggregate(Bounds, Rectangle.Union);
}
static IWidgetDelegate BindHandler(string name)
@@ -69,21 +72,12 @@ namespace OpenRA.Widgets
}
throw new InvalidOperationException("Cannot locate widget delegate: {0}".F(name));
}
public virtual void UpdateEventBounds()
{
EventBounds = Bounds;
foreach (var child in Children)
EventBounds = Rectangle.Union(EventBounds, child.EventBounds);
Parent.UpdateEventBounds();
}
public virtual bool HandleInput(MouseInput mi)
{
// Are we able to handle this event?
if (!Visible || !EventBounds.Contains(mi.Location.X,mi.Location.Y))
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
return false;
// Can any of our children handle this?