-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCEvent.cpp
240 lines (172 loc) · 5.2 KB
/
CEvent.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include "CEvent.h"
CEvent::CEvent()
{
}
CEvent::~CEvent()
{
}
void CEvent::OnEvent( SDL_Event* Event )
{
switch ( Event->type )
{
//Gain/lose mouse focus, Minimize/restore window
case SDL_ACTIVEEVENT:
{
switch ( Event->active.state )
{
case SDL_APPMOUSEFOCUS:
{
if ( Event->active.gain )
{
OnMouseFocus();
}
else
{
OnMouseBlur();
}
}
case SDL_APPINPUTFOCUS:
{
if ( Event->active.gain )
{
OnInputFocus();
}
else
{
OnInputBlur();
}
}
case SDL_APPACTIVE:
{
if ( Event->active.gain )
{
OnRestore();
}
else
{
OnMinimize();
}
}
}
break;
}
case SDL_KEYDOWN:
{
OnKeyDown( Event->key.keysym.sym, Event->key.keysym.mod, Event->key.keysym.unicode );
break;
}
case SDL_KEYUP:
{
OnKeyUp( Event->key.keysym.sym, Event->key.keysym.mod, Event->key.keysym.unicode );
break;
}
case SDL_MOUSEMOTION:
{
OnMouseMove( Event->motion.x,
Event->motion.y,
Event->motion.xrel,
Event->motion.yrel,
//bitwise-AND of the event's motion.state to determine which button is pressed
( Event->motion.state & SDL_BUTTON( SDL_BUTTON_LEFT ) ) != 0,
( Event->motion.state & SDL_BUTTON( SDL_BUTTON_RIGHT ) ) != 0,
( Event->motion.state & SDL_BUTTON( SDL_BUTTON_MIDDLE ) ) != 0
);
break;
}
case SDL_MOUSEBUTTONDOWN:
{
switch ( Event->button.button )
{
case SDL_BUTTON_LEFT:
{
OnLButtonDown( Event->button.x, Event->button.y );
break;
}
case SDL_BUTTON_RIGHT:
{
OnRButtonDown( Event->button.x, Event->button.y );
break;
}
case SDL_BUTTON_MIDDLE:
{
OnMButtonDown( Event->button.x, Event->button.y );
break;
}
}
break;
}
case SDL_MOUSEBUTTONUP:
{
switch ( Event->button.button )
{
case SDL_BUTTON_LEFT:
{
OnLButtonUp( Event->button.x, Event->button.y );
break;
}
case SDL_BUTTON_RIGHT:
{
OnRButtonUp( Event->button.x, Event->button.y );
break;
}
case SDL_BUTTON_MIDDLE:
{
OnMButtonUp( Event->button.x, Event->button.y );
break;
}
}
break;
}
case SDL_QUIT:
{
OnExit();
break;
}
//Unhandled window manager event
case SDL_SYSWMEVENT:
{
//Do nothing?
break;
}
//Resize the window
case SDL_VIDEORESIZE:
{
OnResize( Event->resize.w, Event->resize.h );
break;
}
//Screen modified outside of the window manager (redraw)
case SDL_VIDEOEXPOSE:
{
OnExpose();
break;
}
default:
{
OnUser( Event->user.type,
Event->user.code,
Event->user.data1,
Event->user.data2 );
break;
}
}
}
void CEvent::OnInputFocus() {}
void CEvent::OnInputBlur () {}
void CEvent::OnKeyDown ( SDLKey sym, SDLMod mod, Uint16 unicode ) {}
void CEvent::OnKeyUp ( SDLKey sym, SDLMod mod, Uint16 unicode ) {}
void CEvent::OnMouseFocus () {}
void CEvent::OnMouseBlur () {}
void CEvent::OnMouseMove ( int mX, int mY, int relX, int relY, bool Left, bool Right, bool Middle ) {}
void CEvent::OnMouseWheel ( bool Up, bool Down ) {}
void CEvent::OnLButtonDown ( int mX, int mY ) {}
void CEvent::OnLButtonUp ( int mX, int mY ) {}
void CEvent::OnRButtonDown ( int mX, int mY ) {}
void CEvent::OnRButtonUp ( int mX, int mY ) {}
void CEvent::OnMButtonDown ( int mX, int mY ) {}
void CEvent::OnMButtonUp ( int mX, int mY ) {}
void CEvent::OnMinimize () {}
void CEvent::OnRestore () {}
void CEvent::OnResize ( int w, int h ) {}
void CEvent::OnExpose () {}
void CEvent::OnUser ( Uint8 type, int code, void* data1, void* data2 ) {}
void CEvent::OnExit () {}