integrate scrollbar and checkbox art. fixes #215.

This commit is contained in:
Chris Forbes
2010-07-28 18:16:47 +12:00
parent 72d6a211af
commit 5ca7218eb6
12 changed files with 81 additions and 66 deletions

View File

@@ -10,6 +10,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using OpenRA.Graphics;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
@@ -18,11 +19,11 @@ namespace OpenRA.Widgets
public string Text = ""; public string Text = "";
public int baseLine = 1; public int baseLine = 1;
public bool Bold = false; public bool Bold = false;
public Func<bool> Checked = () => {return false;}; public Func<bool> Checked = () => false;
public override void DrawInner(World world) public override void DrawInner(World world)
{ {
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; var font = Bold ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var pos = RenderOrigin; var pos = RenderOrigin;
var rect = RenderBounds; var rect = RenderBounds;
var check = new Rectangle(rect.Location, var check = new Rectangle(rect.Location,
@@ -31,14 +32,13 @@ namespace OpenRA.Widgets
var textSize = font.Measure(Text); var textSize = font.Measure(Text);
font.DrawText(Text, font.DrawText(Text,
new float2(rect.Left + rect.Height * 1.5f, pos.Y - baseLine + (Bounds.Height - textSize.Y)/2), Color.White); new float2(rect.Left + rect.Height * 1.5f,
pos.Y - baseLine + (Bounds.Height - textSize.Y)/2), Color.White);
if (Checked()) if (Checked())
{ WidgetUtils.DrawRGBA(
Game.Renderer.RgbaSpriteRenderer.Flush(); ChromeProvider.GetImage("checkbox", "checked"),
WidgetUtils.FillRectWithColor(check.InflateBy(-4,-5,-4,-5),Color.White); new float2(rect.Left + 2, rect.Top + 2));
Game.Renderer.LineRenderer.Flush();
}
} }
public override bool HandleInputInner(MouseInput mi) { return true; } public override bool HandleInputInner(MouseInput mi) { return true; }

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Widgets
public ImageWidget() public ImageWidget()
: base() : base()
{ {
GetImageName = () => { return ImageName; }; GetImageName = () => ImageName;
GetImageCollection = () => { return ImageCollection; }; GetImageCollection = () => ImageCollection;
} }
protected ImageWidget(ImageWidget other) protected ImageWidget(ImageWidget other)

View File

@@ -27,8 +27,8 @@ namespace OpenRA.Widgets
public LabelWidget() public LabelWidget()
: base() : base()
{ {
GetText = () => { return Text; }; GetText = () => Text;
GetBackground = () => { return Background; }; GetBackground = () => Background;
} }
protected LabelWidget(LabelWidget other) protected LabelWidget(LabelWidget other)

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Drawing; using System.Drawing;
using OpenRA.Graphics;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
@@ -63,6 +64,15 @@ namespace OpenRA.Widgets
WidgetUtils.DrawPanel(downButtonBg, downButtonRect); WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect); WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect);
var upOffset = UpPressed ? 4 : 3;
var downOffset = DownPressed ? 4 : 3;
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "up_arrow"),
new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset));
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "down_arrow"),
new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset));
Game.Renderer.RgbaSpriteRenderer.Flush();
Game.Renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight); Game.Renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
foreach (var child in Children) foreach (var child in Children)

View File

@@ -9,12 +9,6 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Orders;
using OpenRA.Traits;
using OpenRA.FileFormats;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
@@ -35,7 +29,7 @@ namespace OpenRA.Widgets
ScrollDirection Keyboard; ScrollDirection Keyboard;
ScrollDirection Edge; ScrollDirection Edge;
public ViewportScrollControllerWidget() : base() {} public ViewportScrollControllerWidget() : base() { }
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {} protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {}
public override void DrawInner( World world ) {} public override void DrawInner( World world ) {}

View File

