Apply consistent widget method names. Semantic change: Widgets that want to tick when !Visible must override TickOuter() instead of Tick().

This commit is contained in:
Paul Chote
2011-07-04 03:21:39 +12:00
parent 193999a040
commit 1114293035
41 changed files with 96 additions and 109 deletions

View File

@@ -37,7 +37,7 @@ namespace OpenRA
{
Sync.CheckSyncUnchanged( world, () =>
{
Widget.HandleKeyPress( input );
Widget.DoHandleKeyPress( input );
} );
}
@@ -45,7 +45,7 @@ namespace OpenRA
{
Sync.CheckSyncUnchanged( world, () =>
{
Widget.HandleInput( input );
Widget.DoHandleInput( input );
} );
}
}

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Widgets
public readonly string Background = "dialog";
public readonly bool ClickThrough = false;
public override void DrawInner()
public override void Draw()
{
WidgetUtils.DrawPanel(Background, RenderBounds);
}

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Widgets
return base.LoseFocus(mi);
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (e.KeyName != Key || e.Event != KeyInputEvent.Down)
return false;
@@ -107,7 +107,7 @@ namespace OpenRA.Widgets
public override int2 ChildOrigin { get { return RenderOrigin +
((Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0)); } }
public override void DrawInner()
public override void Draw()
{
var rb = RenderBounds;
var disabled = IsDisabled();

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Widgets
: base(widget) { }
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
public override void DrawInner()
public override void Draw()
{
var pos = RenderOrigin;
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Widgets
this.orderManager = orderManager;
}
public override void DrawInner()
public override void Draw()
{
if (composing)
{
@@ -51,7 +51,7 @@ namespace OpenRA.Widgets
return composing ? false : base.LoseFocus(mi);
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event == KeyInputEvent.Up) return false;
@@ -108,7 +108,7 @@ namespace OpenRA.Widgets
return false;
}
return base.HandleKeyPressInner(e);
return false;
}
}
}

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Widgets
HasPressedState = other.HasPressedState;
}
public override void DrawInner()
public override void Draw()
{
var disabled = IsDisabled();
var font = Game.Renderer.Fonts[Font];

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Widgets
return new ColorBlockWidget(this);
}
public override void DrawInner()
public override void Draw()
{
WidgetUtils.FillRectWithColor(RenderBounds, GetColor());
}

View File

