Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reducing flicker in tile editor, updating chunk/block/tile lists when…
… editing.
  • Loading branch information
MainMemory committed May 3, 2016
1 parent c358146 commit bce35e5
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions SonLVL/MainForm.cs
Expand Up @@ -3436,6 +3436,7 @@ private void ChunkPicture_MouseMove(object sender, MouseEventArgs e)
chunkBlockEditor.SelectedObjects = new[] { destBlock };
LevelData.RedrawChunk(SelectedChunk);
DrawChunkPicture();
ChunkSelector.Invalidate();
}
else if (e.Button == chunkblockMouseSelect)
{
Expand Down Expand Up @@ -3468,6 +3469,7 @@ private void ChunkPicture_MouseDown(object sender, MouseEventArgs e)
BlockSelector.SelectedIndex = blk.Block;
chunkBlockEditor.SelectedObjects = new[] { copiedChunkBlock = blk };
DrawChunkPicture();
ChunkSelector.Invalidate();
}
}

Expand All @@ -3478,6 +3480,7 @@ private void ChunkPicture_MouseUp(object sender, MouseEventArgs e)
LevelData.RedrawChunk(SelectedChunk);
DrawLevel();
DrawChunkPicture();
ChunkSelector.Invalidate();
}
}

Expand Down Expand Up @@ -3571,6 +3574,7 @@ private void ChunkPicture_KeyDown(object sender, KeyEventArgs e)
LevelData.RedrawChunk(SelectedChunk);
DrawLevel();
DrawChunkPicture();
ChunkSelector.Invalidate();
copiedChunkBlock = (chunkBlockEditor.SelectedObjects = blocks)[0];
}

Expand Down Expand Up @@ -3616,6 +3620,7 @@ private void flipChunkHButton_Click(object sender, EventArgs e)
BlockSelector.SelectedIndex = newcnk.Blocks[SelectedChunkBlock.X, SelectedChunkBlock.Y].Block;
copiedChunkBlock = (chunkBlockEditor.SelectedObjects = GetSelectedChunkBlocks())[0];
DrawChunkPicture();
ChunkSelector.Invalidate();
}

private void flipChunkVButton_Click(object sender, EventArgs e)
Expand All @@ -3627,6 +3632,7 @@ private void flipChunkVButton_Click(object sender, EventArgs e)
BlockSelector.SelectedIndex = newcnk.Blocks[SelectedChunkBlock.X, SelectedChunkBlock.Y].Block;
copiedChunkBlock = (chunkBlockEditor.SelectedObjects = GetSelectedChunkBlocks())[0];
DrawChunkPicture();
ChunkSelector.Invalidate();
}

private void BlockPicture_MouseMove(object sender, MouseEventArgs e)
Expand All @@ -3645,6 +3651,7 @@ private void BlockPicture_MouseMove(object sender, MouseEventArgs e)
blockTileEditor.SelectedObjects = new[] { destTile };
LevelData.RedrawBlock(SelectedBlock, false);
DrawBlockPicture();
BlockSelector.Invalidate();
}
else if (e.Button == chunkblockMouseSelect)
{
Expand Down Expand Up @@ -3687,6 +3694,7 @@ private void BlockPicture_MouseUp(object sender, MouseEventArgs e)
LevelData.RedrawBlock(SelectedBlock, true);
DrawLevel();
DrawBlockPicture();
BlockSelector.Invalidate();
}
}

Expand All @@ -3695,6 +3703,7 @@ private void blockTileEditor_PropertyValueChanged(object sender, EventArgs e)
LevelData.RedrawBlock(SelectedBlock, true);
DrawLevel();
DrawBlockPicture();
BlockSelector.Invalidate();
}

private void BlockSelector_SelectedIndexChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -3856,6 +3865,7 @@ private void BlockPicture_KeyDown(object sender, KeyEventArgs e)
LevelData.RedrawBlock(SelectedBlock, true);
DrawLevel();
DrawBlockPicture();
BlockSelector.Invalidate();
copiedBlockTile = (blockTileEditor.SelectedObjects = tiles)[0];
}

Expand Down Expand Up @@ -4099,18 +4109,26 @@ private void TileSelector_SelectedIndexChanged(object sender, EventArgs e)
tile = BitmapBits.FromTile(LevelData.Tiles[SelectedTile], 0);
TileID.Text = SelectedTile.ToString("X3");
TileCount.Text = LevelData.Tiles.Count.ToString("X") + " / 800";
TilePicture.Invalidate();
DrawTilePicture();
copiedBlockTile = new PatternIndex() { Tile = (ushort)SelectedTile, Palette = (byte)SelectedColor.Y };
}
else
rotateTileRightButton.Enabled = flipTileHButton.Enabled = flipTileVButton.Enabled = false;
}

