This commit is contained in:
Chris Forbes
2010-05-08 20:59:18 +12:00
parent 5124319a29
commit 0feb2da477
3 changed files with 82 additions and 18 deletions

View File

@@ -29,16 +29,21 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer(); this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tilePalette = new System.Windows.Forms.FlowLayoutPanel(); this.tilePalette = new System.Windows.Forms.FlowLayoutPanel();
this.tt = new System.Windows.Forms.ToolTip(this.components);
this.surface1 = new OpenRA.Editor.Surface(); this.surface1 = new OpenRA.Editor.Surface();
this.tt = new System.Windows.Forms.ToolTip(this.components);
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.toolStripContainer1.ContentPanel.SuspendLayout(); this.toolStripContainer1.ContentPanel.SuspendLayout();
this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
this.toolStripContainer1.SuspendLayout(); this.toolStripContainer1.SuspendLayout();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout(); this.splitContainer1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// toolStripContainer1 // toolStripContainer1
@@ -55,6 +60,10 @@
this.toolStripContainer1.TabIndex = 1; this.toolStripContainer1.TabIndex = 1;
this.toolStripContainer1.Text = "toolStripContainer1"; this.toolStripContainer1.Text = "toolStripContainer1";
// //
// toolStripContainer1.TopToolStripPanel
//
this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.toolStrip1);
//
// splitContainer1 // splitContainer1
// //
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -81,10 +90,6 @@
this.tilePalette.Size = new System.Drawing.Size(198, 680); this.tilePalette.Size = new System.Drawing.Size(198, 680);
this.tilePalette.TabIndex = 0; this.tilePalette.TabIndex = 0;
// //
// tt
//
this.tt.ShowAlways = true;
//
// surface1 // surface1
// //
this.surface1.BackColor = System.Drawing.Color.Black; this.surface1.BackColor = System.Drawing.Color.Black;
@@ -92,11 +97,34 @@
this.surface1.Location = new System.Drawing.Point(0, 0); this.surface1.Location = new System.Drawing.Point(0, 0);
this.surface1.Map = null; this.surface1.Map = null;
this.surface1.Name = "surface1"; this.surface1.Name = "surface1";
this.surface1.Palette = null;
this.surface1.Size = new System.Drawing.Size(783, 680); this.surface1.Size = new System.Drawing.Size(783, 680);
this.surface1.TabIndex = 2; this.surface1.TabIndex = 2;
this.surface1.Text = "surface1"; this.surface1.Text = "surface1";
this.surface1.TileSet = null; this.surface1.TileSet = null;
// //
// tt
//
this.tt.ShowAlways = true;
//
// toolStrip1
//
this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1});
this.toolStrip1.Location = new System.Drawing.Point(3, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(94, 25);
this.toolStrip1.TabIndex = 0;
//
// toolStripButton1
//
this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Size = new System.Drawing.Size(51, 22);
this.toolStripButton1.Text = "Save";
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -106,11 +134,15 @@
this.Name = "Form1"; this.Name = "Form1";
this.Text = "OpenRA Editor"; this.Text = "OpenRA Editor";
this.toolStripContainer1.ContentPanel.ResumeLayout(false); this.toolStripContainer1.ContentPanel.ResumeLayout(false);
this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false);
this.toolStripContainer1.TopToolStripPanel.PerformLayout();
this.toolStripContainer1.ResumeLayout(false); this.toolStripContainer1.ResumeLayout(false);
this.toolStripContainer1.PerformLayout(); this.toolStripContainer1.PerformLayout();
this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.ResumeLayout(false); this.splitContainer1.ResumeLayout(false);
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -122,6 +154,8 @@
private Surface surface1; private Surface surface1;
private System.Windows.Forms.FlowLayoutPanel tilePalette; private System.Windows.Forms.FlowLayoutPanel tilePalette;
private System.Windows.Forms.ToolTip tt; private System.Windows.Forms.ToolTip tt;
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton toolStripButton1;
} }
} }

View File

@@ -117,7 +117,26 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>77, 17</value>
</metadata>
<metadata name="tt.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="tt.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="toolStripButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI
ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9
HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN
rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K
TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx
oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8
7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI
xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX
LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd
KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC
</value>
</data>
</root> </root>

View File

