3D buttons (still needs a little work)

This commit is contained in:
Paul Chote
2010-03-17 20:37:58 +13:00
parent 79bcb3c739
commit a2b2ad0af5
8 changed files with 69 additions and 36 deletions

View File

@@ -7,6 +7,37 @@ namespace OpenRA.Widgets
class ButtonWidget : Widget
{
public readonly string Text = "";
public bool Depressed = false;
public int VisualHeight = 1;
public override bool HandleInput(MouseInput mi)
{
if (Game.chrome.selectedWidget == this)
Depressed = (GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) ? true : false;
// Relinquish focus
if (Game.chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up)
{
Game.chrome.selectedWidget = null;
Depressed = false;
}
// Are we able to handle this event?
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
return base.HandleInput(mi);
// Give button focus only while the mouse is down
// This is a bit of a hack: it will become cleaner soonish
// It will also steal events from any potential children
// We also want to play a click sound
if (mi.Event == MouseInputEvent.Down)
{
Game.chrome.selectedWidget = this;
Depressed = true;
return true;
}
return base.HandleInput(mi);
}
public override void Draw()
{
@@ -16,7 +47,8 @@ namespace OpenRA.Widgets
return;
}
string collection = "dialog2";
string collection = (Depressed) ? "dialog3" : "dialog2";
int2 stateOffset = (Depressed) ? new int2(VisualHeight,VisualHeight) : new int2(0,0);
Game.chrome.renderer.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);
string[] images = { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
@@ -45,7 +77,7 @@ namespace OpenRA.Widgets
Game.chrome.rgbaRenderer.DrawSprite(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y), "chrome");
Game.chrome.rgbaRenderer.Flush();
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(Game.chrome.renderer.BoldFont.Measure(Text).X / 2, Game.chrome.renderer.BoldFont.Measure(Text).Y/2), Color.White);
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(Game.chrome.renderer.BoldFont.Measure(Text).X / 2, Game.chrome.renderer.BoldFont.Measure(Text).Y/2) + stateOffset, Color.White);
Game.chrome.renderer.Device.DisableScissor();