private void TilePicture_Paint(object sender, PaintEventArgs e)
{
DrawTilePicture();
}

private void DrawTilePicture()
{
if (TileSelector.SelectedIndex == -1) return;
e.Graphics.SetOptions();
e.Graphics.DrawImage(tile.Scale(16).ToBitmap(curpal), 0, 0, 128, 128);
using (Graphics gfx = TilePicture.CreateGraphics())
{
gfx.SetOptions();
gfx.DrawImage(tile.Scale(16).ToBitmap(curpal), 0, 0, 128, 128);
}
}

private void TilePicture_MouseDown(object sender, MouseEventArgs e)
Expand All @@ -4119,7 +4137,7 @@ private void TilePicture_MouseDown(object sender, MouseEventArgs e)
if (e.Button == MouseButtons.Left)
{
tile[e.X / 16, e.Y / 16] = (byte)SelectedColor.X;
TilePicture.Invalidate();
DrawTilePicture();
}
else if (e.Button == MouseButtons.Right)
{
Expand All @@ -4134,7 +4152,7 @@ private void TilePicture_MouseMove(object sender, MouseEventArgs e)
if (e.Button == MouseButtons.Left && new Rectangle(Point.Empty, TilePicture.Size).Contains(e.Location))
{
tile.Bits[((e.Y / 16) * 8) + (e.X / 16)] = (byte)SelectedColor.X;
TilePicture.Invalidate();
DrawTilePicture();
}
}

Expand All @@ -4154,6 +4172,7 @@ private void TilePicture_MouseUp(object sender, MouseEventArgs e)
LevelData.RedrawBlock(i, true);
}
TileSelector.Images[SelectedTile] = LevelData.TileToBmp4bpp(LevelData.Tiles[SelectedTile], 0, SelectedColor.Y);
TileSelector.Invalidate();
blockTileEditor.SelectedObjects = blockTileEditor.SelectedObjects;
}

Expand Down Expand Up @@ -7850,6 +7869,7 @@ private void flipBlockHButton_Click(object sender, EventArgs e)
TileSelector.SelectedIndex = newblk.Tiles[SelectedBlockTile.X, SelectedBlockTile.Y].Tile;
copiedBlockTile = (blockTileEditor.SelectedObjects = GetSelectedBlockTiles())[0];
BlockPicture.Invalidate();
BlockSelector.Invalidate();
}

private void flipBlockVButton_Click(object sender, EventArgs e)
Expand All @@ -7861,6 +7881,7 @@ private void flipBlockVButton_Click(object sender, EventArgs e)
TileSelector.SelectedIndex = newblk.Tiles[SelectedBlockTile.X, SelectedBlockTile.Y].Tile;
copiedBlockTile = (blockTileEditor.SelectedObjects = GetSelectedBlockTiles())[0];
BlockPicture.Invalidate();
BlockSelector.Invalidate();
}

private void flipTileHButton_Click(object sender, EventArgs e)
Expand All @@ -7880,7 +7901,8 @@ private void flipTileHButton_Click(object sender, EventArgs e)
}
TileSelector.Images[SelectedTile] = LevelData.TileToBmp4bpp(LevelData.Tiles[SelectedTile], 0, SelectedColor.Y);
blockTileEditor.SelectedObjects = blockTileEditor.SelectedObjects;
TilePicture.Invalidate();
DrawTilePicture();
TileSelector.Invalidate();
}

private void flipTileVButton_Click(object sender, EventArgs e)
Expand All @@ -7900,7 +7922,8 @@ private void flipTileVButton_Click(object sender, EventArgs e)
}
TileSelector.Images[SelectedTile] = LevelData.TileToBmp4bpp(LevelData.Tiles[SelectedTile], 0, SelectedColor.Y);
blockTileEditor.SelectedObjects = blockTileEditor.SelectedObjects;
TilePicture.Invalidate();
DrawTilePicture();
TileSelector.Invalidate();
}

private void showBlockBehindCollisionCheckBox_CheckedChanged(object sender, EventArgs e)
Expand Down

0 comments on commit bce35e5

Please sign in to comment.