Skip to content

Commit

Permalink
Adding Fill tool to Draw dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Jun 12, 2015
1 parent 91a7dda commit 5be1fc5
Show file tree
Hide file tree
Showing 11 changed files with 450 additions and 257 deletions.
87 changes: 72 additions & 15 deletions SonLVL/DrawTileDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 41 additions & 8 deletions SonLVL/DrawTileDialog.cs
Expand Up @@ -47,24 +47,34 @@ private void TilePicture_Paint(object sender, PaintEventArgs e)
DrawTile();
}

private Tool tool;
private void TilePicture_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
tile.Bits[((e.Y / (int)numericUpDown1.Value) * tile.Width) + (e.X / (int)numericUpDown1.Value)] = (byte)((selectedColor.Y * 16) + selectedColor.X);
lastpoint = new Point(e.X / (int)numericUpDown1.Value, e.Y / (int)numericUpDown1.Value);
DrawTile();
}
switch (tool)
{
case Tool.Pencil:
tile[e.X / (int)numericUpDown1.Value, e.Y / (int)numericUpDown1.Value] = (byte)((selectedColor.Y * 16) + selectedColor.X);
lastpoint = new Point(e.X / (int)numericUpDown1.Value, e.Y / (int)numericUpDown1.Value);
DrawTile();
break;
case Tool.Fill:
tile.FloodFill((byte)((selectedColor.Y * 16) + selectedColor.X), e.X / (int)numericUpDown1.Value, e.Y / (int)numericUpDown1.Value);
DrawTile();
break;
}
}

Point lastpoint;
private void TilePicture_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
if (tool == Tool.Pencil && e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (new Rectangle(Point.Empty, TilePicture.Size).Contains(e.Location))
{
tile.DrawLine((byte)((selectedColor.Y * 16) + selectedColor.X), lastpoint, new Point(e.X / (int)numericUpDown1.Value, e.Y / (int)numericUpDown1.Value));
tile.Bits[((e.Y / (int)numericUpDown1.Value) * tile.Width) + (e.X / (int)numericUpDown1.Value)] = (byte)((selectedColor.Y * 16) + selectedColor.X);
tile[e.X / (int)numericUpDown1.Value, e.Y / (int)numericUpDown1.Value] = (byte)((selectedColor.Y * 16) + selectedColor.X);
}
lastpoint = new Point(e.X / (int)numericUpDown1.Value, e.Y / (int)numericUpDown1.Value);
DrawTile();
}
Expand All @@ -82,11 +92,16 @@ private void numericUpDown1_ValueChanged(object sender, EventArgs e)
TilePicture.Size = new Size(tile.Width * (int)numericUpDown1.Value, tile.Height * (int)numericUpDown1.Value);
}

Cursor pencilcur, fillcur;
private void DrawTileDialog_Shown(object sender, EventArgs e)
{
tileGfx = TilePicture.CreateGraphics();
tileGfx.SetOptions();
TilePicture.Cursor = new Cursor(new System.IO.MemoryStream(Properties.Resources.pencilcur));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Properties.Resources.pencilcur))
pencilcur = new Cursor(ms);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Properties.Resources.fillcur))
fillcur = new Cursor(ms);
TilePicture.Cursor = pencilcur;
TilePicture.Size = new Size(tile.Width * (int)numericUpDown1.Value, tile.Height * (int)numericUpDown1.Value);
}

Expand All @@ -95,5 +110,23 @@ private void TilePicture_Resize(object sender, EventArgs e)
tileGfx = TilePicture.CreateGraphics();
tileGfx.SetOptions();
}

private void pencilToolStripButton_Click(object sender, EventArgs e)
{
pencilToolStripButton.Checked = true;
fillToolStripButton.Checked = false;
tool = Tool.Pencil;
TilePicture.Cursor = pencilcur;
}

private void fillToolStripButton_Click(object sender, EventArgs e)
{
pencilToolStripButton.Checked = false;
fillToolStripButton.Checked = true;
tool = Tool.Fill;
TilePicture.Cursor = fillcur;
}

enum Tool { Pencil, Fill }
}
}
3 changes: 3 additions & 0 deletions SonLVL/DrawTileDialog.resx
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

0 comments on commit 5be1fc5

Please sign in to comment.