git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1230 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
beedee
2007-07-14 07:18:48 +00:00
parent dc64b74ceb
commit 9f1d288833
3 changed files with 63 additions and 1 deletions

View File

@@ -43,6 +43,7 @@
<Compile Include="Actor.cs" /> <Compile Include="Actor.cs" />
<Compile Include="Clock.cs" /> <Compile Include="Clock.cs" />
<Compile Include="float2.cs" /> <Compile Include="float2.cs" />
<Compile Include="Region.cs" />
<Compile Include="SheetBuilder.cs" /> <Compile Include="SheetBuilder.cs" />
<Compile Include="HardwarePalette.cs" /> <Compile Include="HardwarePalette.cs" />
<Compile Include="MainWindow.cs"> <Compile Include="MainWindow.cs">

28
OpenRa.Game/Region.cs Normal file
View File

@@ -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();
}
}
}

View File

@@ -2,15 +2,18 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Drawing; using System.Drawing;
using System.Windows.Forms;
using BluntDirectX.Direct3D; using BluntDirectX.Direct3D;
namespace OpenRa.Game namespace OpenRa.Game
{ {
public delegate void Renderable(Renderer renderer, Viewport viewport);
class Viewport class Viewport
{ {
readonly Size clientSize; readonly Size clientSize;
readonly float2 mapSize; readonly float2 mapSize;
float2 scrollPosition; float2 scrollPosition;
readonly Renderer renderer;
public PointF ScrollPosition { get { return scrollPosition.ToPointF(); } } public PointF ScrollPosition { get { return scrollPosition.ToPointF(); } }
public Size ClientSize { get { return clientSize; } } public Size ClientSize { get { return clientSize; } }
@@ -20,10 +23,40 @@ namespace OpenRa.Game
scrollPosition = (scrollPosition + delta).Constrain(new Range<float2>(float2.Zero, mapSize)); scrollPosition = (scrollPosition + delta).Constrain(new Range<float2>(float2.Zero, mapSize));
} }
public Viewport(Size clientSize, float2 mapSize) public Viewport(Size clientSize, float2 mapSize, Renderer renderer)
{ {
this.clientSize = clientSize; this.clientSize = clientSize;
this.mapSize = 24 * mapSize - new float2(clientSize) + new float2(128, 0); this.mapSize = 24 * mapSize - new float2(clientSize) + new float2(128, 0);
this.renderer = renderer;
}
List<Region> 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);
} }
} }
} }