Private
Public Access
The DrawPreview now draws
This commit is contained in:
1 parent
6380549a9b
commit
0af10a3c9d
3 files changed
+111
-4
No files matched your search
+1
@@ -45,6 +45,7 @@
|
|||||||
this.button1.TabIndex = 0;
|
this.button1.TabIndex = 0;
|
||||||
this.button1.Text = "Submit";
|
this.button1.Text = "Submit";
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.SubmitCommand);
|
||||||
//
|
//
|
||||||
// textBox1
|
// textBox1
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ namespace Advanced_Software_Engineering
|
|||||||
{
|
{
|
||||||
public partial class Draw_Preview : Form
|
public partial class Draw_Preview : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Graphics graphics;
|
||||||
|
Commander commander;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The draw preview window.
|
/// The draw preview window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -22,6 +26,8 @@ namespace Advanced_Software_Engineering
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
SettingsAndHelperFunctions.NumberOfWindows++;
|
SettingsAndHelperFunctions.NumberOfWindows++;
|
||||||
|
graphics = panel1.CreateGraphics();
|
||||||
|
commander = new Commander(graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawPreview_FormClosed(object sender, FormClosedEventArgs e)
|
private void DrawPreview_FormClosed(object sender, FormClosedEventArgs e)
|
||||||
@@ -31,9 +37,16 @@ namespace Advanced_Software_Engineering
|
|||||||
|
|
||||||
private void DrawPreviewPane_Paint(object sender, PaintEventArgs e)
|
private void DrawPreviewPane_Paint(object sender, PaintEventArgs e)
|
||||||
{
|
{
|
||||||
Graphics g = e.Graphics;
|
commander.DrawAllCommands();
|
||||||
Pen myBlackPen = new Pen(Color.Black, 5);
|
}
|
||||||
|
|
||||||
|
private void SubmitCommand(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
commander.ProcessCommands(textBox1.Text);
|
||||||
|
textBox1.Text = "";
|
||||||
|
|
||||||
|
//Makes sure that the panel updates
|
||||||
|
panel1.Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+95
-2
@@ -1,4 +1,6 @@
|
|||||||
using System.Security.Policy;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Policy;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering
|
namespace Advanced_Software_Engineering
|
||||||
@@ -24,8 +26,99 @@ namespace Advanced_Software_Engineering
|
|||||||
System.Console.WriteLine("Showing MainMenu");
|
System.Console.WriteLine("Showing MainMenu");
|
||||||
Program.MainMenu.Show();
|
Program.MainMenu.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// This function removes spaces from the start and the end of the text. This should be unit tested.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">Simply any string of any size</param>
|
||||||
|
/// <returns>A string without spaces at the begining or the end</returns>
|
||||||
|
/// <example>
|
||||||
|
/// For example
|
||||||
|
/// <code>
|
||||||
|
/// string a = " a simple sentence surrounded by spaces ";
|
||||||
|
/// string b = StripSpaces(a);
|
||||||
|
/// Console.WriteLine(b); // => "a simple sentence surrounded by spaces";
|
||||||
|
/// </code>
|
||||||
|
/// </example>
|
||||||
|
/// <example>
|
||||||
|
/// The code won't remove internal double spaces:
|
||||||
|
/// <code>
|
||||||
|
/// string a = " a simple sentence surrounded by spaces ";
|
||||||
|
/// string b = StripSpaces(a);
|
||||||
|
/// Console.WriteLine(b); // => "a simple sentence surrounded by spaces";
|
||||||
|
/// </code>
|
||||||
|
/// </example>
|
||||||
|
public static string Strip(string text)
|
||||||
|
{
|
||||||
|
//Console.WriteLine("Stripping: '" + text + "'");
|
||||||
|
int start;
|
||||||
|
|
||||||
|
for (start = 0; start < text.Length; start++)
|
||||||
|
{
|
||||||
|
char character = text[start];
|
||||||
|
if (character != " "[0]) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int end;
|
||||||
|
|
||||||
|
for (end = text.Length - 1; end >= 0; end--)
|
||||||
|
{
|
||||||
|
char character = text[end];
|
||||||
|
if (character != " "[0]) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
string result = text.Substring(start, end - start + 1);
|
||||||
|
|
||||||
|
//Console.WriteLine("Started at: " + start);
|
||||||
|
//Console.WriteLine("Ended at: " + end);
|
||||||
|
//Console.WriteLine("Result: " + result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int ConvertToInt(string text)
|
||||||
|
{
|
||||||
|
text = Strip(text);
|
||||||
|
return int.Parse(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<string> StripStringArray(string[] array)
|
||||||
|
{
|
||||||
|
List<string> newStringList = new List<string>();
|
||||||
|
|
||||||
|
foreach (string arrayElement in array)
|
||||||
|
{
|
||||||
|
string strippedElement = Strip(arrayElement);
|
||||||
|
if (strippedElement.Length == 0) continue;
|
||||||
|
else newStringList.Add(strippedElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newStringList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, string[]> CommandAndParameterParser(string text)
|
||||||
|
{
|
||||||
|
Dictionary<string, string[]> commandAndParameters = new Dictionary<string, string[]>();
|
||||||
|
|
||||||
|
//split the command from the parameters
|
||||||
|
string[] parameters = Strip(text).Split(new char[] { " "[0] }, 2);
|
||||||
|
|
||||||
|
//set command var
|
||||||
|
string command = Strip(parameters[0]);
|
||||||
|
commandAndParameters["command"] = new string[] { command };
|
||||||
|
|
||||||
|
//seperate all of the parameters by a comma
|
||||||
|
parameters = parameters[1].Split(","[0]);
|
||||||
|
|
||||||
|
//Remove spaces around parameters
|
||||||
|
parameters = StripStringArray(parameters).ToArray();
|
||||||
|
|
||||||
|
//set parameter list
|
||||||
|
commandAndParameters["parameters"] = parameters;
|
||||||
|
|
||||||
|
return commandAndParameters;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user