diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs
index ad582f8a1e..8349a06360 100644
--- a/OpenRA.Game/Chrome.cs
+++ b/OpenRA.Game/Chrome.cs
@@ -162,18 +162,6 @@ namespace OpenRA
renderer.Device.DisableScissor();
- if (Game.Settings.PerfText)
- renderer.RegularFont.DrawText( rgbaRenderer, "RenderFrame {0} ({2:F1} ms)\nTick {4}/ Net{1} ({3:F1} ms)\n".F(
- Game.RenderFrame,
- Game.orderManager.FrameNumber,
- PerfHistory.items["render"].LastValue,
- PerfHistory.items["tick_time"].LastValue,
- Game.LocalTick),
- new int2(140, 15), Color.White);
-
- if (Game.Settings.PerfGraph)
- PerfHistory.Render(renderer, world.WorldRenderer.lineRenderer);
-
DrawRadar( world );
DrawPower( world );
rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer, chromeCollection, "moneybin"), new float2(Game.viewport.Width - 320, 0), "chrome");
diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index fc48d49f12..62eb0ece81 100755
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -297,6 +297,7 @@
+
diff --git a/OpenRA.Game/Support/PerfHistory.cs b/OpenRA.Game/Support/PerfHistory.cs
index 94a8dcbed3..39cc5ba2be 100644
--- a/OpenRA.Game/Support/PerfHistory.cs
+++ b/OpenRA.Game/Support/PerfHistory.cs
@@ -1,4 +1,4 @@
-#region Copyright & License Information
+#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
@@ -55,31 +55,6 @@ namespace OpenRA.Support
if (item.hasNormalTick)
item.Tick();
}
-
- public static void Render(Renderer r, LineRenderer lr)
- {
- float2 origin = Game.viewport.Location + new float2(330, Game.viewport.Height - 30);
- float2 basis = new float2(-3, -3);
-
- lr.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
- lr.DrawLine(origin + new float2(100,0) * basis, origin + new float2(100,70) * basis, Color.White, Color.White);
-
- foreach (var item in items.Values)
- {
- int n = 0;
- item.Samples().Aggregate((a, b) =>
- {
- lr.DrawLine(
- origin + new float2(n, (float)a) * basis,
- origin + new float2(n+1, (float)b) * basis,
- item.c, item.c);
- ++n;
- return b;
- });
- }
-
- lr.Flush();
- }
}
class PerfItem
diff --git a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
index d2c90c74dd..72f12ca86e 100644
--- a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
@@ -19,6 +19,8 @@
#endregion
using System;
using OpenRA.FileFormats;
+using OpenRA.Support;
+
namespace OpenRA.Widgets.Delegates
{
public class IngameChromeDelegate : IWidgetDelegate
@@ -26,7 +28,8 @@ namespace OpenRA.Widgets.Delegates
public IngameChromeDelegate()
{
var r = Chrome.rootWidget;
- var optionsBG = r.GetWidget("INGAME_OPTIONS_BG");
+ var gameRoot = r.GetWidget("INGAME_ROOT");
+ var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
optionsBG.Visible = !optionsBG.Visible;
return true;
@@ -49,6 +52,21 @@ namespace OpenRA.Widgets.Delegates
return true;
};
+ // Perf text
+ var perfText = gameRoot.GetWidget("PERFTEXT");
+ perfText.GetText = () => {
+ return "RenderFrame {0} ({2:F1} ms)\nTick {4}/ Net{1} ({3:F1} ms)".F(
+ Game.RenderFrame,
+ Game.orderManager.FrameNumber,
+ PerfHistory.items["render"].LastValue,
+ PerfHistory.items["tick_time"].LastValue,
+ Game.LocalTick);
+ };
+ perfText.IsVisible = () => {return (perfText.Visible && Game.Settings.PerfText);};
+
+ // Perf graph
+ var perfGraph = gameRoot.GetWidget("PERFGRAPH");
+ perfGraph.IsVisible = () => {return (perfGraph.Visible && Game.Settings.PerfGraph);};
}
}
}
diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs
index 41472d3084..c8aedbb3ca 100644
--- a/OpenRA.Game/Widgets/LabelWidget.cs
+++ b/OpenRA.Game/Widgets/LabelWidget.cs
@@ -19,6 +19,7 @@
#endregion
using System.Drawing;
+using System;
namespace OpenRA.Widgets
{
@@ -26,26 +27,35 @@ namespace OpenRA.Widgets
{
public string Text = "";
public string Align = "Left";
+ public bool Bold = true;
+ public Func GetText;
+ public override void Initialize()
+ {
+ base.Initialize();
+ GetText = () => {return Text;};
+ }
+
public override void Draw(World world)
{
- if (!Visible)
+ if (!IsVisible())
{
base.Draw(world);
return;
}
-
- Rectangle r = Bounds;
- Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
- int2 textSize = Game.chrome.renderer.BoldFont.Measure(Text);
+ var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
+ var text = GetText();
+ Rectangle r = Bounds;
+ Game.chrome.renderer.Device.EnableScissor(r.Left,r.Top,r.Width,r.Height);
+ int2 textSize = font.Measure(text);
int2 position = new int2(Bounds.X,Bounds.Y);
if (Align == "Center")
position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2)
- new int2(textSize.X / 2, textSize.Y/2);
- Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White);
+ font.DrawText(Game.chrome.rgbaRenderer, text, position, Color.White);
Game.chrome.rgbaRenderer.Flush();
Game.chrome.renderer.Device.DisableScissor();
base.Draw(world);
diff --git a/OpenRA.Game/Widgets/PerfGraphWidget.cs b/OpenRA.Game/Widgets/PerfGraphWidget.cs
new file mode 100644
index 0000000000..7b6feaaa60
--- /dev/null
+++ b/OpenRA.Game/Widgets/PerfGraphWidget.cs
@@ -0,0 +1,62 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
+ * This file is part of OpenRA.
+ *
+ * OpenRA is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenRA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenRA. If not, see .
+ */
+#endregion
+using System.Drawing;
+using System.Collections.Generic;
+using System.Linq;
+using OpenRA.Support;
+
+namespace OpenRA.Widgets
+{
+ class PerfGraphWidget : Widget
+ {
+ public override void Draw(World world)
+ {
+ if (!IsVisible())
+ {
+ base.Draw(world);
+ return;
+ }
+
+ float2 origin = Game.viewport.Location + new float2(Bounds.Right,Bounds.Bottom);
+ float2 basis = new float2(-Bounds.Width/100,-Bounds.Height/100);
+
+ Game.chrome.lineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
+ Game.chrome.lineRenderer.DrawLine(origin + new float2(100,0) * basis, origin + new float2(100,70) * basis, Color.White, Color.White);
+
+ foreach (var item in PerfHistory.items.Values)
+ {
+ int n = 0;
+ item.Samples().Aggregate((a, b) =>
+ {
+ Game.chrome.lineRenderer.DrawLine(
+ origin + new float2(n, (float)a) * basis,
+ origin + new float2(n+1, (float)b) * basis,
+ item.c, item.c);
+ ++n;
+ return b;
+ });
+ }
+
+ Game.chrome.lineRenderer.Flush();
+
+ base.Draw(world);
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs
index ec68afc8d2..5ad594fcac 100644
--- a/OpenRA.Game/Widgets/Widget.cs
+++ b/OpenRA.Game/Widgets/Widget.cs
@@ -48,6 +48,12 @@ namespace OpenRA.Widgets
public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); }
+ // Common Funcs that most widgets will want
+ public Func OnMouseDown = mi => {return false;};
+ public Func OnMouseUp = mi => {return false;};
+ public Func OnMouseMove = mi => {return false;};
+ public Func IsVisible;
+
public virtual void Initialize()
{
// Parse the YAML equations to find the widget bounds
@@ -69,6 +75,8 @@ namespace OpenRA.Widgets
width,
height);
+ // Non-static func definitions
+ IsVisible = () => {return Visible;};
foreach (var child in Children)
child.Initialize();
@@ -87,13 +95,7 @@ namespace OpenRA.Widgets
if (name == null) return null;
return Game.CreateObject(name);
}
-
- // Common Funcs that most widgets will want
- public Func OnMouseDown = mi => {return false;};
- public Func OnMouseUp = mi => {return false;};
- public Func OnMouseMove = mi => {return false;};
-
-
+
public virtual bool HandleInput(MouseInput mi)
{
// Are we able to handle this event?
diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml
index 836209b346..7a63732af7 100644
--- a/mods/ra/menus.yaml
+++ b/mods/ra/menus.yaml
@@ -261,6 +261,21 @@ Container:
Id:INGAME_ROOT
Visible:false
Children:
+ PerfGraph@PERFGRAPH:
+ Id:PERFGRAPH
+ X:10
+ Y:WINDOW_BOTTOM - 250
+ Width:200
+ Height:200
+ Delegate:IngameChromeDelegate
+ Label@PERFTEXT:
+ Id:PERFTEXT
+ Bold: false
+ X:10
+ Y:WINDOW_BOTTOM - 40
+ Width:200
+ Height:100
+ Delegate:IngameChromeDelegate
SpecialPowerBin@INGAME_POWERS_BIN:
Id:INGAME_POWERS_BIN
X:0