forked from 84634E1A607A/ConwayLifeGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl.cs
175 lines (161 loc) · 7.5 KB
/
Control.cs
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ConwayLifeGame
{
public partial class Control : Form
{
readonly private Bitmap previewBitmap;
readonly Graphics graphics;
readonly private SolidBrush brush;
readonly private SolidBrush rbrush;
private Size size;
public Control()
{
InitializeComponent();
size = PreviewPictureBox.Size;
previewBitmap = new Bitmap(size.Width, size.Height);
brush = new SolidBrush(Color.Black);
rbrush = new SolidBrush(Color.FromArgb(0x80, Color.Red));
graphics = Graphics.FromImage(previewBitmap);
PresetSelect.Maximum = Map.PresetNum;
PreviewPictureBox_Paint();
MouseStateClick.Checked = true;
}
private void PreviewPictureBox_SizeChanged(object sender, EventArgs e)
{
size = PreviewPictureBox.Size;
}
private void PreviewPictureBox_Paint()
{
Map.Preset preset_info = Map.GetBulitinInfo();
graphics.Clear(BackColor);
int scale, xStart, yStart;
if (Map.SelectedDirection <= 4)
{
scale = Math.Min(size.Width / preset_info.width, size.Height / preset_info.height);
xStart = (size.Width - preset_info.width * scale) / 2; yStart = (size.Height - preset_info.height * scale) / 2;
}
else
{
scale = Math.Min(size.Width / preset_info.height, size.Height / preset_info.width);
xStart = (size.Width - preset_info.height * scale) / 2; yStart = (size.Height - preset_info.width * scale) / 2;
}
graphics.TranslateTransform(xStart, yStart);
switch (Map.SelectedDirection)
{
case 1:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * point.X, scale * point.Y, scale, scale));
break;
case 2:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * point.X, scale * (preset_info.height - 1 - point.Y), scale, scale));
break;
case 3:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * (preset_info.width - 1 - point.X), scale * point.Y, scale, scale));
break;
case 4:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * (preset_info.width - 1 - point.X), scale * (preset_info.height - 1 - point.Y), scale, scale));
break;
case 5:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * point.Y, scale * point.X, scale, scale));
break;
case 6:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * point.Y, scale * (preset_info.width - 1 - point.X), scale, scale));
break;
case 7:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * (preset_info.height - 1 - point.Y), scale * point.X, scale, scale));
break;
case 8:
foreach (Point point in preset_info.points)
graphics.FillRectangle(brush, new Rectangle(scale * (preset_info.height - 1 - point.Y), scale * (preset_info.width - 1 - point.X), scale, scale));
break;
}
graphics.FillRectangle(rbrush, new Rectangle((int)(scale * 0.1), (int)(scale * 0.1), (int)(scale * 0.8), (int)(scale * 0.8)));
graphics.ResetTransform();
PreviewPictureBox.Image = previewBitmap;
}
public void StartStop_Click(object sender, EventArgs e)
{
if (Map.MouseInfo.state == Map.MouseState.select && Map.Started == false) return;
Map.Started = !Map.Started;
if (Map.Started)
{
Program.main.ClacTimer.Start();
Program.main.StatusLabel.Text = "Running";
}
else {
Program.main.ClacTimer.Stop();
Program.main.StatusLabel.Text = "Paused";
}
}
private void Control_FormClosing(object sender, FormClosingEventArgs e)
{
SetVisibleCore(false);
e.Cancel = true;
}
public void Reset_Click(object sender, EventArgs e)
{
Program.main.ClacTimer.Stop();
// Value Reset
Map.Reset();
// Control Reset
XPivot.Value = Map.XPivot;
YPivot.Value = Map.YPivot;
PresetSelect.Value = Map.SelectedPreset;
DirectionSelect.Value = Map.SelectedDirection;
Timer.Value = Map.Timer;
MapScale.Value = Map.Scale;
Program.SetMainLabel("Map reset", 1500);
}
private void PresetSelect_ValueChanged(object sender, EventArgs e)
{
Map.SelectedPreset = (int)PresetSelect.Value;
PreviewPictureBox_Paint();
Program.SetMainLabel("Selected preset: " + Map.SelectedPreset, 1000);
}
private void DirectionSelect_ValueChanged(object sender, EventArgs e)
{
Map.SelectedDirection = (int)DirectionSelect.Value;
PreviewPictureBox_Paint();
Program.SetMainLabel("Selected direction: " + Map.SelectedDirection, 1000);
}
private void XPivot_ValueChanged(object sender, EventArgs e)
{
Map.MouseInfo.select_first = Map.MouseInfo.select_second = new Point();
Map.XPivot = (int)XPivot.Value;
}
private void YPivot_ValueChanged(object sender, EventArgs e)
{
Map.MouseInfo.select_first = Map.MouseInfo.select_second = new Point();
Map.YPivot = (int)YPivot.Value;
}
private void MapScale_ValueChanged(object sender, EventArgs e)
{
Map.MouseInfo.select_first = Map.MouseInfo.select_second = new Point();
Map.Scale = (int)MapScale.Value;
}
private void Timer_ValueChanged(object sender, EventArgs e)
{
Map.Timer = (int)Timer.Value;
Program.main.ClacTimer.Interval = Map.Timer;
Program.SetMainLabel("Timer: " + Map.Timer, 500);
}
private void MouseState_CheckedChanged(object sender, EventArgs e)
{
if (MouseStateClick.Checked) Map.MouseInfo.state = Map.MouseState.click;
else if (MouseStatePen.Checked) Map.MouseInfo.state = Map.MouseState.pen;
else if (MouseStateEraser.Checked) Map.MouseInfo.state = Map.MouseState.eraser;
else if (MouseStateDrag.Checked) Map.MouseInfo.state = Map.MouseState.drag;
else if (MouseStateSelect.Checked) { Map.MouseInfo.state = Map.MouseState.select; if (Map.Started) StartStop_Click(null, null); }
if (!MouseStateSelect.Checked) Map.MouseInfo.select_first = Map.MouseInfo.select_second = new Point();
Program.SetMainLabel("Mouse function: " + Map.MouseInfo.state.ToString(), 1000);
}
}
}