split Widget static bits into Ui static class

This commit is contained in:
Chris Forbes
2011-12-13 23:38:59 +13:00
parent 83055f0a17
commit ed429a3b30
60 changed files with 173 additions and 168 deletions

View File

@@ -95,14 +95,14 @@ namespace OpenRA
// Hacky workaround for orderManager visibility
public static Widget OpenWindow(World world, string widget)
{
return Widget.OpenWindow(widget, new WidgetArgs() {{ "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer }});
return Ui.OpenWindow(widget, new WidgetArgs() {{ "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer }});
}
// Who came up with the great idea of making these things
// impossible for the things that want them to access them directly?
public static Widget OpenWindow(string widget, WidgetArgs args)
{
return Widget.OpenWindow(widget, new WidgetArgs(args)
return Ui.OpenWindow(widget, new WidgetArgs(args)
{
{ "world", worldRenderer.world },
{ "orderManager", orderManager },
@@ -160,7 +160,7 @@ namespace OpenRA
using( new PerfSample( "tick_time" ) )
{
orderManager.LastTickTime += Settings.Game.Timestep;
Widget.DoTick();
Ui.DoTick();
var world = orderManager.world;
if (orderManager.GameStarted)
++Viewport.TicksSinceLastMove;
@@ -215,7 +215,7 @@ namespace OpenRA
worldRenderer = new WorldRenderer(orderManager.world);
if (orderManager.GameStarted) return;
Widget.SelectedWidget = null;
Ui.SelectedWidget = null;
orderManager.LocalFrameNumber = 0;
orderManager.LastTickTime = Environment.TickCount;
@@ -270,7 +270,7 @@ namespace OpenRA
AddChatLine = (a,b,c) => {};
ConnectionStateChanged = om => {};
BeforeGameStart = () => {};
Widget.ResetAll();
Ui.ResetAll();
worldRenderer = null;
if (server != null)

View File

@@ -126,15 +126,15 @@ namespace OpenRA.Graphics
using( new PerfSample("render_widgets") )
{
Widget.DoDraw();
var cursorName = Widget.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default";
Ui.DoDraw();
var cursorName = Ui.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default";
var cursorSequence = CursorProvider.GetCursorSequence(cursorName);
var cursorSprite = cursorSequence.GetSprite((int)cursorFrame);
renderer.SpriteRenderer.DrawSprite(cursorSprite,
Viewport.LastMousePos - cursorSequence.Hotspot,
Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette),
cursorSprite.size);
Viewport.LastMousePos - cursorSequence.Hotspot,
Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette),
cursorSprite.size);
}
using( new PerfSample("render_flip") )
@@ -194,7 +194,7 @@ namespace OpenRA.Graphics
{
if (cachedScroll != scrollPosition)
{
int2 boundary = new int2(1,1); // Add a curtain of cells around the viewport to account for rounding errors
var boundary = new int2(1,1); // Add a curtain of cells around the viewport to account for rounding errors
var tl = ViewToWorld(int2.Zero).ToInt2() - boundary;
var br = ViewToWorld(new int2(Width, Height)).ToInt2() + boundary;

View File

@@ -35,18 +35,12 @@ namespace OpenRA
public void OnKeyInput( KeyInput input )
{
Sync.CheckSyncUnchanged( world, () =>
{
Widget.DoHandleKeyPress( input );
} );
Sync.CheckSyncUnchanged(world, () => Ui.DoHandleKeyPress(input));
}
public void OnMouseInput( MouseInput input )
{
Sync.CheckSyncUnchanged( world, () =>
{
Widget.DoHandleInput( input );
} );
Sync.CheckSyncUnchanged(world, () => Ui.DoHandleInput(input));
}
}
}

View File

@@ -128,7 +128,7 @@ namespace OpenRA.Widgets
var s = font.Measure(text);
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
DrawBackground(rb, disabled, Depressed, Widget.MouseOverWidget == this);
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this);
font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
disabled ? Color.Gray : Color.White);
}

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Widgets
var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
var state = disabled ? "checkbox-disabled" :
Depressed && HasPressedState ? "checkbox-pressed" :
Widget.MouseOverWidget == this ? "checkbox-hover" :
Ui.MouseOverWidget == this ? "checkbox-hover" :
"checkbox";
WidgetUtils.DrawPanel(state, check);

View File

@@ -57,8 +57,8 @@ namespace OpenRA.Widgets
if (panel == null)
return;
Widget.RootWidget.RemoveChild(fullscreenMask);
Widget.RootWidget.RemoveChild(panel);
Ui.RootWidget.RemoveChild(fullscreenMask);
Ui.RootWidget.RemoveChild(panel);
panel = fullscreenMask = null;
}
@@ -72,17 +72,17 @@ namespace OpenRA.Widgets
fullscreenMask = new MaskWidget();
fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height);
fullscreenMask.OnMouseDown = mi => RemovePanel();
Widget.RootWidget.AddChild(fullscreenMask);
Ui.RootWidget.AddChild(fullscreenMask);
var oldBounds = panel.Bounds;
panel.Bounds = new Rectangle(RenderOrigin.X, RenderOrigin.Y + Bounds.Height, oldBounds.Width, oldBounds.Height);
Widget.RootWidget.AddChild(panel);
Ui.RootWidget.AddChild(panel);
}
public void ShowDropDown<T>(string panelTemplate, int height, IEnumerable<T> options, Func<T, ScrollItemWidget, ScrollItemWidget> setupItem)
{
var substitutions = new Dictionary<string,int>() {{ "DROPDOWN_WIDTH", Bounds.Width }};
var panel = (ScrollPanelWidget)Widget.LoadWidget(panelTemplate, null, new WidgetArgs()
var panel = (ScrollPanelWidget)Ui.LoadWidget(panelTemplate, null, new WidgetArgs()
{{ "substitutions", substitutions }});
var itemTemplate = panel.GetWidget<ScrollItemWidget>("TEMPLATE");
@@ -91,7 +91,7 @@ namespace OpenRA.Widgets
{
var o = option;
ScrollItemWidget item = setupItem(o, itemTemplate);
var item = setupItem(o, itemTemplate);
var onClick = item.OnClick;
item.OnClick = () => { onClick(); RemovePanel(); };

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Widgets
public override void Draw()
{
var state = IsSelected() ? "scrollitem-selected" :
Widget.MouseOverWidget == this ? "scrollitem-hover" :
Ui.MouseOverWidget == this ? "scrollitem-hover" :
null;
if (state != null)

View File

@@ -70,13 +70,13 @@ namespace OpenRA.Widgets
scrollbarRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, ScrollbarHeight + 2);
thumbRect = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);
var upHover = Widget.MouseOverWidget == this && upButtonRect.Contains(Viewport.LastMousePos);
var upHover = Ui.MouseOverWidget == this && upButtonRect.Contains(Viewport.LastMousePos);
var upDisabled = thumbHeight == 0 || ListOffset >= 0;
var downHover = Widget.MouseOverWidget == this && downButtonRect.Contains(Viewport.LastMousePos);
var downHover = Ui.MouseOverWidget == this && downButtonRect.Contains(Viewport.LastMousePos);
var downDisabled = thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight;
var thumbHover = Widget.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos);
var thumbHover = Ui.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos);
WidgetUtils.DrawPanel(Background, backgroundRect);
WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect);
ButtonWidget.DrawBackground("button", upButtonRect, upDisabled, UpPressed, upHover);

View File

@@ -117,7 +117,7 @@ namespace OpenRA.Widgets
WidgetUtils.DrawPanel("slider-track", trackRect);
// Thumb
var thumbHover = Widget.MouseOverWidget == this && tr.Contains(Viewport.LastMousePos);
var thumbHover = Ui.MouseOverWidget == this && tr.Contains(Viewport.LastMousePos);
ButtonWidget.DrawBackground("scrollthumb", tr, IsDisabled(), isMoving, thumbHover);
}
}

