almost working renderer

This commit is contained in:
Chris Forbes
2010-05-08 20:24:23 +12:00
parent f08247afd0
commit a09aed3370
3 changed files with 66 additions and 13 deletions

View File

@@ -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;

View File

@@ -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++ )

View File

@@ -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<ushort, Bitmap> Brush { get; set; }
Dictionary<int2, Bitmap> Chunks = new Dictionary<int2, Bitmap>();
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;
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))
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)
{
e.Graphics.DrawRectangle(RedPen, new Rectangle(CellSize * u, CellSize * v, CellSize, CellSize));
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);
}
if (Brush.Second != null)
e.Graphics.DrawImage(Brush.Second,
(MousePos - new int2(MousePos.X % 24, MousePos.Y % 24)).ToPoint());
}
}
}