Private
Public Access
Draw Preview now draws from Text Editor directly
This commit is contained in:
1 parent
8a63dbae2f
commit
0db4469cf5
5 files changed
+128
-54
No files matched your search
@@ -1,13 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Advanced_Software_Engineering {
|
||||
class VerbFactory {
|
||||
@@ -70,7 +63,7 @@ namespace Advanced_Software_Engineering {
|
||||
|
||||
public interface Verb {
|
||||
void ExecuteVerb();
|
||||
|
||||
string GetDescription();
|
||||
}
|
||||
|
||||
class MoveTo : Verb {
|
||||
@@ -92,15 +85,27 @@ namespace Advanced_Software_Engineering {
|
||||
this.drawer.MovePen(moveToPoint);
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return "Move origin to " + moveToPoint.X + ", " + moveToPoint.Y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DrawTo : MoveTo {
|
||||
public DrawTo(Drawer drawer, int x, int y) : base(drawer, x, y) { }
|
||||
class DrawTo : Verb {
|
||||
protected Drawer drawer;
|
||||
protected Point moveToPoint;
|
||||
|
||||
public DrawTo(Drawer drawer, Point point) : base(drawer, point) { }
|
||||
public DrawTo(Drawer drawer, int x, int y) {
|
||||
this.drawer = drawer;
|
||||
moveToPoint = new Point(x, y);
|
||||
}
|
||||
|
||||
public new void ExecuteVerb() {
|
||||
this.drawer.DrawLine(moveToPoint);
|
||||
public void ExecuteVerb() {
|
||||
drawer.DrawLine(moveToPoint);
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return "Draw line " + moveToPoint.X + ", " + moveToPoint.Y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +133,8 @@ namespace Advanced_Software_Engineering {
|
||||
public void ExecuteVerb() {
|
||||
foreach (Verb verb in lineVerbs) verb.ExecuteVerb();
|
||||
}
|
||||
|
||||
public abstract string GetDescription();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -139,11 +146,16 @@ namespace Advanced_Software_Engineering {
|
||||
|
||||
RegularPolygons(Drawer drawer, Point origin, int sides, int scale) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ExecuteVerb() {
|
||||
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Value {
|
||||
|
||||
@@ -3,80 +3,77 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Advanced_Software_Engineering
|
||||
{
|
||||
class Commander
|
||||
{
|
||||
namespace Advanced_Software_Engineering {
|
||||
class Commander {
|
||||
|
||||
Graphics graphics;
|
||||
List<Verb> commands = new List<Verb>();
|
||||
Drawer drawer;
|
||||
|
||||
public void DrawAllCommands()
|
||||
{
|
||||
foreach (Verb verb in this.commands)
|
||||
{
|
||||
public void DrawAllCommands() {
|
||||
foreach (Verb verb in this.commands) {
|
||||
verb.ExecuteVerb();
|
||||
}
|
||||
}
|
||||
|
||||
public Commander(Graphics graphics)
|
||||
{
|
||||
public Commander(Graphics graphics) {
|
||||
this.graphics = graphics;
|
||||
this.drawer = new Drawer(this.graphics);
|
||||
}
|
||||
|
||||
public Commander(Graphics graphics, string rawCommands)
|
||||
{
|
||||
public Commander(Graphics graphics, string rawCommands) {
|
||||
this.graphics = graphics;
|
||||
this.drawer = new Drawer(this.graphics);
|
||||
this.ProcessCommands(rawCommands);
|
||||
}
|
||||
|
||||
public void AddCommand(Verb command)
|
||||
{
|
||||
public void AddCommand(Verb command) {
|
||||
commands.Add(command);
|
||||
}
|
||||
|
||||
public void ProcessCommands(string rawCommands)
|
||||
{
|
||||
public void ProcessCommands(string rawCommands) {
|
||||
//ignore case
|
||||
rawCommands = rawCommands.ToLower();
|
||||
Console.WriteLine("Processing:\n" + rawCommands);
|
||||
|
||||
//isolate commands
|
||||
string[] commands = rawCommands.Split(Environment.NewLine.ToCharArray());
|
||||
|
||||
foreach (string rawCommand in commands)
|
||||
{
|
||||
//handle errors later
|
||||
Console.WriteLine("\nThe rawCommand processed:");
|
||||
foreach (string rawCommand in commands) {
|
||||
if (rawCommand == "") continue;
|
||||
AddCommand(VerbFactory.MakeVerb(drawer, rawCommand));
|
||||
Console.WriteLine(rawCommand);
|
||||
}
|
||||
|
||||
Console.WriteLine("\n\nHere is what the program is going to do:");
|
||||
Console.WriteLine("Set origin to 0, 0");
|
||||
foreach(Verb verb in this.commands) {
|
||||
Console.WriteLine(verb.GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
public void ProcessCommandsAndExecute(string rawCommands)
|
||||
{
|
||||
public void ProcessCommandsAndExecute(string rawCommands) {
|
||||
int start = commands.Count;
|
||||
ProcessCommands(rawCommands);
|
||||
|
||||
for (; start < commands.Count; start++)
|
||||
{
|
||||
for (; start < commands.Count; start++) {
|
||||
commands[start].ExecuteVerb();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAllCommands() {
|
||||
commands = new List<Verb>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Drawer
|
||||
{
|
||||
class Drawer {
|
||||
protected static Color defaultColor = Color.Black;
|
||||
protected static float defaultWidth = 1f;
|
||||
protected bool fill = false;
|
||||
protected Color fillColor = Color.Black;
|
||||
|
||||
|
||||
protected Brush brush;
|
||||
@@ -86,15 +83,13 @@ namespace Advanced_Software_Engineering
|
||||
protected Point penPosition;
|
||||
protected Graphics graphics;
|
||||
|
||||
public Drawer(Graphics graphics)
|
||||
{
|
||||
public Drawer(Graphics graphics) {
|
||||
this.graphics = graphics;
|
||||
pen = new Pen(defaultColor, defaultWidth);
|
||||
brush = new SolidBrush(defaultColor);
|
||||
}
|
||||
|
||||
public void MovePen(Point point)
|
||||
{
|
||||
public void MovePen(Point point) {
|
||||
this.penPosition = point;
|
||||
}
|
||||
|
||||
@@ -103,15 +98,38 @@ namespace Advanced_Software_Engineering
|
||||
public void DisableFill() => fill = true;
|
||||
public void SetFill(bool down) => fill = down;
|
||||
|
||||
public void DrawLine(Point point)
|
||||
{
|
||||
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 DrawPoints(GraphicsPath path)
|
||||
{
|
||||
graphics.FillPath(brush, path);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,10 +30,21 @@ namespace Advanced_Software_Engineering
|
||||
commander = new Commander(graphics);
|
||||
}
|
||||
|
||||
public Draw_Preview(String commands) {
|
||||
InitializeComponent();
|
||||
SettingsAndHelperFunctions.NumberOfWindows++;
|
||||
graphics = panel1.CreateGraphics();
|
||||
commander = new Commander(graphics, commands);
|
||||
|
||||
//disable components
|
||||
textBox1.Enabled = false;
|
||||
button1.Enabled = false;
|
||||
}
|
||||
|
||||
private void DrawPreview_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
SettingsAndHelperFunctions.WindowClosed();
|
||||
this.Dispose();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private void DrawPreviewPane_Paint(object sender, PaintEventArgs e)
|
||||
@@ -46,5 +57,13 @@ namespace Advanced_Software_Engineering
|
||||
commander.ProcessCommandsAndExecute(textBox1.Text);
|
||||
textBox1.Text = "";
|
||||
}
|
||||
|
||||
public void SubmitCommands(string comamnds) {
|
||||
commander.ProcessCommandsAndExecute(comamnds);
|
||||
}
|
||||
|
||||
public void RemoveAllCommands() {
|
||||
commander.RemoveAllCommands();
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -109,12 +109,14 @@ namespace Advanced_Software_Engineering
|
||||
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.exitToolStripMenuItem.Text = "Exit";
|
||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||
//
|
||||
// runToolStripMenuItem
|
||||
//
|
||||
this.runToolStripMenuItem.Name = "runToolStripMenuItem";
|
||||
this.runToolStripMenuItem.Size = new System.Drawing.Size(40, 20);
|
||||
this.runToolStripMenuItem.Text = "Run";
|
||||
this.runToolStripMenuItem.Click += new System.EventHandler(this.runToolStripMenuItem_Click);
|
||||
//
|
||||
// helpToolStripMenuItem
|
||||
//
|
||||
@@ -128,13 +130,14 @@ namespace Advanced_Software_Engineering
|
||||
// aboutToolStripMenuItem
|
||||
//
|
||||
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
|
||||
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(107, 22);
|
||||
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.aboutToolStripMenuItem.Text = "About";
|
||||
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
|
||||
//
|
||||
// helpToolStripMenuItem1
|
||||
//
|
||||
this.helpToolStripMenuItem1.Name = "helpToolStripMenuItem1";
|
||||
this.helpToolStripMenuItem1.Size = new System.Drawing.Size(107, 22);
|
||||
this.helpToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
|
||||
this.helpToolStripMenuItem1.Text = "Help";
|
||||
//
|
||||
// Text_Editor
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Advanced_Software_Engineering {
|
||||
public partial class Text_Editor : Form {
|
||||
const string DefaultTitleString = "Advanced Software Engineering - Text Editor ";
|
||||
|
||||
Draw_Preview DisplayForm = null;
|
||||
|
||||
/// <summary>
|
||||
/// The text editor is the main window that the user will be using for writing code.
|
||||
/// </summary>
|
||||
@@ -27,5 +29,25 @@ namespace Advanced_Software_Engineering {
|
||||
private void newFileToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
new Text_Editor().Show();
|
||||
}
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
new About_Window().Show();
|
||||
}
|
||||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
Close();
|
||||
}
|
||||
|
||||
private void runToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
if(DisplayForm == null) {
|
||||
DisplayForm = new Draw_Preview(textBox1.Text);
|
||||
} else {
|
||||
Console.WriteLine("Removed all commands");
|
||||
DisplayForm.RemoveAllCommands();
|
||||
DisplayForm.SubmitCommands(textBox1.Text);
|
||||
}
|
||||
DisplayForm.Show();
|
||||
DisplayForm.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user