View File

@@ -203,7 +203,7 @@ namespace OpenRA.Widgets
var disabled = IsDisabled();
var state = disabled ? "textfield-disabled" :
Focused ? "textfield-focused" :
Widget.MouseOverWidget == this ? "textfield-hover" :
Ui.MouseOverWidget == this ? "textfield-hover" :
"textfield";
WidgetUtils.DrawPanel(state,

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Widgets
public static string GetScrollCursor(Widget w, ScrollDirection edge, int2 pos)
{
if (!Game.Settings.Game.ViewportEdgeScroll || Widget.MouseOverWidget != w)
if (!Game.Settings.Game.ViewportEdgeScroll || Ui.MouseOverWidget != w)
return null;
var blockedDirections = Game.viewport.GetBlockedDirections();
@@ -81,10 +81,10 @@ namespace OpenRA.Widgets
{
switch (e.KeyName)
{
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, (e.Event == KeyInputEvent.Down)); return true;
case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, (e.Event == KeyInputEvent.Down)); return true;
case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, (e.Event == KeyInputEvent.Down)); return true;
case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, (e.Event == KeyInputEvent.Down)); return true;
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, e.Event == KeyInputEvent.Down); return true;
case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, e.Event == KeyInputEvent.Down); return true;
case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, e.Event == KeyInputEvent.Down); return true;
case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, e.Event == KeyInputEvent.Down); return true;
}
return false;
}
@@ -109,7 +109,6 @@ namespace OpenRA.Widgets
{
var scroll = new float2(0, 0);
// Modified to use the ViewportEdgeScrollStep setting - Gecko
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
scroll += new float2(0, -1);
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))

