Removed pen specific behavior

This commit is contained in:
Lukasz Baldyga committed 2020-10-13 17:20:29 +01:00
1 parent 8acf87b001
commit 456aec28b7
2 files changed
+23 -41

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;
@@ -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;
Point penPosition; protected Brush brush;
Graphics graphics; protected Pen pen;
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);
}
} }
} }