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

This commit is contained in:
chrisf
2007-07-14 06:59:06 +00:00
parent 89a0a07ed1
commit 8e1e815f8b
5 changed files with 91 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
namespace OpenRa.FileFormats
{
@@ -16,6 +17,8 @@ namespace OpenRa.FileFormats
public readonly int Width;
public readonly int Height;
public PointF Size { get { return new PointF(Width, Height); } }
public readonly TileReference[ , ] MapTiles = new TileReference[ 128, 128 ];
public readonly List<TreeReference> Trees = new List<TreeReference>();

View File

@@ -76,28 +76,29 @@ namespace OpenRa.Game
}
}
Point lastPos;
float2 lastPos;
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
lastPos = e.Location;
lastPos = new float2(e.Location);
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button != 0)
{
PointF scrollPos = viewport.ScrollPosition;
scrollPos.X = Util.Constrain(scrollPos.X + lastPos.X - e.X, new Range<float>(0, map.Width * 24 - ClientSize.Width + 128));
scrollPos.Y = Util.Constrain(scrollPos.Y + lastPos.Y - e.Y, new Range<float>(0, map.Height * 24 - ClientSize.Height));
if (e.Button == 0)
return;
lastPos = e.Location;
float2 scrollPos = new float2(viewport.ScrollPosition) + lastPos - new float2(e.Location);
float2 mapSize = 24 * new float2(map.Size) - viewport.Size + new float2(128, 0);
viewport.ScrollPosition = scrollPos;
}
scrollPos = scrollPos.Constrain(new Range<float2>(float2.Zero, mapSize));
lastPos = new float2(e.Location);
viewport.ScrollPosition = scrollPos.ToPointF();
}
void Frame()

View File

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

View File

@@ -21,10 +21,11 @@ namespace OpenRa.Game
get { return clientSize; }
}
public Viewport(Size clientSize)
{
this.clientSize = clientSize;
}
public float2 Size { get { return new float2(clientSize); } }
}
}

74
OpenRa.Game/float2.cs Normal file
View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using BluntDirectX.Direct3D;
namespace OpenRa.Game
{
[StructLayout(LayoutKind.Sequential)]
class float2
{
public float X, Y;
public float2(float x, float y)
{
X = x;
Y = y;
}
public PointF ToPointF()
{
return new PointF(X, Y);
}
public float2(PointF p)
{
X = p.X;
Y = p.Y;
}
public float2(Point p)
{
X = p.X;
Y = p.Y;
}
public float2(Size p)
{
X = p.Width;
Y = p.Height;
}
public float2(SizeF p)
{
X = p.Width;
Y = p.Height;
}
public static float2 operator +(float2 a, float2 b)
{
return new float2(a.X + b.X, a.Y + b.Y);
}
public static float2 operator -(float2 a, float2 b)
{
return new float2(a.X - b.X, a.Y - b.Y);
}
public float2 Constrain(Range<float2> r)
{
return new float2(
Util.Constrain(X, new Range<float>(r.Start.X, r.End.X)),
Util.Constrain(Y, new Range<float>(r.Start.Y, r.End.Y)));
}
public static float2 operator *(float a, float2 b)
{
return new float2(a * b.X, a * b.Y);
}
public static readonly float2 Zero = new float2(0, 0);
}
}