View File

@@ -17,7 +17,7 @@ using OpenRA.Graphics;
namespace OpenRA.Widgets
{
public abstract class Widget
public static class Ui
{
public static Widget RootWidget = new ContainerWidget();
@@ -108,10 +108,13 @@ namespace OpenRA.Widgets
{
RootWidget.RemoveChildren();
while (Widget.WindowList.Count > 0)
Widget.CloseWindow();
while (WindowList.Count > 0)
CloseWindow();
}
}
public abstract class Widget
{
// Info defined in YAML
public string Id = null;
public string X = "0";
@@ -221,6 +224,7 @@ namespace OpenRA.Widgets
}
public virtual Rectangle EventBounds { get { return RenderBounds; } }
public virtual Rectangle GetEventBounds()
{
return Children
@@ -229,16 +233,17 @@ namespace OpenRA.Widgets
.Aggregate(EventBounds, Rectangle.Union);
}
public bool Focused { get { return SelectedWidget == this; } }
public bool Focused { get { return Ui.SelectedWidget == this; } }
public virtual bool TakeFocus(MouseInput mi)
{
if (Focused)
return true;
if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
if (Ui.SelectedWidget != null && !Ui.SelectedWidget.LoseFocus(mi))
return false;
SelectedWidget = this;
Ui.SelectedWidget = this;
return true;
}
@@ -251,8 +256,8 @@ namespace OpenRA.Widgets
public virtual bool LoseFocus()
{
if (SelectedWidget == this)
SelectedWidget = null;
if (Ui.SelectedWidget == this)
Ui.SelectedWidget = null;
return true;
}
@@ -285,17 +290,17 @@ namespace OpenRA.Widgets
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location))))
return false;
var oldMouseOver = MouseOverWidget;
var oldMouseOver = Ui.MouseOverWidget;
// Send the event to the deepest children first and bubble up if unhandled
foreach (var child in Children.OfType<Widget>().Reverse())
if (child.HandleMouseInputOuter(mi))
return true;
if (IgnoreChildMouseOver)
MouseOverWidget = oldMouseOver;
Ui.MouseOverWidget = oldMouseOver;
if (mi.Event == MouseInputEvent.Move && MouseOverWidget == null && !IgnoreMouseOver)
MouseOverWidget = this;
if (mi.Event == MouseInputEvent.Move && Ui.MouseOverWidget == null && !IgnoreMouseOver)
Ui.MouseOverWidget = this;
return HandleMouseInput(mi);
}