-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.cs
More file actions
128 lines (108 loc) · 4.26 KB
/
GUI.cs
File metadata and controls
128 lines (108 loc) · 4.26 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
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CellularAutomaton
{
public partial class Gui : Form
{
public Gui()
{
InitializeComponent();
cellTypeComboBox.ComboBox.DataSource = cellularAutomaton.GetStates();
ruleComboBox.ComboBox.DataSource = cellularAutomaton.GetRules();
ruleComboBox.ComboBox.SelectedIndex = 0;
cellTypeComboBox.ComboBox.SelectedIndex = 1;
cellsCountTextBox.Text = cellularAutomaton.CellsCount.ToString();
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
cellularAutomaton.DefaultState = cellTypeComboBox.ComboBox.SelectedIndex;
}
private void randomizeStatesButton_Click(object sender, EventArgs e)
{
cellularAutomaton.RandomizeStates();
cellularAutomaton.Refresh();
}
private void startButton_Click(object sender, EventArgs e)
{
statusBar.Text = " Evolution";
if (epochCountTextBox.Text == "")
{
cellularAutomaton.Evolution(); //MessageBox.Show("Musisz wpisać liczbę epok");
//statusBar.Text = "Błąd";
}
else
{
progressBar.Maximum = int.Parse(epochCountTextBox.Text);
startButton.Checked = true;
evolutionTask = new Task(EvolutionLoop);
evolutionTask.RunSynchronously();
}
startButton.Checked = false;
}
private void stopButton_Click(object sender, EventArgs e)
{
evolutionTask.Wait();
statusBar.Text = "Stopped";
}
private void EvolutionLoop()
{
statusBar.Text = "Evolution";
statusBar.Invalidate();
for (var i = 0; i < int.Parse(epochCountTextBox.Text); i++)
{
cellularAutomaton.Evolution();
progressBar.Value = i + 1;
Thread.Sleep(0);
Thread.Sleep(100);
}
statusBar.Text = "Ready";
}
private void ruleComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
cellularAutomaton.Rule = (Rules) ruleComboBox.SelectedIndex;
cellularAutomaton.Refresh();
/* switch ((Rules)ruleComboBox.SelectedIndex)
{
case Rules.TrokaAutomaton:
ruleComboBox.ComboBox.DataSource = cellularAutomaton.getRules();
typKomorkiComboBox.ComboBox.SelectedIndex=0;
break;
case Rules.GameOfLife:
//ruleComboBox.MaxDropDownItems = 2;
List<Rules> tab = cellularAutomaton.getRules();
for (int i = 2; i < tab.Count; i++)
tab.RemoveAt(i);
ruleComboBox.ComboBox.DataSource = tab;
ruleComboBox.ComboBox.SelectedIndex = 1;
typKomorkiComboBox.ComboBox.SelectedIndex = 0;
break;
case Rules.Darwinia:
ruleComboBox.ComboBox.DataSource = cellularAutomaton.getRules();
typKomorkiComboBox.ComboBox.SelectedIndex=0;
break;
case Rules.PrzeplywCiepla:
ruleComboBox.ComboBox.DataSource = cellularAutomaton.getRules();
typKomorkiComboBox.ComboBox.SelectedIndex=0;
break;
}*/
}
private void cellsCountTextBox_LostFocus(object sender, EventArgs e)
{
long a;
if (long.TryParse(cellsCountTextBox.Text, out a))
if (a != cellularAutomaton.CellsCount)
cellularAutomaton.CellsCount = a;
cellsCountTextBox.Text = cellularAutomaton.CellsCount.ToString();
}
}
}