@@ -9,12 +9,11 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Orders; using OpenRA.Orders;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.FileFormats;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -13,11 +13,8 @@
<image name="bg" x="306" y="31" width="192" height="192" /> <image name="bg" x="306" y="31" width="192" height="192" />
<image name="power-indicator" x="187" y="4" width="4" height="7" /> <image name="power-indicator" x="187" y="4" width="4" height="7" />
</collection> </collection>
<collection name="power-gdi" src="chrome-gdi.png"> <collection name="power-gdi" src="chrome-gdi.png">
<image name="power-indicator" x="187" y="4" width="4" height="7" /> <image name="power-indicator" x="187" y="4" width="4" height="7" />
</collection> </collection>
<collection name="palette-gdi" src="chrome-gdi.png"> <collection name="palette-gdi" src="chrome-gdi.png">
<image name="top" x="297" y="288" width="201" height="9" /> <image name="top" x="297" y="288" width="201" height="9" />
@@ -59,11 +56,8 @@
<image name="bg" x="306" y="31" width="192" height="192" /> <image name="bg" x="306" y="31" width="192" height="192" />
<image name="power-indicator" x="187" y="4" width="4" height="7" /> <image name="power-indicator" x="187" y="4" width="4" height="7" />
</collection> </collection>
<collection name="power-nod" src="chrome-nod.png"> <collection name="power-nod" src="chrome-nod.png">
<image name="power-indicator" x="187" y="4" width="4" height="7" /> <image name="power-indicator" x="187" y="4" width="4" height="7" />
</collection> </collection>
<collection name="palette-nod" src="chrome-nod.png"> <collection name="palette-nod" src="chrome-nod.png">
<image name="top" x="297" y="288" width="201" height="9" /> <image name="top" x="297" y="288" width="201" height="9" />
@@ -155,7 +149,7 @@
<image name="corner-bl" x="0" y="82" width="1" height="1" /> <image name="corner-bl" x="0" y="82" width="1" height="1" />
<image name="corner-br" x="82" y="82" width="1" height="1" /> <image name="corner-br" x="82" y="82" width="1" height="1" />
</collection> </collection>
<collection name="dialog3" src="dialog3.png"> <collection name="dialog3" src="dialog3.png">
<image name="background" x="1" y="1" width="126" height="126" /> <image name="background" x="1" y="1" width="126" height="126" />
<image name="border-r" x="127" y="1" width="1" height="126" /> <image name="border-r" x="127" y="1" width="1" height="126" />
<image name="border-l" x="0" y="1" width="1" height="126" /> <image name="border-l" x="0" y="1" width="1" height="126" />
@@ -201,11 +195,18 @@
<image name="nod" x="0" y="84" width="30" height="15" /> <image name="nod" x="0" y="84" width="30" height="15" />
<image name="random" x="60" y="84" width="30" height="15" /> <image name="random" x="60" y="84" width="30" height="15" />
</collection> </collection>
<collection name="music" src="musicplayer.png"> <collection name="music" src="musicplayer.png">
<image name="pause" x="0" y="0" width="25" height="25" /> <image name="pause" x="0" y="0" width="25" height="25" />
<image name="stop" x="28" y="0" width="25" height="25" /> <image name="stop" x="28" y="0" width="25" height="25" />
<image name="play" x="56" y="0" width="25" height="25" /> <image name="play" x="56" y="0" width="25" height="25" />
<image name="next" x="84" y="0" width="25" height="25" /> <image name="next" x="84" y="0" width="25" height="25" />
<image name="prev" x="112" y="0" width="25" height="25" /> <image name="prev" x="112" y="0" width="25" height="25" />
</collection> </collection>
<collection name="scrollbar" src="buttons.png">
<image name="down_arrow" x="16" y="112" width="16" height="16" />
<image name="up_arrow" x="32" y="112" width="16" height="16" />
</collection>
<collection name="checkbox" src="buttons.png">
<image name="checked" x="0" y="112" width="16" height="16" />
</collection>
</chrome> </chrome>

View File

