diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj
index 406107f042..243e37438d 100644
--- a/OpenRa.Game/OpenRa.Game.csproj
+++ b/OpenRa.Game/OpenRa.Game.csproj
@@ -43,6 +43,7 @@
+
diff --git a/OpenRa.Game/Region.cs b/OpenRa.Game/Region.cs
new file mode 100644
index 0000000000..24e939222e
--- /dev/null
+++ b/OpenRa.Game/Region.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Drawing;
+
+namespace OpenRa.Game
+{
+ class Region
+ {
+ PointF location;
+ Size size;
+ Renderable drawFunction;
+
+ public Region(PointF location, Size size, Renderable drawFunction)
+ {
+ this.location = location;
+ this.size = size;
+ this.drawFunction = drawFunction;
+ }
+
+ public void Draw(Renderer renderer, Viewport viewport)
+ {
+ renderer.Device.EnableScissor(location.X, location.Y, size.Width, size.Height);
+ drawFunction(renderer, viewport);
+ renderer.Device.DisableScissor();
+ }
+ }
+}
diff --git a/OpenRa.Game/Viewport.cs b/OpenRa.Game/Viewport.cs
index 0d535a4bf1..e25e1de745 100644
--- a/OpenRa.Game/Viewport.cs
+++ b/OpenRa.Game/Viewport.cs
@@ -2,15 +2,18 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
+using System.Windows.Forms;
using BluntDirectX.Direct3D;
namespace OpenRa.Game
{
+ public delegate void Renderable(Renderer renderer, Viewport viewport);
class Viewport
{
readonly Size clientSize;
readonly float2 mapSize;
float2 scrollPosition;
+ readonly Renderer renderer;
public PointF ScrollPosition { get { return scrollPosition.ToPointF(); } }
public Size ClientSize { get { return clientSize; } }
@@ -20,10 +23,40 @@ namespace OpenRa.Game
scrollPosition = (scrollPosition + delta).Constrain(new Range(float2.Zero, mapSize));
}
- public Viewport(Size clientSize, float2 mapSize)
+ public Viewport(Size clientSize, float2 mapSize, Renderer renderer)
{
this.clientSize = clientSize;
this.mapSize = 24 * mapSize - new float2(clientSize) + new float2(128, 0);
+ this.renderer = renderer;
+ }
+
+ List regions;
+ public void ResquestRegion(AnchorStyles anchor, int distanceFromAnchor, Renderable drawFunction)
+ {
+ switch (anchor)
+ {
+ case AnchorStyles.Top:
+ regions.Add(new Region(new PointF(0, 0), new Size(clientSize.Width, distanceFromAnchor), drawFunction));
+ break;
+ case AnchorStyles.Bottom:
+ regions.Add(new Region(new PointF(0, clientSize.Height), new Size(clientSize.Width, distanceFromAnchor), drawFunction));
+ break;
+ case AnchorStyles.Left:
+ regions.Add(new Region(new PointF(0, 0), new Size(distanceFromAnchor, clientSize.Height), drawFunction));
+ break;
+ case AnchorStyles.Right:
+ regions.Add(new Region(new PointF(clientSize.Width, 0), new Size(distanceFromAnchor, clientSize.Height), drawFunction));
+ break;
+ case AnchorStyles.None:
+ throw new NotImplementedException();
+ break;
+ }
+ }
+
+ public void DrawRegions()
+ {
+ foreach (Region region in regions)
+ region.Draw(renderer, this);
}
}
}