diff --git a/OpenRA.Editor/Form1.Designer.cs b/OpenRA.Editor/Form1.Designer.cs index 7443aba42e..1fa311f31d 100644 --- a/OpenRA.Editor/Form1.Designer.cs +++ b/OpenRA.Editor/Form1.Designer.cs @@ -32,8 +32,8 @@ this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.tilePalette = new System.Windows.Forms.FlowLayoutPanel(); - this.surface1 = new OpenRA.Editor.Surface(); this.tt = new System.Windows.Forms.ToolTip(this.components); + this.surface1 = new OpenRA.Editor.Surface(); this.toolStripContainer1.ContentPanel.SuspendLayout(); this.toolStripContainer1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout(); @@ -81,6 +81,10 @@ this.tilePalette.Size = new System.Drawing.Size(198, 680); this.tilePalette.TabIndex = 0; // + // tt + // + this.tt.ShowAlways = true; + // // surface1 // this.surface1.BackColor = System.Drawing.Color.Black; diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index 98c869de99..1328c2840a 100644 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -36,6 +36,7 @@ namespace OpenRA.Editor surface1.TileSet = tileset; surface1.Map = map; + surface1.Palette = palette; // construct the palette of tiles @@ -44,8 +45,27 @@ namespace OpenRA.Editor try { var bitmap = RenderTemplate(tileset, (ushort)n, palette); - var ibox = new PictureBox { Image = bitmap, Width = bitmap.Width, Height = bitmap.Height }; + var ibox = new PictureBox + { + Image = bitmap, + Width = bitmap.Width / 2, + Height = bitmap.Height / 2, + SizeMode = PictureBoxSizeMode.StretchImage + }; + + var p = Pair.New(n, bitmap); + ibox.Click += (_, e) => surface1.Brush = p; + + var template = tileset.walk[n]; tilePalette.Controls.Add(ibox); + + tt.SetToolTip(ibox, + "{1}:{0} ({3}x{4} {2})".F( + template.Name, + template.Index, + template.Bridge, + template.Size.X, + template.Size.Y)); } catch { } } @@ -77,7 +97,7 @@ namespace OpenRA.Editor var template = ts.walk[n]; var tile = ts.tiles[n]; - var bitmap = new Bitmap(Surface.CellSize * template.Size.X, Surface.CellSize * template.Size.Y); + var bitmap = new Bitmap(24 * template.Size.X, 24 * template.Size.Y); for( var u = 0; u < template.Size.X; u++ ) for( var v = 0; v < template.Size.Y; v++ ) diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 5ee7b9ff4b..8afff58c7c 100644 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -12,7 +12,11 @@ namespace OpenRA.Editor { public Map Map { get; set; } public TileSet TileSet { get; set; } + public Palette Palette { get; set; } public int2 Offset { get; set; } + public Pair Brush { get; set; } + + Dictionary Chunks = new Dictionary(); public Surface() : base() @@ -26,23 +30,48 @@ namespace OpenRA.Editor public const int CellSize = 24; static readonly Pen RedPen = new Pen(Color.Red); + int2 MousePos; + + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + MousePos = new int2(e.Location); + Invalidate(); + } + + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + if (e.Button == MouseButtons.Right) + Brush = Pair.New((ushort)0, null as Bitmap); + + Invalidate(); + } + + const int ChunkSize = 8; // 8x8 chunks ==> 192x192 bitmaps. + + Bitmap RenderChunk(int u, int v) + { + var bitmap = new Bitmap(ChunkSize * 24, ChunkSize * 24); + return bitmap; + } protected override void OnPaint(PaintEventArgs e) { if (Map == null) return; if (TileSet == null) return; - var n = (ushort)14; + 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) + { + var x = new int2(u,v); + if (!Chunks.ContainsKey(x)) Chunks[x] = RenderChunk(u, v); + e.Graphics.DrawImage(Chunks[x], u * ChunkSize * 24, v * ChunkSize * 24); + } - var template = TileSet.walk[n]; - var tile = TileSet.tiles[n]; - - for( var u = 0; u < template.Size.X; u++ ) - for( var v = 0; v < template.Size.Y; v++ ) - if (template.TerrainType.ContainsKey(u + v * template.Size.X)) - { - e.Graphics.DrawRectangle(RedPen, new Rectangle(CellSize * u, CellSize * v, CellSize, CellSize)); - } + if (Brush.Second != null) + e.Graphics.DrawImage(Brush.Second, + (MousePos - new int2(MousePos.X % 24, MousePos.Y % 24)).ToPoint()); } } } \ No newline at end of file