From 720e9cc5a58e7be8b4529ea9b0a8c7330a5db96e Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Sat, 24 Oct 2020 08:32:25 +0100 Subject: [PATCH] Added more shapes to draw --- .../Advanced Software Engineering/Command.cs | 132 ++++++++++++++---- .../Commander.cs | 5 +- .../TextEditor.cs | 2 +- 3 files changed, 109 insertions(+), 30 deletions(-) diff --git a/Advanced Software Engineering/Advanced Software Engineering/Command.cs b/Advanced Software Engineering/Advanced Software Engineering/Command.cs index 6d7a546..83a1783 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Command.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Command.cs @@ -3,6 +3,9 @@ using System.CodeDom; using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Security.Cryptography; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; namespace Advanced_Software_Engineering { public class VerbFactory { @@ -128,34 +131,6 @@ namespace Advanced_Software_Engineering { } } - abstract class Shape : Verb { - protected Drawer drawer; - protected Point[] vertices; - private List lineVerbs; - - - Shape(Drawer drawer, Point[] vertices) { - //Throw exceptions if impossible to create Spape Verb - switch (vertices.Length) { - case 0: - throw new Exception("Cannot create shape with no vertices."); - case 1: - throw new Exception("Cannot create shape with only one vertex. Are you thinking of 'dot'?"); - case 2: - throw new Exception("Cannot create shape with only two verticies. Are you thinking of 'drawto'/'moveto'/'line'?"); - } - - //TODO - - } - - public void ExecuteVerb() { - foreach (Verb verb in lineVerbs) verb.ExecuteVerb(); - } - - public abstract string GetDescription(); - } - /// /// A class that generates a RegularPolygon verb. /// @@ -200,6 +175,107 @@ namespace Advanced_Software_Engineering { } } + class Square : Verb { + + Verb verb; + + Square(Drawer drawer, double scale) { + verb = new RegularPolygon(drawer, 4, scale); + } + + Square(Drawer drawer, double scale, double offset) { + verb = new RegularPolygon(drawer, 4, scale, offset); + } + + public void ExecuteVerb() => verb.ExecuteVerb(); + + public string GetDescription() => verb.GetDescription(); + } + + class Triangle : Verb { + Verb verb; + + Triangle(Drawer drawer, double scale) { + verb = new RegularPolygon(drawer, 3, scale); + } + + Triangle(Drawer drawer, double scale, double offset) { + verb = new RegularPolygon(drawer, 3, scale, offset); + } + + public void ExecuteVerb() => verb.ExecuteVerb(); + + public string GetDescription() => verb.GetDescription(); + } + + //TODO: correct + class Rectangle : Verb { + Verb verb; + + Drawer drawer; + List points; + bool correctForOrigin; + + Rectangle(Drawer drawer, double width, double height, bool center = true) { + this.drawer = drawer; + correctForOrigin = true; + + PointF[] points = new PointF[] + { + new PointF((float) -width, (float) -height), + new PointF((float) width, (float) -height), + new PointF((float) width, (float) height), + new PointF((float) -width, (float) height) + }; + + this.points = new List(); + foreach (PointF pointF in points) this.points.Add(new Point((int)Math.Round(pointF.X), (int)Math.Round(pointF.Y))); + } + + Rectangle(Drawer drawer, Point point1, Point point2) { + this.drawer = drawer; + + PointF[] points = new PointF[] + { + new PointF((float) point1.X, (float) point1.Y), + new PointF((float) point1.X, (float) point2.Y), + new PointF((float) point2.X, (float) point2.Y), + new PointF((float) point2.X, (float) point1.Y) + }; + + this.points = new List(); + foreach (PointF pointF in points) this.points.Add(new Point((int)Math.Round(pointF.X), (int)Math.Round(pointF.Y))); + + correctForOrigin = false; + + } + + public string GetDescription() { + return ""; + } + + public void ExecuteVerb() => drawer.DrawLines(points.ToArray()); + + } + + class Circle : Verb { + Drawer drawer; + double scale; + + public Circle(Drawer drawer, double scale) { + this.drawer = drawer; + this.scale = scale; + } + + public void ExecuteVerb() { + drawer.DrawCircle(scale); + } + + public string GetDescription() { + return "Draws a circle radius" + scale.ToString() + ", with origin of the pen"; + } + } + abstract class Value { } diff --git a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs index be9f6d6..e0a9e0c 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs @@ -165,7 +165,6 @@ namespace Advanced_Software_Engineering { path.AddLine(points[0], points.Last()); DrawLines(path); - } //Doesn't move pen @@ -175,6 +174,10 @@ namespace Advanced_Software_Engineering { graphics.DrawPath(pen, path); } + public void DrawCircle(double scale) { + graphics.DrawEllipse(pen, penPosition.X, penPosition.Y, (float)scale, (float)scale); + } + } } diff --git a/Advanced Software Engineering/Advanced Software Engineering/TextEditor.cs b/Advanced Software Engineering/Advanced Software Engineering/TextEditor.cs index 1403e6b..e56e8d8 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/TextEditor.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/TextEditor.cs @@ -230,7 +230,7 @@ namespace Advanced_Software_Engineering { } else if (e.KeyCode == Keys.F1 && e.Shift) { DescribeCode(); e.Handled = true; - } + } } private void checkSyntaxToolStripMenuItem_Click(object sender, EventArgs e) => CheckCode();