@@ -30,9 +30,9 @@ namespace OpenRA.Widgets
{
}
public override void DrawInner()
public override void Draw()
{
base.DrawInner();
base.Draw();
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
var image = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow");
@@ -130,7 +130,6 @@ namespace OpenRA.Widgets
return true;
}
public override void DrawInner() { }
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new MaskWidget(this); }
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new ImageWidget(this); }
public override void DrawInner()
public override void Draw()
{
var name = GetImageName();
var collection = GetImageCollection();

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Widgets
GetContrastColor = other.GetContrastColor;
}
public override void DrawInner()
public override void Draw()
{
SpriteFont font = Game.Renderer.Fonts[Font];
var text = GetText();

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Widgets
Rectangle MapRect;
float PreviewScale = 0;
public override void DrawInner()
public override void Draw()
{
var map = Map();
if( map == null ) return;

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Widgets
{
public PerfGraphWidget() : base() { }
public override void DrawInner()
public override void Draw()
{
var rect = RenderBounds;
float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom);

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Widgets
Percentage = widget.Percentage;
}
public override void DrawInner()
public override void Draw()
{
var rb = RenderBounds;
WidgetUtils.DrawPanel("progressbar-bg", rb);

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Widgets
public Func<bool> IsSelected = () => false;
public override void DrawInner()
public override void Draw()
{
var state = IsSelected() ? "scrollitem-selected" :
RenderBounds.Contains(Viewport.LastMousePos) ? "scrollitem-hover" :

View File

@@ -56,8 +56,7 @@ namespace OpenRA.Widgets
base.AddChild(child);
}
public override void DrawInner() {}
public override void Draw()
public override void DrawOuter()
{
if (!IsVisible())
return;
@@ -101,7 +100,7 @@ namespace OpenRA.Widgets
Game.Renderer.EnableScissor(backgroundRect.X + 1, backgroundRect.Y + 1, backgroundRect.Width - 2, backgroundRect.Height - 2);
foreach (var child in Children)
child.Draw();
child.DrawOuter();
Game.Renderer.DisableScissor();
}

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Widgets
Text = Text.Replace("\r", "");
}
public override void DrawInner()
public override void Draw()
{
var bg = GetBackground();

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Widgets
Sprite sprite = null;
string cachedImage = null;
int cachedFrame= -1;
public override void DrawInner()
public override void Draw()
{
var image = GetImage();
var frame = GetFrame();

View File

@@ -174,7 +174,7 @@ namespace OpenRA.Widgets
}
}
public override void DrawInner()
public override void Draw()
{
if (!IsVisible())
return;

View File

@@ -104,7 +104,7 @@ namespace OpenRA.Widgets
return minIndex;
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (IsDisabled())
return false;
@@ -189,11 +189,9 @@ namespace OpenRA.Widgets
blinkCycle = 20;
showCursor ^= true;
}
base.Tick();
}
public override void DrawInner()
public override void Draw()
{
var apparentText = GetApparentText();
var font = Game.Renderer.Fonts[Font];

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Widgets
IsVisible = () => Game.Settings.Game.MatchTimer;
}
public override void DrawInner()
public override void Draw()
{
var s = WidgetUtils.FormatTime(Game.LocalTick);
var size = Game.Renderer.Fonts["Title"].Measure(s);

View File

@@ -32,7 +32,6 @@ namespace OpenRA.Widgets
public ViewportScrollControllerWidget() : base() { }
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {}
public override void DrawInner() {}
public override bool HandleMouseInput(MouseInput mi)
{
@@ -114,7 +113,7 @@ namespace OpenRA.Widgets
return base.LoseFocus(mi);
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
switch (e.KeyName)
{

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Widgets
overlaySprite.sheet.Texture.SetData(overlay);
}
public override void DrawInner()
public override void Draw()
{
if (video == null)
return;
@@ -104,7 +104,7 @@ namespace OpenRA.Widgets
Game.Renderer.RgbaSpriteRenderer.DrawSprite(overlaySprite, videoOrigin, videoSize);
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event == KeyInputEvent.Down)
{

View File

@@ -29,33 +29,6 @@ namespace OpenRA.Widgets
static Stack<Widget> WindowList = new Stack<Widget>();
public static Widget SelectedWidget;
public static bool HandleInput(MouseInput mi)
{
bool handled = false;
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
handled = true;
if (!handled && RootWidget.HandleMouseInputOuter(mi))
handled = true;
if (mi.Event == MouseInputEvent.Move)
{
Viewport.LastMousePos = mi.Location;
Viewport.TicksSinceLastMove = 0;
}
return handled;
}
public static bool HandleKeyPress(KeyInput e)
{
if (SelectedWidget != null)
return SelectedWidget.HandleKeyPressOuter(e);
if (RootWidget.HandleKeyPressOuter(e))
return true;
return false;
}
public static void CloseWindow()
{
if (WindowList.Count > 0)
@@ -85,12 +58,39 @@ namespace OpenRA.Widgets
public static void DoTick()
{
RootWidget.Tick();
RootWidget.TickOuter();
}
public static void DoDraw()
{
RootWidget.Draw();
RootWidget.DrawOuter();
}
public static bool DoHandleInput(MouseInput mi)
{
bool handled = false;
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
handled = true;
if (!handled && RootWidget.HandleMouseInputOuter(mi))
handled = true;
if (mi.Event == MouseInputEvent.Move)
{
Viewport.LastMousePos = mi.Location;
Viewport.TicksSinceLastMove = 0;
}
return handled;
}
public static bool DoHandleKeyPress(KeyInput e)
{
if (SelectedWidget != null)
return SelectedWidget.HandleKeyPressOuter(e);
if (RootWidget.HandleKeyPressOuter(e))
return true;
return false;
}
public static void ResetAll()
@@ -252,6 +252,7 @@ namespace OpenRA.Widgets
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
}
public virtual bool HandleMouseInput(MouseInput mi) { return false; }
public bool HandleMouseInputOuter(MouseInput mi)
{
// Are we able to handle this event?
@@ -266,8 +267,7 @@ namespace OpenRA.Widgets
return HandleMouseInput(mi);
}
public virtual bool HandleMouseInput(MouseInput mi) { return false; }
public virtual bool HandleKeyPressInner(KeyInput e) { return false; }
public virtual bool HandleKeyPress(KeyInput e) { return false; }
public virtual bool HandleKeyPressOuter(KeyInput e)
{
if (!IsVisible())
@@ -279,28 +279,31 @@ namespace OpenRA.Widgets
return true;
// Do any widgety behavior (enter text etc)
var handled = HandleKeyPressInner(e);
var handled = HandleKeyPress(e);
return handled;
}
public abstract void DrawInner();
public virtual void Draw()
public virtual void Draw() {}
public virtual void DrawOuter()
{
if (IsVisible())
{
DrawInner();
Draw();
foreach (var child in Children)
child.Draw();
child.DrawOuter();
}
}
public virtual void Tick()
public virtual void Tick() {}
public virtual void TickOuter()
{
if (IsVisible())
{
Tick();
foreach (var child in Children)
child.Tick();
child.TickOuter();
}
}
public virtual void AddChild(Widget child)
@@ -354,7 +357,6 @@ namespace OpenRA.Widgets
public ContainerWidget(ContainerWidget other)
: base(other) { }
public override void DrawInner() { }
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); }
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Widgets
this.worldRenderer = worldRenderer;
}
public override void DrawInner()
public override void Draw()
{
var selbox = SelectionBox;
if (selbox == null)
@@ -128,7 +128,7 @@ namespace OpenRA.Widgets
} );
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event == KeyInputEvent.Down)
{

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Cnc.Widgets
pm = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
}
public override void DrawInner()
public override void Draw()
{
float powerScaleBy = 100;
var maxPower = Math.Max(pm.PowerProvided, pm.PowerDrained);

View File

@@ -82,8 +82,6 @@ namespace OpenRA.Mods.Cnc.Widgets
if (CurrentQueue != null)
RefreshIcons();
base.Tick();
}
public override bool HandleMouseInput(MouseInput mi)
@@ -171,7 +169,7 @@ namespace OpenRA.Mods.Cnc.Widgets
eventBounds = Icons.Keys.Aggregate(Rectangle.Union);
}
public override void DrawInner()
public override void Draw()
{
if (CurrentQueue == null)
return;

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Cnc.Widgets
IsVisible = () => queueGroup != null && Groups[queueGroup].Tabs.Count > 0;
}
public override void DrawInner()
public override void Draw()
{
var rb = RenderBounds;
leftButtonRect = new Rectangle(rb.X, rb.Y, ArrowWidth, rb.Height);
@@ -180,7 +180,6 @@ namespace OpenRA.Mods.Cnc.Widgets
{
if (leftPressed) Scroll(1);
if (rightPressed) Scroll(-1);
base.Tick();
}
public override bool LoseFocus(MouseInput mi)
@@ -230,7 +229,7 @@ namespace OpenRA.Mods.Cnc.Widgets
return (leftPressed || rightPressed);
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event != KeyInputEvent.Down) return false;
if (e.KeyName == "tab")

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.Widgets
pr = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
}
public override void DrawInner()
public override void Draw()
{
float scaleBy = 100;
var max = Math.Max(pr.OreCapacity, pr.Ore);

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Cnc.Widgets
eventBounds = (Icons.Count == 0) ? Rectangle.Empty : Icons.Keys.Aggregate(Rectangle.Union);
}
public override void DrawInner()
public override void Draw()
{
var overlayFont = Game.Renderer.Fonts["TinyBold"];
var holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
@@ -101,7 +101,6 @@ namespace OpenRA.Mods.Cnc.Widgets
public override void Tick ()
{
base.Tick();
RefreshIcons();
}

View File

@@ -101,8 +101,6 @@ namespace OpenRA.Mods.RA.Widgets
CurrentQueue = VisibleQueues.FirstOrDefault();
TickPaletteAnimation(world);
base.Tick();
}
void TickPaletteAnimation(World world)
@@ -145,7 +143,7 @@ namespace OpenRA.Mods.RA.Widgets
CurrentQueue = queue;
}
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event == KeyInputEvent.Up) return false;
if (e.KeyName == "tab")
@@ -175,7 +173,7 @@ namespace OpenRA.Mods.RA.Widgets
return true;
}
public override void DrawInner()
public override void Draw()
{
if (!IsVisible()) return;
// todo: fix

View File

@@ -21,7 +21,5 @@ namespace OpenRA.Mods.RA.Widgets
public string InstallMode = "";
public string ResolvedPackagePath { get { return PackagePath.Replace("^", Platform.SupportDir); } }
public override void DrawInner() {}
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Widgets
this.world = world;
}
public override void DrawInner()
public override void Draw()
{
if( world.LocalPlayer == null ) return;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Widgets
GetLongDesc = () => LongDesc;
}
public override void DrawInner()
public override void Draw()
{
var image = ChromeProvider.GetImage(Image + "-button", GetImage());
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Widgets
this.world = world;
}
public override void DrawInner()
public override void Draw()
{
if( world.LocalPlayer == null ) return;

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.RA.Widgets
get { return new Rectangle((int)mapRect.X, (int)mapRect.Y, (int)mapRect.Width, (int)mapRect.Height);}
}
public override void DrawInner()
public override void Draw()
{
if( world == null || world.LocalPlayer == null ) return;

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA.Widgets
get { return new Rectangle((int)mapRect.X, (int)mapRect.Y, (int)mapRect.Width, (int)mapRect.Height);}
}
public override void DrawInner()
public override void Draw()
{
if( world == null || world.LocalPlayer == null ) return;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA
this.world = widget.world;
}
public override void DrawInner()
public override void Draw()
{
var state = Depressed ? "pressed" :
RenderBounds.Contains(Viewport.LastMousePos) ? "hover" : "normal";

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Widgets
return false;
}
public override void DrawInner()
public override void Draw()
{
buttons.Clear();

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Widgets
b.Stances[a] == Stance.Ally;
}
public override void DrawInner()
public override void Draw()
{
if (!Initialised)
Init();

View File

@@ -35,11 +35,9 @@ namespace OpenRA.Mods.RA.Widgets
OrderManager = orderManager;
}
public override void DrawInner() { }
public override string GetCursor(int2 pos) { return null; }
public override bool HandleKeyPressInner(KeyInput e)
public override bool HandleKeyPress(KeyInput e)
{
if (World == null) return false;
if (World.LocalPlayer == null) return false;

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Widgets
this.world = world;
}
public override void DrawInner()
public override void Draw()
{
if (Viewport.TicksSinceLastMove < TooltipDelay || world == null)
return;