-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLife_OnEvent.cpp
190 lines (160 loc) · 3.16 KB
/
CLife_OnEvent.cpp
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "CLife.h"
void CLife::OnEvent( SDL_Event* Event )
{
CEvent::OnEvent( Event );
}
void CLife::OnKeyDown( SDLKey sym, SDLMod mod, Uint16 unicode )
{
switch ( sym )
{
case SDLK_ESCAPE:
{
OnExit();
break;
}
case SDLK_RIGHT:
{
UnPause();
break;
}
case SDLK_SPACE:
{
UnPause();
StepOnce = true;
break;
}
default:
{
break;
}
}
}
void CLife::OnKeyUp( SDLKey sym, SDLMod mod, Uint16 unicode )
{
switch ( sym )
{
case SDLK_RIGHT:
{
Pause();
break;
}
case SDLK_s:
{
Pause();
Save();
break;
}
case SDLK_RETURN:
{
TogglePause();
break;
}
case SDLK_UP:
case SDLK_PLUS:
case SDLK_KP_PLUS:
case SDLK_PERIOD:
{
Framerate->raiseFPS();
break;
}
case SDLK_DOWN:
case SDLK_MINUS:
case SDLK_KP_MINUS:
case SDLK_COMMA:
{
Framerate->lowerFPS();
break;
}
case SDLK_e:
{
ToggleEditMode();
break;
}
case SDLK_h:
{
//Pause();
TogglePause();
Stabilize();
ToggleStepping();
TogglePause();
break;
}
case SDLK_c:
{
SwitchColours();
break;
}
case SDLK_r:
{
Reset();
break;
}
//Patterns:
case SDLK_0:
case SDLK_KP0:
{
Patternify(0);
break;
}
case SDLK_1:
case SDLK_KP1:
{
Patternify(1);
break;
}
case SDLK_2:
case SDLK_KP2:
{
Patternify(2);
break;
}
case SDLK_3:
case SDLK_KP3:
{
Patternify(3);
break;
}
case SDLK_7:
case SDLK_KP7:
case SDLK_x:
{
Patternify(7);
break;
}
case SDLK_8:
case SDLK_KP8:
{
Patternify(8);
break;
}
case SDLK_9:
case SDLK_KP9:
{
Patternify(9);
break;
}
default:
{
break;
}
}
}
void CLife::OnMouseMove( int mX, int mY, int relX, int relY, bool Left, bool Right, bool Middle )
{
}
void CLife::OnLButtonDown( int mX, int mY )
{
if ( EditMode )
{
int row = ( mY / ( CGraphicCell::CellSize + GraphicGrid->getSpacing() ) );
int col = ( mX / ( CGraphicCell::CellSize + GraphicGrid->getSpacing() ) );
bool cellalive = LifeGrid->getCellAt( row, col )->isAlive();
LifeGrid->setCellAt( row, col, !cellalive );
GraphicGrid->setAt( row, col, static_cast<CGraphicCell::GCellState>( !cellalive ) );
}
}
void CLife::OnExit()
{
Pause();
Running = false;
}