Private
Public Access
Removed pen specific behavior
This commit is contained in:
1 parent
8acf87b001
commit
456aec28b7
2 files changed
+28
-46
No files matched your search
@@ -130,7 +130,6 @@ namespace Advanced_Software_Engineering
|
|||||||
protected Drawer drawer;
|
protected Drawer drawer;
|
||||||
protected Point[] vertices;
|
protected Point[] vertices;
|
||||||
private List<Verb> lineVerbs;
|
private List<Verb> lineVerbs;
|
||||||
private bool finishDown;
|
|
||||||
|
|
||||||
|
|
||||||
Shape(Drawer drawer, Point[] vertices)
|
Shape(Drawer drawer, Point[] vertices)
|
||||||
@@ -146,17 +145,7 @@ namespace Advanced_Software_Engineering
|
|||||||
throw new Exception("Cannot create shape with only two verticies. Are you thinking of 'drawto'/'moveto'/'line'?");
|
throw new Exception("Cannot create shape with only two verticies. Are you thinking of 'drawto'/'moveto'/'line'?");
|
||||||
}
|
}
|
||||||
|
|
||||||
finishDown = drawer.IsPenDown();
|
//TODO
|
||||||
|
|
||||||
//Move pen to every vertex.
|
|
||||||
//Using MoveTo rather than LineTo because LineTo would be slower if done multiple times (pen up pen down over and over if the pen wasn't down initially)
|
|
||||||
for (int i = 1; i < vertices.Length; i++)
|
|
||||||
{
|
|
||||||
lineVerbs.Add(new DrawTo(drawer, vertices[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Join first and last line
|
|
||||||
lineVerbs.Add(new DrawTo(drawer, vertices[0]));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,23 +174,6 @@ namespace Advanced_Software_Engineering
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PenControl : Verb
|
|
||||||
{
|
|
||||||
bool penStatus;
|
|
||||||
Drawer drawer;
|
|
||||||
|
|
||||||
public PenControl(Drawer drawer, bool down)
|
|
||||||
{
|
|
||||||
penStatus = down;
|
|
||||||
this.drawer = drawer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ExecuteVerb()
|
|
||||||
{
|
|
||||||
drawer.SetPen(penStatus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Value
|
abstract class Value
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Remoting.Messaging;
|
using System.Runtime.Remoting.Messaging;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -16,9 +17,9 @@ namespace Advanced_Software_Engineering
|
|||||||
List<Verb> commands = new List<Verb>();
|
List<Verb> commands = new List<Verb>();
|
||||||
Drawer drawer;
|
Drawer drawer;
|
||||||
|
|
||||||
public void DrawAllCommands()
|
public void DrawAllCommands()
|
||||||
{
|
{
|
||||||
foreach(Verb verb in this.commands)
|
foreach (Verb verb in this.commands)
|
||||||
{
|
{
|
||||||
verb.ExecuteVerb();
|
verb.ExecuteVerb();
|
||||||
}
|
}
|
||||||
@@ -50,7 +51,7 @@ namespace Advanced_Software_Engineering
|
|||||||
//isolate commands
|
//isolate commands
|
||||||
string[] commands = rawCommands.Split(Environment.NewLine.ToCharArray());
|
string[] commands = rawCommands.Split(Environment.NewLine.ToCharArray());
|
||||||
|
|
||||||
foreach(string rawCommand in commands)
|
foreach (string rawCommand in commands)
|
||||||
{
|
{
|
||||||
//handle errors later
|
//handle errors later
|
||||||
AddCommand(VerbFactory.MakeVerb(drawer, rawCommand));
|
AddCommand(VerbFactory.MakeVerb(drawer, rawCommand));
|
||||||
@@ -62,7 +63,7 @@ namespace Advanced_Software_Engineering
|
|||||||
int start = commands.Count;
|
int start = commands.Count;
|
||||||
ProcessCommands(rawCommands);
|
ProcessCommands(rawCommands);
|
||||||
|
|
||||||
for(; start < commands.Count; start++)
|
for (; start < commands.Count; start++)
|
||||||
{
|
{
|
||||||
commands[start].ExecuteVerb();
|
commands[start].ExecuteVerb();
|
||||||
}
|
}
|
||||||
@@ -72,31 +73,35 @@ namespace Advanced_Software_Engineering
|
|||||||
|
|
||||||
class Drawer
|
class Drawer
|
||||||
{
|
{
|
||||||
protected static Color defaultPenColor = Color.Black;
|
protected static Color defaultColor = Color.Black;
|
||||||
protected static float defaultPenWidth = 1f;
|
protected static float defaultWidth = 1f;
|
||||||
|
protected bool fill = false;
|
||||||
|
protected Color fillColor = Color.Black;
|
||||||
|
|
||||||
Pen pen = new Pen(defaultPenColor, defaultPenWidth);
|
|
||||||
bool penDown = true;
|
protected Brush brush;
|
||||||
|
protected Pen pen;
|
||||||
Point penPosition;
|
|
||||||
Graphics graphics;
|
|
||||||
|
protected Point penPosition;
|
||||||
|
protected Graphics graphics;
|
||||||
|
|
||||||
public Drawer(Graphics graphics)
|
public Drawer(Graphics graphics)
|
||||||
{
|
{
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
pen = new Pen(defaultColor, defaultWidth);
|
||||||
|
brush = new SolidBrush(defaultColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MovePen(Point point)
|
public void MovePen(Point point)
|
||||||
{
|
{
|
||||||
if(penDown) graphics.DrawLine(pen, penPosition, point);
|
|
||||||
|
|
||||||
this.penPosition = point;
|
this.penPosition = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPenDown() => penDown;
|
public bool GetFill() => fill;
|
||||||
public void PenUp() => penDown = false;
|
public void EnableFill() => fill = false;
|
||||||
public void PenDown() => penDown = true;
|
public void DisableFill() => fill = true;
|
||||||
public void SetPen(bool down) => penDown = down;
|
public void SetFill(bool down) => fill = down;
|
||||||
|
|
||||||
public void DrawLine(Point point)
|
public void DrawLine(Point point)
|
||||||
{
|
{
|
||||||
@@ -104,6 +109,11 @@ namespace Advanced_Software_Engineering
|
|||||||
penPosition = point;
|
penPosition = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DrawPoints(GraphicsPath path)
|
||||||
|
{
|
||||||
|
graphics.FillPath(brush, path);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user