Added a new tool (Dotted Pencil)
This commit is contained in:
96
Paint_2/DotPencil.cs
Normal file
96
Paint_2/DotPencil.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
public class DotPencil:PaintTool
|
||||
{
|
||||
private List<List<Point>> _drawings;
|
||||
private List<Color> _colors;
|
||||
private List<int> _widths;
|
||||
private Color _color;
|
||||
private int _width;
|
||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public int Width { get => _width; set => _width = value; }
|
||||
public DotPencil()
|
||||
{
|
||||
Drawings = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
Drawings[Drawings.Count - 1].Add(point);
|
||||
}
|
||||
public void Paint(Bitmap canvas)
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
int drawingCounter = 0;
|
||||
Size pointSize;
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
int pointCounter = 0;
|
||||
foreach (Point p in drawing)
|
||||
{
|
||||
if (pointCounter > 0)
|
||||
{
|
||||
pointSize = new Size(Widths[drawingCounter], Widths[drawingCounter]);
|
||||
gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(new Point(p.X - pointSize.Width / 2, p.Y - pointSize.Height / 2), pointSize));
|
||||
}
|
||||
|
||||
pointCounter += 1;
|
||||
}
|
||||
drawingCounter += 1;
|
||||
}
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Color = color;
|
||||
Width = width;
|
||||
List<Point> points = new List<Point>();
|
||||
Drawings.Add(points);
|
||||
Colors.Add(Color);
|
||||
Widths.Add(Width);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Drawings = new List<List<Point>>();
|
||||
}
|
||||
public void Stop(Point point)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
List<Color> result = new List<Color>();
|
||||
if (Colors.Count <= colorNumber)
|
||||
{
|
||||
//We need to fill with black color
|
||||
for (int i = Colors.Count; i > 0; i--)
|
||||
{
|
||||
result.Add(Colors[(Colors.Count) - i]);
|
||||
}
|
||||
for (int i = colorNumber - Colors.Count; i > 0; i--)
|
||||
{
|
||||
result.Add(Color.FromArgb(0x00, 0x00, 0x00));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = colorNumber; i > 0; i--)
|
||||
{
|
||||
result.Add(Colors[(Colors.Count) - i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Paint_2/Form1.Designer.cs
generated
2
Paint_2/Form1.Designer.cs
generated
@@ -435,6 +435,7 @@
|
||||
this.btnPencil.TabIndex = 20;
|
||||
this.btnPencil.Text = "Pencil";
|
||||
this.btnPencil.UseVisualStyleBackColor = false;
|
||||
this.btnPencil.Click += new System.EventHandler(this.btnPencil_Click);
|
||||
//
|
||||
// btnDotTracer
|
||||
//
|
||||
@@ -448,6 +449,7 @@
|
||||
this.btnDotTracer.TabIndex = 21;
|
||||
this.btnDotTracer.Text = "Dot tracer";
|
||||
this.btnDotTracer.UseVisualStyleBackColor = false;
|
||||
this.btnDotTracer.Click += new System.EventHandler(this.btnDotTracer_Click);
|
||||
//
|
||||
// btnShapeCreator
|
||||
//
|
||||
|
||||
@@ -14,6 +14,9 @@ namespace Paint_2
|
||||
{
|
||||
public partial class PaintForm : Form
|
||||
{
|
||||
const int DEFAULT_PENCIL = 0;
|
||||
const int DOT_PENCIL = 1;
|
||||
|
||||
const string DEFAULT_FILEPATH = "C:/Paint2/Drawings/";
|
||||
Sketch sketch;
|
||||
List<PaintTool> toolList;
|
||||
@@ -29,7 +32,7 @@ namespace Paint_2
|
||||
nupHeight.Value = canvas.Height;
|
||||
toolList = new List<PaintTool>();
|
||||
toolList.Add(new Pencil());
|
||||
toolList.Add(new Pencil());
|
||||
toolList.Add(new DotPencil());
|
||||
sketch = new Sketch(new Size((int)nupWidth.Value, (int)nupHeight.Value), toolList);
|
||||
canvas.Image = sketch.Drawing;
|
||||
tmrRefresh.Enabled = true;
|
||||
@@ -43,17 +46,9 @@ namespace Paint_2
|
||||
{
|
||||
drawing = true;
|
||||
sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), (int)nupPencilWidth.Value);
|
||||
//tmrRefresh.Enabled = true;
|
||||
|
||||
List<Color> colorHistory = sketch.CurrentTool.GetLastColors(4);
|
||||
btnColorHistory1.BackColor = colorHistory[0];
|
||||
btnColorHistory2.BackColor = colorHistory[1];
|
||||
btnColorHistory3.BackColor = colorHistory[2];
|
||||
btnColorHistory4.BackColor = colorHistory[3];
|
||||
}
|
||||
private void canvas_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
//tmrRefresh.Enabled = false;
|
||||
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
||||
drawing = false;
|
||||
RefreshUi();
|
||||
@@ -90,6 +85,12 @@ namespace Paint_2
|
||||
hoveringColor = GetHoverColor();
|
||||
lblHoveringColor.Text = ColorToString(hoveringColor);
|
||||
btnHoveringColor.BackColor = hoveringColor;
|
||||
|
||||
List<Color> colorHistory = sketch.CurrentTool.GetLastColors(4);
|
||||
btnColorHistory1.BackColor = colorHistory[0];
|
||||
btnColorHistory2.BackColor = colorHistory[1];
|
||||
btnColorHistory3.BackColor = colorHistory[2];
|
||||
btnColorHistory4.BackColor = colorHistory[3];
|
||||
}
|
||||
private Color GetHoverColor()
|
||||
{
|
||||
@@ -193,5 +194,17 @@ namespace Paint_2
|
||||
|
||||
image.Save(DEFAULT_FILEPATH + fileName + "/" + fileName + ".png", System.Drawing.Imaging.ImageFormat.Png);
|
||||
}
|
||||
|
||||
private void btnDotTracer_Click(object sender, EventArgs e)
|
||||
{
|
||||
sketch.ChangeTool(DOT_PENCIL);
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void btnPencil_Click(object sender, EventArgs e)
|
||||
{
|
||||
sketch.ChangeTool(DEFAULT_PENCIL);
|
||||
RefreshUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DotPencil.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -45,6 +45,16 @@ namespace Paint_2
|
||||
{
|
||||
//empty
|
||||
}
|
||||
public void ChangeTool(int toolId)
|
||||
{
|
||||
try
|
||||
{
|
||||
CurrentTool = ToolList[toolId];
|
||||
}catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Oooops...");
|
||||
}
|
||||
}
|
||||
public void StartDrawing(Point location,Color color,int width)
|
||||
{
|
||||
CurrentTool.Start(color,width);
|
||||
|
||||
Reference in New Issue
Block a user