diff --git a/Paint_2/DotPencil.cs b/Paint_2/DotPencil.cs new file mode 100644 index 0000000..0f45043 --- /dev/null +++ b/Paint_2/DotPencil.cs @@ -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> _drawings; + private List _colors; + private List _widths; + private Color _color; + private int _width; + public List> Drawings { get => _drawings; set => _drawings = value; } + public List Colors { get => _colors; set => _colors = value; } + public List 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>(); + Colors = new List(); + Widths = new List(); + } + 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 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 points = new List(); + Drawings.Add(points); + Colors.Add(Color); + Widths.Add(Width); + } + public void Clear() + { + Drawings = new List>(); + } + public void Stop(Point point) + { + throw new NotImplementedException(); + } + public List GetLastColors(int colorNumber) + { + List result = new List(); + 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; + } + } +} diff --git a/Paint_2/Form1.Designer.cs b/Paint_2/Form1.Designer.cs index 4ea2590..68fbf21 100644 --- a/Paint_2/Form1.Designer.cs +++ b/Paint_2/Form1.Designer.cs @@ -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 // diff --git a/Paint_2/Form1.cs b/Paint_2/Form1.cs index d28e1a0..36e5758 100644 --- a/Paint_2/Form1.cs +++ b/Paint_2/Form1.cs @@ -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 toolList; @@ -29,7 +32,7 @@ namespace Paint_2 nupHeight.Value = canvas.Height; toolList = new List(); 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 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 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(); + } } } diff --git a/Paint_2/Paint_2.csproj b/Paint_2/Paint_2.csproj index a6a55cb..dad7e1d 100644 --- a/Paint_2/Paint_2.csproj +++ b/Paint_2/Paint_2.csproj @@ -46,6 +46,7 @@ + Form diff --git a/Paint_2/Sketch.cs b/Paint_2/Sketch.cs index 9024a47..72a73e7 100644 --- a/Paint_2/Sketch.cs +++ b/Paint_2/Sketch.cs @@ -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);