@@ -26,21 +26,30 @@ namespace OpenRA.Editor
UpdateStyles(); UpdateStyles();
} }
public const int CellSize = 24;
static readonly Pen RedPen = new Pen(Color.Red); static readonly Pen RedPen = new Pen(Color.Red);
int2 MousePos; int2 MousePos;
protected override void OnMouseMove(MouseEventArgs e) protected override void OnMouseMove(MouseEventArgs e)
{ {
base.OnMouseMove(e); base.OnMouseMove(e);
var oldMousePos = MousePos;
MousePos = new int2(e.Location); MousePos = new int2(e.Location);
if (e.Button == MouseButtons.Middle)
{
Offset += MousePos - oldMousePos;
Invalidate();
}
else
if (Brush.Second != null)
Invalidate(); Invalidate();
} }
protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e)
{ {
base.OnMouseDown(e); base.OnMouseDown(e);
if (e.Button == MouseButtons.Right) if (e.Button == MouseButtons.Right)
Brush = Pair.New((ushort)0, null as Bitmap); Brush = Pair.New((ushort)0, null as Bitmap);
@@ -52,6 +61,7 @@ namespace OpenRA.Editor
Bitmap RenderChunk(int u, int v) Bitmap RenderChunk(int u, int v)
{ {
var bitmap = new Bitmap(ChunkSize * 24, ChunkSize * 24); var bitmap = new Bitmap(ChunkSize * 24, ChunkSize * 24);
bitmap.SetPixel(0, 0, Color.Green);
var hx = Math.Min(Map.Width - u * ChunkSize, ChunkSize); var hx = Math.Min(Map.Width - u * ChunkSize, ChunkSize);
var hy = Math.Min(Map.Height - v * ChunkSize, ChunkSize); var hy = Math.Min(Map.Height - v * ChunkSize, ChunkSize);
@@ -62,21 +72,22 @@ namespace OpenRA.Editor
var tr = Map.MapTiles[u * ChunkSize + i, v * ChunkSize + j]; var tr = Map.MapTiles[u * ChunkSize + i, v * ChunkSize + j];
var tile = TileSet.tiles[tr.type]; var tile = TileSet.tiles[tr.type];
try var index = (tr.index < tile.TileBitmapBytes.Count) ? tr.index : 0;
{ var rawImage = tile.TileBitmapBytes[index];
var rawImage = tile.TileBitmapBytes[tr.index % tile.TileBitmapBytes.Count];
for (var x = 0; x < 24; x++) for (var x = 0; x < 24; x++)
for (var y = 0; y < 24; y++) for (var y = 0; y < 24; y++)
bitmap.SetPixel(i * 24 + x, j * 24 + y, Palette.GetColor(rawImage[x + 24 * y])); bitmap.SetPixel(i * 24 + x, j * 24 + y, Palette.GetColor(rawImage[x + 24 * y]));
} }
catch
{
}
}
return bitmap; return bitmap;
} }
int2 GetBrushLocation()
{
var v = MousePos - Offset;
return new int2(v.X / 24, v.Y / 24);
}
protected override void OnPaint(PaintEventArgs e) protected override void OnPaint(PaintEventArgs e)
{ {
if (Map == null) return; if (Map == null) return;
@@ -85,14 +96,14 @@ namespace OpenRA.Editor
for( var u = Map.TopLeft.X - Map.TopLeft.X % ChunkSize; u < Map.BottomRight.X; u += ChunkSize ) for( var u = Map.TopLeft.X - Map.TopLeft.X % ChunkSize; u < Map.BottomRight.X; u += ChunkSize )
for (var v = Map.TopLeft.Y - Map.TopLeft.Y % ChunkSize; v < Map.BottomRight.Y; v += ChunkSize) for (var v = Map.TopLeft.Y - Map.TopLeft.Y % ChunkSize; v < Map.BottomRight.Y; v += ChunkSize)
{ {
var x = new int2(u,v); var x = new int2(u/ChunkSize,v/ChunkSize);
if (!Chunks.ContainsKey(x)) Chunks[x] = RenderChunk(u / ChunkSize, v / ChunkSize); if (!Chunks.ContainsKey(x)) Chunks[x] = RenderChunk(u / ChunkSize, v / ChunkSize);
e.Graphics.DrawImage(Chunks[x], u * ChunkSize * 24, v * ChunkSize * 24); e.Graphics.DrawImage(Chunks[x], (24 * ChunkSize * x + Offset).ToPoint());
} }
if (Brush.Second != null) if (Brush.Second != null)
e.Graphics.DrawImage(Brush.Second, e.Graphics.DrawImage(Brush.Second,
(MousePos - new int2(MousePos.X % 24, MousePos.Y % 24)).ToPoint()); (24 * GetBrushLocation() + Offset).ToPoint());
} }
} }
} }