Formatted code with visual studio

This commit is contained in:
2022-05-31 14:19:33 +02:00
parent 730c09d94e
commit a10da16f12
4 changed files with 31 additions and 30 deletions

View File

@@ -53,7 +53,7 @@ namespace Paint_2
} }
else else
{ {
sketch.StartDrawing(MousePositionToCanvasPosition(),sketch.CurrentTool.Color, (int)nupPencilWidth.Value); sketch.StartDrawing(MousePositionToCanvasPosition(), sketch.CurrentTool.Color, (int)nupPencilWidth.Value);
} }
} }
private void canvas_MouseUp(object sender, MouseEventArgs e) private void canvas_MouseUp(object sender, MouseEventArgs e)
@@ -89,7 +89,7 @@ namespace Paint_2
private void ForceRefresh() private void ForceRefresh()
{ {
canvas.Image = sketch.ForcePaint(); canvas.Image = sketch.ForcePaint();
//RefreshUi(); RefreshUi();
} }
private void RefreshUi() private void RefreshUi()
{ {
@@ -108,8 +108,8 @@ namespace Paint_2
lsbTools.DataSource = toolList; lsbTools.DataSource = toolList;
lblWidth.Text = "Width: "+canvas.Width.ToString(); lblWidth.Text = "Width: " + canvas.Width.ToString();
lblHeight.Text = "Height: "+canvas.Height.ToString(); lblHeight.Text = "Height: " + canvas.Height.ToString();
if (randomColor) if (randomColor)
{ {
@@ -154,7 +154,7 @@ namespace Paint_2
value = value.Replace("#", String.Empty); value = value.Replace("#", String.Empty);
int R, G, B; int R, G, B;
try try
{ {
R = Convert.ToInt32(String.Concat(value[0], value[1]), fromBase); R = Convert.ToInt32(String.Concat(value[0], value[1]), fromBase);
G = Convert.ToInt32(String.Concat(value[2], value[3]), fromBase); G = Convert.ToInt32(String.Concat(value[2], value[3]), fromBase);
B = Convert.ToInt32(String.Concat(value[4], value[4]), fromBase); B = Convert.ToInt32(String.Concat(value[4], value[4]), fromBase);
@@ -237,7 +237,7 @@ namespace Paint_2
private void PaintForm_Resize(object sender, EventArgs e) private void PaintForm_Resize(object sender, EventArgs e)
{ {
canvas.Size = new Size(this.Width - (this.Width - panelTools.Location.X) - canvas.Location.X - WINDOW_OFFSET, this.Height-(this.Height-panelHoverColor.Location.Y) - WINDOW_OFFSET - (panelFile.Location.Y + panelFile.Height)); canvas.Size = new Size(this.Width - (this.Width - panelTools.Location.X) - canvas.Location.X - WINDOW_OFFSET, this.Height - (this.Height - panelHoverColor.Location.Y) - WINDOW_OFFSET - (panelFile.Location.Y + panelFile.Height));
sketch.Resize(canvas.Size); sketch.Resize(canvas.Size);
RefreshUi(); RefreshUi();
} }

View File

@@ -24,13 +24,13 @@ namespace Paint_2
int Width { get; set; } int Width { get; set; }
string Name { get; set; } string Name { get; set; }
void Start(Color color,int width); void Start(Color color, int width);
void Stop(Point point); void Stop(Point point);
void Add(Point point); void Add(Point point);
void Undo(); void Undo();
void Redo(); void Redo();
void Clear(); void Clear();
List<Color> GetLastColors(int colorNumber); List<Color> GetLastColors(int colorNumber);
void Paint(Bitmap canvas); void Paint(Bitmap canvas);
string ToString(); string ToString();
} }

View File

@@ -46,9 +46,9 @@ namespace Paint_2
} }
public void Add(Point point) public void Add(Point point)
{ {
Drawings[Drawings.Count -1].Add(point); Drawings[Drawings.Count - 1].Add(point);
} }
public void Paint(Bitmap canvas) public void Paint(Bitmap canvas)
{ {
Graphics gr = Graphics.FromImage(canvas); Graphics gr = Graphics.FromImage(canvas);
int drawingCounter = 0; int drawingCounter = 0;
@@ -62,8 +62,8 @@ namespace Paint_2
if (pointCounter > 0) if (pointCounter > 0)
{ {
pointSize = new Size(Widths[drawingCounter], Widths[drawingCounter]); 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)); gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(new Point(p.X - pointSize.Width / 2, p.Y - pointSize.Height / 2), pointSize));
gr.DrawLine(new Pen(Colors[drawingCounter],Widths[drawingCounter]),drawing[pointCounter -1],p); gr.DrawLine(new Pen(Colors[drawingCounter], Widths[drawingCounter]), drawing[pointCounter - 1], p);
} }
pointCounter += 1; pointCounter += 1;
@@ -98,9 +98,9 @@ namespace Paint_2
{ {
result.Add(Colors[(Colors.Count) - i]); result.Add(Colors[(Colors.Count) - i]);
} }
for (int i = colorNumber - Colors.Count;i > 0; i--) for (int i = colorNumber - Colors.Count; i > 0; i--)
{ {
result.Add(Color.FromArgb(0x00,0x00,0x00)); result.Add(Color.FromArgb(0x00, 0x00, 0x00));
} }
} }
else else
@@ -123,11 +123,11 @@ namespace Paint_2
if (Drawings.Count > 1) if (Drawings.Count > 1)
{ {
DrawingsRedo.Add(Drawings[last]); DrawingsRedo.Add(Drawings[last]);
Drawings.RemoveAt(Drawings.Count -1); Drawings.RemoveAt(Drawings.Count - 1);
ColorsRedo.Add(Colors[last]); ColorsRedo.Add(Colors[last]);
Colors.RemoveAt(Colors.Count -1); Colors.RemoveAt(Colors.Count - 1);
WidthsRedo.Add(Widths[last]); WidthsRedo.Add(Widths[last]);
Widths.RemoveAt(Widths.Count -1); Widths.RemoveAt(Widths.Count - 1);
} }
else else
{ {
@@ -144,11 +144,11 @@ namespace Paint_2
{ {
if (DrawingsRedo.Count > 0 && WidthsRedo.Count > 0 && ColorsRedo.Count > 0) if (DrawingsRedo.Count > 0 && WidthsRedo.Count > 0 && ColorsRedo.Count > 0)
{ {
Drawings.Add(DrawingsRedo[DrawingsRedo.Count -1]); Drawings.Add(DrawingsRedo[DrawingsRedo.Count - 1]);
DrawingsRedo.RemoveAt(DrawingsRedo.Count - 1); DrawingsRedo.RemoveAt(DrawingsRedo.Count - 1);
Colors.Add(ColorsRedo[ColorsRedo.Count -1]); Colors.Add(ColorsRedo[ColorsRedo.Count - 1]);
ColorsRedo.RemoveAt(ColorsRedo.Count - 1); ColorsRedo.RemoveAt(ColorsRedo.Count - 1);
Widths.Add(WidthsRedo[WidthsRedo.Count -1]); Widths.Add(WidthsRedo[WidthsRedo.Count - 1]);
WidthsRedo.RemoveAt(WidthsRedo.Count - 1); WidthsRedo.RemoveAt(WidthsRedo.Count - 1);
} }
} }

View File

@@ -28,7 +28,7 @@ namespace Paint_2
public Size SketchSize { get => _sketchSize; set => _sketchSize = value; } public Size SketchSize { get => _sketchSize; set => _sketchSize = value; }
public string Name { get => _name; set => _name = value; } public string Name { get => _name; set => _name = value; }
public Sketch(Size sketchSize,List<PaintTool> toolList) public Sketch(Size sketchSize, List<PaintTool> toolList)
{ {
IsDrawing = false; IsDrawing = false;
SketchSize = sketchSize; SketchSize = sketchSize;
@@ -43,7 +43,7 @@ namespace Paint_2
CurrentTool = null; CurrentTool = null;
} }
} }
public Sketch(List<PaintTool> toolList) : this(new Size(500, 500),toolList) public Sketch(List<PaintTool> toolList) : this(new Size(500, 500), toolList)
{ {
//empty //empty
} }
@@ -60,7 +60,8 @@ namespace Paint_2
try try
{ {
CurrentTool = ToolList[toolId]; CurrentTool = ToolList[toolId];
}catch (Exception ex) }
catch (Exception ex)
{ {
Console.WriteLine("Oooops..."); Console.WriteLine("Oooops...");
} }
@@ -73,18 +74,18 @@ namespace Paint_2
{ {
CurrentTool.Redo(); CurrentTool.Redo();
} }
public void StartDrawing(Point location,Color color,int width) public void StartDrawing(Point location, Color color, int width)
{ {
CurrentTool.Start(color,width); CurrentTool.Start(color, width);
CurrentTool.Add(location); CurrentTool.Add(location);
} }
public void ChangePaintToolColor(Color color) public void ChangePaintToolColor(Color color)
{ {
CurrentTool.Start(color,CurrentTool.Width); CurrentTool.Start(color, CurrentTool.Width);
} }
public void ChangePaintToolWidth(int width) public void ChangePaintToolWidth(int width)
{ {
CurrentTool.Start(CurrentTool.Color,width); CurrentTool.Start(CurrentTool.Color, width);
} }
public void StopDrawing(Point location) public void StopDrawing(Point location)
{ {
@@ -101,14 +102,14 @@ namespace Paint_2
tool.Clear(); tool.Clear();
} }
} }
public Bitmap Paint() public Bitmap Paint()
{ {
CurrentTool.Paint(Drawing); CurrentTool.Paint(Drawing);
return Drawing; return Drawing;
} }
public Bitmap ForcePaint() public Bitmap ForcePaint()
{ {
Drawing = new Bitmap(SketchSize.Width,SketchSize.Height); Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
foreach (PaintTool tool in ToolList) foreach (PaintTool tool in ToolList)
{ {
tool.Paint(Drawing); tool.Paint(Drawing);
@@ -118,7 +119,7 @@ namespace Paint_2
public Color GetColor(Point location) public Color GetColor(Point location)
{ {
//Todo //Todo
return Color.FromArgb(0x34,0xF4,0xFF); return Color.FromArgb(0x34, 0xF4, 0xFF);
} }
} }
} }