From c31653ef01c348f9ab318442a22280ef399e173c Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Sun, 25 Oct 2020 05:40:36 +0000 Subject: [PATCH] Refactored Drawer into its own file --- .../Advanced Software Engineering.csproj | 1 + .../Commander.cs | 74 ---------------- .../Advanced Software Engineering/Drawer.cs | 87 +++++++++++++++++++ 3 files changed, 88 insertions(+), 74 deletions(-) create mode 100644 Advanced Software Engineering/Advanced Software Engineering/Drawer.cs diff --git a/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj b/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj index bdc73e7..0dddb34 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj +++ b/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj @@ -74,6 +74,7 @@ + Form diff --git a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs index 6efa3d0..5da43a3 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs @@ -105,78 +105,4 @@ namespace Advanced_Software_Engineering { } - public class Drawer { - protected static Color defaultColor = Color.Black; - protected static float defaultWidth = 1f; - protected bool fill = false; - - - protected Brush brush; - protected Pen pen; - - - protected Point penPosition; - protected Graphics graphics; - - public Drawer(Graphics graphics) { - this.graphics = graphics; - ResetDrawer(); - } - - public void ResetDrawer() { - graphics.Clear(Color.White); - penPosition = new Point(0, 0); - pen = new Pen(defaultColor, defaultWidth); - brush = new SolidBrush(defaultColor); - } - - public void SetGraphics(Graphics graphics) => this.graphics = graphics; - - public void MovePen(Point point) => penPosition = point; - public Point GetPenPosition() => new Point(penPosition.X, penPosition.Y); - - public bool GetFill() => fill; - public void EnableFill() => fill = false; - public void DisableFill() => fill = true; - public void SetFill(bool down) => fill = down; - - public void SetPenColor(Color color) => pen.Color = color; - public void SetPenWidth(float width) => pen.Width = width; - - public void SetFillColor(Color color) => ((SolidBrush)brush).Color = color; - - public void DrawLine(Point point) { - graphics.DrawLine(pen, penPosition, point); - penPosition = point; - } - - public void DrawLines(Point[] points) { - if (points.Length < 2) { - throw new Exception("Cannot have less than two points in a line"); - } - - GraphicsPath path = new GraphicsPath(); - - for (int i = 1; i < points.Length; i++) { - path.AddLine(points[i - 1], points[i]); - } - - path.AddLine(points[0], points.Last()); - - DrawLines(path); - } - - //Doesn't move pen - public void DrawLines(GraphicsPath path) { - //path.Widen(pen); - if (fill) graphics.FillPath(brush, path); - graphics.DrawPath(pen, path); - } - - public void DrawCircle(double scale) { - graphics.DrawEllipse(pen, penPosition.X - (float)(scale), penPosition.Y - (float)(scale), (float)scale*2, (float)scale*2); - } - - } - } diff --git a/Advanced Software Engineering/Advanced Software Engineering/Drawer.cs b/Advanced Software Engineering/Advanced Software Engineering/Drawer.cs new file mode 100644 index 0000000..968be8e --- /dev/null +++ b/Advanced Software Engineering/Advanced Software Engineering/Drawer.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Advanced_Software_Engineering { + public class Drawer { + protected static Color defaultColor = Color.Black; + protected static float defaultWidth = 1f; + protected bool fill = false; + + + protected Brush brush; + protected Pen pen; + + + protected Point penPosition; + protected Graphics graphics; + + public Drawer(Graphics graphics) { + this.graphics = graphics; + ResetDrawer(); + } + + public void ResetDrawer() { + graphics.Clear(Color.White); + penPosition = new Point(0, 0); + pen = new Pen(defaultColor, defaultWidth); + brush = new SolidBrush(defaultColor); + } + + public void SetGraphics(Graphics graphics) => this.graphics = graphics; + + public void MovePen(Point point) => penPosition = point; + public Point GetPenPosition() => new Point(penPosition.X, penPosition.Y); + + public bool GetFill() => fill; + public void EnableFill() => fill = false; + public void DisableFill() => fill = true; + public void SetFill(bool down) => fill = down; + + public void SetPenColor(Color color) => pen.Color = color; + public void SetPenWidth(float width) => pen.Width = width; + + public void SetFillColor(Color color) => ((SolidBrush)brush).Color = color; + + public void DrawLine(Point point) { + graphics.DrawLine(pen, penPosition, point); + penPosition = point; + } + + public void DrawLines(Point[] points) { + if (points.Length < 2) { + throw new Exception("Cannot have less than two points in a line"); + } + + GraphicsPath path = new GraphicsPath(); + + for (int i = 1; i < points.Length; i++) { + path.AddLine(points[i - 1], points[i]); + } + + path.AddLine(points[0], points.Last()); + + DrawLines(path); + } + + //Doesn't move pen + public void DrawLines(GraphicsPath path) { + //path.Widen(pen); + if (fill) graphics.FillPath(brush, path); + graphics.DrawPath(pen, path); + } + + public void DrawCircle(double scale) { + graphics.DrawEllipse(pen, penPosition.X - (float)(scale), penPosition.Y - (float)(scale), (float)scale * 2, (float)scale * 2); + } + + public void ClearCanvas() { + graphics.Clear(Color.White); + } + + } +}