Added the rectangle Tool and the ability for each tool to be painted or force painted
This commit is contained in:
@@ -17,6 +17,7 @@ namespace Paint_2
|
|||||||
{
|
{
|
||||||
private List<List<Point>> _drawings;
|
private List<List<Point>> _drawings;
|
||||||
private List<List<Point>> _drawingsRedo;
|
private List<List<Point>> _drawingsRedo;
|
||||||
|
private bool _needsFullRefresh;
|
||||||
private PaintToolUtils Utils;
|
private PaintToolUtils Utils;
|
||||||
private List<Color> _colors;
|
private List<Color> _colors;
|
||||||
private List<Color> _colorsRedo;
|
private List<Color> _colorsRedo;
|
||||||
@@ -28,6 +29,7 @@ namespace Paint_2
|
|||||||
|
|
||||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||||
|
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||||
@@ -38,6 +40,7 @@ namespace Paint_2
|
|||||||
|
|
||||||
public BezierPencil(string name)
|
public BezierPencil(string name)
|
||||||
{
|
{
|
||||||
|
NeedsFullRefresh = false;
|
||||||
Drawings = new List<List<Point>>();
|
Drawings = new List<List<Point>>();
|
||||||
DrawingsRedo = new List<List<Point>>();
|
DrawingsRedo = new List<List<Point>>();
|
||||||
Colors = new List<Color>();
|
Colors = new List<Color>();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Paint_2
|
|||||||
|
|
||||||
private List<List<Point>> _drawings;
|
private List<List<Point>> _drawings;
|
||||||
private List<List<Point>> _drawingsRedo;
|
private List<List<Point>> _drawingsRedo;
|
||||||
|
private bool _needsFullRefresh;
|
||||||
private PaintToolUtils Utils;
|
private PaintToolUtils Utils;
|
||||||
private List<Color> _colors;
|
private List<Color> _colors;
|
||||||
private List<Color> _colorsRedo;
|
private List<Color> _colorsRedo;
|
||||||
@@ -30,6 +31,7 @@ namespace Paint_2
|
|||||||
|
|
||||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||||
|
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||||
@@ -47,6 +49,7 @@ namespace Paint_2
|
|||||||
Widths = new List<int>();
|
Widths = new List<int>();
|
||||||
WidthsRedo = new List<int>();
|
WidthsRedo = new List<int>();
|
||||||
Name = name;
|
Name = name;
|
||||||
|
NeedsFullRefresh = false;
|
||||||
|
|
||||||
Utils = new PaintToolUtils(this);
|
Utils = new PaintToolUtils(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,16 @@ namespace Paint_2
|
|||||||
lsbTools.DataSource = Project.AvaibleTools;
|
lsbTools.DataSource = Project.AvaibleTools;
|
||||||
DebugLabel.Text = "";
|
DebugLabel.Text = "";
|
||||||
|
|
||||||
canvas.Image = Project.PaintLayers();
|
PaintTool currentTool = Project.GetCurrentTool(SelectedLayers);
|
||||||
|
if (currentTool.NeedsFullRefresh)
|
||||||
|
{
|
||||||
|
canvas.Image = Project.ForcePaintLayers();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
canvas.Image = Project.PaintLayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
lblSelectedColor.Text = ColorToString(Project.GetCurrentToolColor(SelectedLayers));
|
lblSelectedColor.Text = ColorToString(Project.GetCurrentToolColor(SelectedLayers));
|
||||||
btnSelectedColor.BackColor = Project.GetCurrentToolColor(SelectedLayers);
|
btnSelectedColor.BackColor = Project.GetCurrentToolColor(SelectedLayers);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace Paint_2
|
|||||||
Color Color { get; set; }
|
Color Color { get; set; }
|
||||||
List<int> Widths { get; set; }
|
List<int> Widths { get; set; }
|
||||||
List<int> WidthsRedo { get; set; }
|
List<int> WidthsRedo { get; set; }
|
||||||
|
bool NeedsFullRefresh { get; set; }
|
||||||
int Width { get; set; }
|
int Width { get; set; }
|
||||||
string Name { get; set; }
|
string Name { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Project.cs" />
|
<Compile Include="Project.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="RectanglePencil.cs" />
|
||||||
<Compile Include="Sketch.cs" />
|
<Compile Include="Sketch.cs" />
|
||||||
<EmbeddedResource Include="ColorPicker.resx">
|
<EmbeddedResource Include="ColorPicker.resx">
|
||||||
<DependentUpon>ColorPicker.cs</DependentUpon>
|
<DependentUpon>ColorPicker.cs</DependentUpon>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace Paint_2
|
|||||||
private List<List<Point>> _drawings;
|
private List<List<Point>> _drawings;
|
||||||
private List<List<Point>> _drawingsRedo;
|
private List<List<Point>> _drawingsRedo;
|
||||||
private PaintToolUtils Utils;
|
private PaintToolUtils Utils;
|
||||||
|
private bool _needsFullRefresh;
|
||||||
private List<Color> _colors;
|
private List<Color> _colors;
|
||||||
private List<Color> _colorsRedo;
|
private List<Color> _colorsRedo;
|
||||||
private List<int> _widths;
|
private List<int> _widths;
|
||||||
@@ -37,6 +38,7 @@ namespace Paint_2
|
|||||||
public Color Color { get => _color; set => _color = value; }
|
public Color Color { get => _color; set => _color = value; }
|
||||||
public string Name { get => _name; set => _name = value; }
|
public string Name { get => _name; set => _name = value; }
|
||||||
public int Width { get => _width; set => _width = value; }
|
public int Width { get => _width; set => _width = value; }
|
||||||
|
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||||
|
|
||||||
public Pencil(string name)
|
public Pencil(string name)
|
||||||
{
|
{
|
||||||
@@ -48,6 +50,7 @@ namespace Paint_2
|
|||||||
WidthsRedo = new List<int>();
|
WidthsRedo = new List<int>();
|
||||||
Name = name;
|
Name = name;
|
||||||
Utils = new PaintToolUtils(this);
|
Utils = new PaintToolUtils(this);
|
||||||
|
NeedsFullRefresh = false;
|
||||||
}
|
}
|
||||||
public void Add(Point point)
|
public void Add(Point point)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ namespace Paint_2
|
|||||||
AvaibleTools.Add(new Pencil("Default Pencil"));
|
AvaibleTools.Add(new Pencil("Default Pencil"));
|
||||||
AvaibleTools.Add(new DotPencil("Dotted Line"));
|
AvaibleTools.Add(new DotPencil("Dotted Line"));
|
||||||
AvaibleTools.Add(new BezierPencil("Bezier Generator"));
|
AvaibleTools.Add(new BezierPencil("Bezier Generator"));
|
||||||
|
AvaibleTools.Add(new RectanglePencil("Rectangle tool"));
|
||||||
//We create a single first layer with the default toolSet
|
//We create a single first layer with the default toolSet
|
||||||
|
|
||||||
Layers = new List<Sketch>();
|
Layers = new List<Sketch>();
|
||||||
|
|||||||
148
Paint_2/RectanglePencil.cs
Normal file
148
Paint_2/RectanglePencil.cs
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace Paint_2
|
||||||
|
{
|
||||||
|
internal class RectanglePencil:PaintTool
|
||||||
|
{
|
||||||
|
private List<List<Point>> _drawings;
|
||||||
|
private List<List<Point>> _drawingsRedo;
|
||||||
|
private bool _needsFullRefresh;
|
||||||
|
private PaintToolUtils Utils;
|
||||||
|
private List<Color> _colors;
|
||||||
|
private List<Color> _colorsRedo;
|
||||||
|
private List<int> _widths;
|
||||||
|
private List<int> _widthsRedo;
|
||||||
|
private Color _color;
|
||||||
|
private string _name;
|
||||||
|
private int _width;
|
||||||
|
|
||||||
|
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||||
|
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||||
|
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||||
|
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||||
|
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||||
|
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||||
|
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||||
|
public Color Color { get => _color; set => _color = value; }
|
||||||
|
public string Name { get => _name; set => _name = value; }
|
||||||
|
public int Width { get => _width; set => _width = value; }
|
||||||
|
|
||||||
|
public RectanglePencil(string name)
|
||||||
|
{
|
||||||
|
NeedsFullRefresh = true;
|
||||||
|
Drawings = new List<List<Point>>();
|
||||||
|
DrawingsRedo = new List<List<Point>>();
|
||||||
|
Colors = new List<Color>();
|
||||||
|
ColorsRedo = new List<Color>();
|
||||||
|
Widths = new List<int>();
|
||||||
|
WidthsRedo = new List<int>();
|
||||||
|
Name = name;
|
||||||
|
Utils = new PaintToolUtils(this);
|
||||||
|
}
|
||||||
|
public void Add(Point point)
|
||||||
|
{
|
||||||
|
List<Point> myDrawing = Drawings[Drawings.Count - 1];
|
||||||
|
if (myDrawing.Count == 0 || myDrawing.Count == 1)
|
||||||
|
{
|
||||||
|
myDrawing.Add(point);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myDrawing[1] = point;
|
||||||
|
}
|
||||||
|
Drawings[Drawings.Count - 1] = myDrawing;
|
||||||
|
}
|
||||||
|
public void Paint(Bitmap canvas)
|
||||||
|
{
|
||||||
|
Graphics gr = Graphics.FromImage(canvas);
|
||||||
|
int drawingCounter = 0;
|
||||||
|
Size pointSize;
|
||||||
|
|
||||||
|
foreach (List<Point> drawing in Drawings)
|
||||||
|
{
|
||||||
|
if (drawing.Count == 2)
|
||||||
|
{
|
||||||
|
Point p1 = drawing[0];
|
||||||
|
Point p2 = drawing[1];
|
||||||
|
|
||||||
|
Point start = new Point(0,0);
|
||||||
|
Point end = new Point(0,0);
|
||||||
|
|
||||||
|
if (p2.X > p1.X)
|
||||||
|
{
|
||||||
|
start.X = p1.X;
|
||||||
|
end.X = p2.X;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start.X = p2.X;
|
||||||
|
end.X = p1.X;
|
||||||
|
}
|
||||||
|
if (p2.Y > p1.Y)
|
||||||
|
{
|
||||||
|
start.Y = p1.Y;
|
||||||
|
end.Y = p2.Y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start.Y = p2.Y;
|
||||||
|
end.Y = p1.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
gr.FillRectangle(new SolidBrush(Colors[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
|
||||||
|
}
|
||||||
|
drawingCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Start(Color color, int width)
|
||||||
|
{
|
||||||
|
Utils.StandartStart(color, width);
|
||||||
|
}
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
Utils.StandartClear();
|
||||||
|
}
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Drawings.Count; i++)
|
||||||
|
{
|
||||||
|
List<Point> Drawing = Drawings[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Bitmap PostProcessing(List<Point> Drawing, Bitmap bmp, int width, Color color)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
public List<Color> GetLastColors(int colorNumber)
|
||||||
|
{
|
||||||
|
return Utils.SandartGetLastColors(colorNumber);
|
||||||
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Undo()
|
||||||
|
{
|
||||||
|
Utils.StandartUndo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Redo()
|
||||||
|
{
|
||||||
|
Utils.StandartRedo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
RectanglePencil result = new RectanglePencil(Name);
|
||||||
|
result.Width = Width;
|
||||||
|
result.Color = Color;
|
||||||
|
return (Object)(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user