@@ -96,8 +96,9 @@ Container@ROOT:
Checkbox@STATUS: Checkbox@STATUS:
Id:STATUS Id:STATUS
X:455 X:455
Width:25 Y:2
Height:25 Width:20
Height:20
Container@TEMPLATE_REMOTE: Container@TEMPLATE_REMOTE:
Id:TEMPLATE_REMOTE Id:TEMPLATE_REMOTE
X:0 X:0
@@ -151,8 +152,9 @@ Container@ROOT:
Checkbox@STATUS: Checkbox@STATUS:
Id:STATUS Id:STATUS
X:455 X:455
Width:25 Y:2
Height:25 Width:20
Height:20
Container@LABEL_CONTAINER: Container@LABEL_CONTAINER:
X:30 X:30
Y:45 Y:45

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -12,9 +12,9 @@
<image name="bottom" x="297" y="223" width="210" height="30" /> <image name="bottom" x="297" y="223" width="210" height="30" />
<image name="bg" x="306" y="31" width="192" height="192" /> <image name="bg" x="306" y="31" width="192" height="192" />
</collection> </collection>
<collection name="power-allies" src="chrome-allies.png"> <collection name="power-allies" src="chrome-allies.png">
<image name="power-indicator" x="187" y="4" width="4" height="7" /> <image name="power-indicator" x="187" y="4" width="4" height="7" />
</collection> </collection>
<collection name="palette-allies" src="chrome-allies.png"> <collection name="palette-allies" src="chrome-allies.png">
<image name="top" x="297" y="288" width="201" height="9" /> <image name="top" x="297" y="288" width="201" height="9" />
<image name="dock-top" x="498" y="274" width="14" height="23" /> <image name="dock-top" x="498" y="274" width="14" height="23" />
@@ -55,7 +55,7 @@
<image name="bg" x="306" y="31" width="192" height="192" /> <image name="bg" x="306" y="31" width="192" height="192" />
<image name="power-indicator" x="187" y="4" width="4" height="7" /> <image name="power-indicator" x="187" y="4" width="4" height="7" />
</collection> </collection>
<collection name="power-soviet" src="chrome-soviet.png"> <collection name="power-soviet" src="chrome-soviet.png">
<image name="power-indicator" x="187" y="4" width="4" height="7" /> <image name="power-indicator" x="187" y="4" width="4" height="7" />
</collection> </collection>
<collection name="palette-soviet" src="chrome-soviet.png"> <collection name="palette-soviet" src="chrome-soviet.png">
@@ -189,16 +189,23 @@
<image name="pressed" x="34" y="56" width="34" height="28" /> <image name="pressed" x="34" y="56" width="34" height="28" />
<image name="disabled" x="68" y="56" width="34" height="28" /> <image name="disabled" x="68" y="56" width="34" height="28" />
</collection> </collection>
<collection name="flags" src="buttons.png"> <collection name="flags" src="buttons.png">
<image name="allies" x="30" y="84" width="30" height="15" /> <image name="allies" x="30" y="84" width="30" height="15" />
<image name="soviet" x="0" y="84" width="30" height="15" /> <image name="soviet" x="0" y="84" width="30" height="15" />
<image name="random" x="60" y="84" width="30" height="15" /> <image name="random" x="60" y="84" width="30" height="15" />
</collection> </collection>
<collection name="music" src="musicplayer.png"> <collection name="music" src="musicplayer.png">
<image name="pause" x="0" y="0" width="25" height="25" /> <image name="pause" x="0" y="0" width="25" height="25" />
<image name="stop" x="28" y="0" width="25" height="25" /> <image name="stop" x="28" y="0" width="25" height="25" />
<image name="play" x="56" y="0" width="25" height="25" /> <image name="play" x="56" y="0" width="25" height="25" />
<image name="next" x="84" y="0" width="25" height="25" /> <image name="next" x="84" y="0" width="25" height="25" />
<image name="prev" x="112" y="0" width="25" height="25" /> <image name="prev" x="112" y="0" width="25" height="25" />
</collection> </collection>
<collection name="scrollbar" src="buttons.png">
<image name="down_arrow" x="16" y="112" width="16" height="16" />
<image name="up_arrow" x="32" y="112" width="16" height="16" />
</collection>
<collection name="checkbox" src="buttons.png">
<image name="checked" x="0" y="112" width="16" height="16" />
</collection>
</chrome> </chrome>

View File

@@ -96,8 +96,9 @@ Container@ROOT:
Checkbox@STATUS: Checkbox@STATUS:
Id:STATUS Id:STATUS
X:455 X:455
Width:25 Y:2
Height:25 Width:20
Height:20
Container@TEMPLATE_REMOTE: Container@TEMPLATE_REMOTE:
Id:TEMPLATE_REMOTE Id:TEMPLATE_REMOTE
X:0 X:0
@@ -151,8 +152,9 @@ Container@ROOT:
Checkbox@STATUS: Checkbox@STATUS:
Id:STATUS Id:STATUS
X:455 X:455
Width:25 Y:2
Height:25 Width:20
Height:20
Container@LABEL_CONTAINER: Container@LABEL_CONTAINER:
X:30 X:30
Y:45 Y:45