-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFormMain.cs
More file actions
152 lines (136 loc) · 4.41 KB
/
FormMain.cs
File metadata and controls
152 lines (136 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CodePainterApp
{
public partial class FormMain : Form
{
DrawedPointsTable DrawedPointsTable = null;
Graphics Graphics = null;
CodeManager CodeManager = null;
private void Run()
{
if (rtxtCode.Text != string.Empty)
{
btnRun.Enabled = false;
btnClear.Enabled = false;
btnClearArena.Enabled = false;
this.rtxtCode.Text = this.rtxtCode.Text.ToUpper();
Application.DoEvents();
CodeManager.RunCode(rtxtCode);
btnRun.Enabled = true;
btnClear.Enabled = true;
btnClearArena.Enabled = true;
}
}
private void ClearCode()
{
this.rtxtCode.Clear();
CodeManager = new CodeManager(this.drawer, rtxtLogShower);
}
private void ClearArena()
{
DrawedPointsTable.ClearArena(Graphics);
DrawedPointsTable = new DrawedPointsTable(1200, 1200, 20, 20);
drawer.InitializeDrawer(pnlArena, DrawedPointsTable, 20, 20, 1200, 1200);
drawer.Top = 0;
drawer.Left = 0;
}
private void ShowAvailableComands()
{
FormCommands form = new FormCommands();
form.ShowDialog();
}
private void ShowAbout()
{
FormAbout form = new FormAbout();
form.ShowDialog();
}
public FormMain()
{
InitializeComponent();
}
private void pnlArena_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.FromArgb(250, 40, 40, 40));
for (int i = 0; i <= pnlArena.Width; i += 20)
{
Graphics.DrawLine(p, i, 0, i, this.pnlArena.Height);
}
for (int i = 0; i <= pnlArena.Height; i += 20)
{
Graphics.DrawLine(p, 0, i, this.pnlArena.Width, i);
}
DrawedPointsTable.ReDraw(Graphics);
}
private void FormMain_Load(object sender, EventArgs e)
{
this.Graphics = pnlArena.CreateGraphics();
DrawedPointsTable = new DrawedPointsTable(1200,1200, 20, 20);
drawer.InitializeDrawer(pnlArena, DrawedPointsTable, 20, 20, 1200, 1200);
CodeManager = new CodeManager(this.drawer , this.rtxtLogShower);
}
private void btnRun_Click(object sender, EventArgs e)
{
Run();
}
private void btnClear_Click(object sender, EventArgs e)
{
ClearCode();
}
private void btnClearArena_Click(object sender, EventArgs e)
{
ClearArena();
}
private void mnuAvailableCommands_Click(object sender, EventArgs e)
{
ShowAvailableComands();
}
private void mnuAbout_Click(object sender, EventArgs e)
{
ShowAbout();
}
private void mnuOpenFile_Click(object sender, EventArgs e)
{
if(openDialog.ShowDialog() == DialogResult.OK )
{
string fileText = null;
try
{
fileText = File.ReadAllText(openDialog.FileName);
ClearArena();
ClearCode();
rtxtCode.Text = fileText;
}
catch(Exception ex)
{
rtxtLogShower.Text = ex.Message.ToString();
}
}
}
private void mnuSaveFile_Click(object sender, EventArgs e)
{
if (rtxtCode.Text != string.Empty)
{
if (saveDialog.ShowDialog() == DialogResult.OK)
{
try
{
File.AppendAllText(saveDialog.FileName, rtxtCode.Text);
}
catch (Exception ex)
{
rtxtLogShower.Text = ex.Message.ToString();
}
}
}
}
}
}