The DrawPreview now draws

This commit is contained in:
Lukasz Baldyga committed 2020-10-12 12:49:02 +01:00
1 parent 6380549a9b
commit 0af10a3c9d
3 files changed
+110 -3

No files matched your search

@@ -45,6 +45,7 @@
this.button1.TabIndex = 0;
this.button1.Text = "Submit";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.SubmitCommand);
//
// textBox1
//
@@ -12,6 +12,10 @@ namespace Advanced_Software_Engineering
{
public partial class Draw_Preview : Form
{
Graphics graphics;
Commander commander;
/// <summary>
/// The draw preview window.
/// </summary>
@@ -22,6 +26,8 @@ namespace Advanced_Software_Engineering
{
InitializeComponent();
SettingsAndHelperFunctions.NumberOfWindows++;
graphics = panel1.CreateGraphics();
commander = new Commander(graphics);
}
private void DrawPreview_FormClosed(object sender, FormClosedEventArgs e)
@@ -31,9 +37,16 @@ namespace Advanced_Software_Engineering
private void DrawPreviewPane_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen myBlackPen = new Pen(Color.Black, 5);
commander.DrawAllCommands();
}
private void SubmitCommand(object sender, EventArgs e)
{
commander.ProcessCommands(textBox1.Text);
textBox1.Text = "";
//Makes sure that the panel updates
panel1.Invalidate();
}
}
}
@@ -1,4 +1,6 @@
using System.Security.Policy;
using System;
using System.Collections.Generic;
using System.Security.Policy;
using System.Windows.Forms;
namespace Advanced_Software_Engineering
@@ -26,6 +28,97 @@ namespace Advanced_Software_Engineering
}
}
/// <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;
}
}
}