view src/EventHandler.cpp @ 7:104dff305563

Added App::on_InputFocus and app::on_InputBlur to make sure the program does not receive mouse clicks when not in foreground. Added option in CmakeLists.txt to support compiling for gprof.
author Eris Caffee <discordia@eldalin.com>
date Mon, 15 Nov 2010 21:55:46 -0600
parents d691ce98f406
children
line source
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Fracter - A simple Mandelbrot Set viewer.
4 //
5 // Copyright (C) 2010 Sarah Eris Horsley Caffee
6 //
7 // This file is part of Fracter.
8 //
9 // Fracter is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 //
23 // EventHandler.cpp
24 // EventHandler class implementation.
25 //
26 ////////////////////////////////////////////////////////////////////////////////
28 #include "EventHandler.h"
31 ////////////////////////////////////////////////////////////////////////////////
32 EventHandler::EventHandler()
33 {
34 }
37 ////////////////////////////////////////////////////////////////////////////////
38 EventHandler::~EventHandler()
39 {
40 }
43 ////////////////////////////////////////////////////////////////////////////////
44 void EventHandler::on_Event(SDL_Event * event)
45 {
46 switch(event->type)
47 {
48 case SDL_ACTIVEEVENT:
49 {
50 switch(event->active.state)
51 {
52 case SDL_APPMOUSEFOCUS:
53 {
54 if (event->active.gain) on_MouseFocus();
55 else on_MouseBlur();
56 break;
57 }
58 case SDL_APPINPUTFOCUS:
59 {
60 if (event->active.gain) on_InputFocus();
61 else on_InputBlur();
62 break;
63 }
64 case SDL_APPACTIVE:
65 {
66 if (event->active.gain) on_Restore();
67 else on_Minimize();
68 break;
69 }
70 }
71 break;
72 }
74 case SDL_KEYDOWN:
75 {
76 on_KeyDown(event->key);
77 break;
78 }
79 case SDL_KEYUP:
80 {
81 on_KeyUp(event->key);
82 break;
83 }
85 case SDL_MOUSEMOTION:
86 {
87 on_MouseMove(event->motion);
88 break;
89 }
90 case SDL_MOUSEBUTTONDOWN:
91 {
92 switch (event->button.button)
93 {
94 case SDL_BUTTON_LEFT:
95 {
96 on_LButtonDown(event->button);
97 break;
98 }
99 case SDL_BUTTON_RIGHT:
100 {
101 on_RButtonDown(event->button);
102 break;
103 }
104 case SDL_BUTTON_MIDDLE:
105 {
106 on_MButtonDown(event->button);
107 break;
108 }
109 case SDL_BUTTON_WHEELDOWN:
110 {
111 on_MouseWheelDown(event->button);
112 break;
113 }
114 }
115 break;
116 }
117 case SDL_MOUSEBUTTONUP:
118 {
119 switch (event->button.button)
120 {
121 case SDL_BUTTON_LEFT:
122 {
123 on_LButtonUp(event->button);
124 break;
125 }
126 case SDL_BUTTON_RIGHT:
127 {
128 on_RButtonUp(event->button);
129 break;
130 }
131 case SDL_BUTTON_MIDDLE:
132 {
133 on_MButtonUp(event->button);
134 break;
135 }
136 case SDL_BUTTON_WHEELUP:
137 {
138 on_MouseWheelUp(event->button);
139 break;
140 }
141 }
142 break;
143 }
145 case SDL_JOYAXISMOTION:
146 {
147 on_JoyAxis(event->jaxis);
148 break;
149 }
150 case SDL_JOYBALLMOTION:
151 {
152 on_JoyBall(event->jball);
153 break;
154 }
155 case SDL_JOYHATMOTION:
156 {
157 on_JoyHat(event->jhat);
158 break;
159 }
160 case SDL_JOYBUTTONDOWN:
161 {
162 on_JoyButtonDown(event->jbutton);
163 break;
164 }
165 case SDL_JOYBUTTONUP:
166 {
167 on_JoyButtonUp(event->jbutton);
168 break;
169 }
171 case SDL_VIDEORESIZE:
172 {
173 on_Resize(event->resize);
174 break;
175 }
176 case SDL_VIDEOEXPOSE:
177 {
178 on_Expose();
179 break;
180 }
181 case SDL_QUIT:
182 {
183 on_Quit();
184 break;
185 }
186 case SDL_SYSWMEVENT:
187 {
188 on_SysWM(event->syswm);
189 break;
190 }
192 case SDL_NOEVENT:
193 case SDL_EVENT_RESERVEDA:
194 case SDL_EVENT_RESERVEDB:
195 case SDL_EVENT_RESERVED2:
196 case SDL_EVENT_RESERVED3:
197 case SDL_EVENT_RESERVED4:
198 case SDL_EVENT_RESERVED5:
199 case SDL_EVENT_RESERVED6:
200 case SDL_EVENT_RESERVED7:
201 case SDL_NUMEVENTS:
202 {
203 // Reserved events are silently ignored.
204 break;
205 }
207 default:
208 {
209 // All other events are user events.
210 on_User(event->user);
211 break;
212 }
213 }
214 }
218 ////////////////////////////////////////////////////////////////////////////////
220 // Active events
222 void EventHandler::on_MouseFocus()
223 {
224 }
226 void EventHandler::on_MouseBlur()
227 {
228 }
230 void EventHandler::on_InputFocus()
231 {
232 }
234 void EventHandler::on_InputBlur()
235 {
236 }
238 void EventHandler::on_Minimize()
239 {
240 }
242 void EventHandler::on_Restore()
243 {
244 }
247 // Keyboard events
249 void EventHandler::on_KeyDown(SDL_KeyboardEvent key)
250 {
251 }
253 void EventHandler::on_KeyUp(SDL_KeyboardEvent key)
254 {
255 }
258 // Mouse events
260 void EventHandler::on_MouseMove(SDL_MouseMotionEvent motion)
261 {
262 }
264 void EventHandler::on_LButtonDown(SDL_MouseButtonEvent button)
265 {
266 }
268 void EventHandler::on_LButtonUp(SDL_MouseButtonEvent button)
269 {
270 }
272 void EventHandler::on_RButtonDown(SDL_MouseButtonEvent button)
273 {
274 }
276 void EventHandler::on_RButtonUp(SDL_MouseButtonEvent button)
277 {
278 }
280 void EventHandler::on_MButtonDown(SDL_MouseButtonEvent button)
281 {
282 }
284 void EventHandler::on_MButtonUp(SDL_MouseButtonEvent button)
285 {
286 }
288 void EventHandler::on_MouseWheelDown(SDL_MouseButtonEvent button)
289 {
290 }
292 void EventHandler::on_MouseWheelUp(SDL_MouseButtonEvent button)
293 {
294 }
297 // Joystick events
299 void EventHandler::on_JoyAxis(SDL_JoyAxisEvent jaxis)
300 {
301 }
303 void EventHandler::on_JoyButtonDown(SDL_JoyButtonEvent jbutton)
304 {
305 }
307 void EventHandler::on_JoyButtonUp(SDL_JoyButtonEvent jbutton)
308 {
309 }
311 void EventHandler::on_JoyHat(SDL_JoyHatEvent jhat)
312 {
313 }
315 void EventHandler::on_JoyBall(SDL_JoyBallEvent jball)
316 {
317 }
320 // Misc events
322 void EventHandler::on_Resize(SDL_ResizeEvent resize)
323 {
324 }
326 void EventHandler::on_Expose()
327 {
328 }
330 void EventHandler::on_Quit()
331 {
332 }
334 void EventHandler::on_User(SDL_UserEvent user)
335 {
336 }
338 void EventHandler::on_SysWM(SDL_SysWMEvent syswm)
339 {
340 }