New checkboxes (independent from old checkboxes) that support hover and disable.

This commit is contained in:
Paul Chote
2011-05-07 12:07:13 +12:00
parent c15d2f5cfe
commit 5647917fda
3 changed files with 48 additions and 24 deletions

View File

@@ -23,13 +23,13 @@ namespace OpenRA.Mods.Cnc.Widgets
public CncMenuButtonWidget()
: base()
{
OnMouseUp = mi => { OnClick(); return true; };
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
}
protected CncMenuButtonWidget(CncMenuButtonWidget widget)
: base(widget)
{
OnMouseUp = mi => { OnClick(); return true; };
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
}
public override int2 ChildOrigin { get { return RenderOrigin; } }
@@ -50,5 +50,37 @@ namespace OpenRA.Mods.Cnc.Widgets
font.Measure(text).Y / 2), IsDisabled() ? Color.Gray : Color.White);
}
}
public class CncCheckboxWidget : CncMenuButtonWidget
{
public CncCheckboxWidget()
: base() { }
protected CncCheckboxWidget(CncCheckboxWidget widget)
: base(widget) { }
public Func<bool> IsChecked = () => false;
public int baseLine = 1;
public override void DrawInner()
{
var state = IsDisabled() ? "button-disabled" :
Depressed ? "button-pressed" :
RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" :
"button";
var font = Game.Renderer.BoldFont;
var rect = RenderBounds;
WidgetUtils.DrawPanel(state, new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height)));
var textSize = font.Measure(Text);
font.DrawText(Text,
new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - baseLine + (Bounds.Height - textSize.Y)/2), Color.White);
if (IsChecked())
WidgetUtils.DrawRGBA(
ChromeProvider.GetImage("checkbox", "checked"),
new float2(rect.Left + 2, rect.Top + 2));
}
}
}