1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef __EVENT_HPP_
|
---|
10 | #define __EVENT_HPP_
|
---|
11 |
|
---|
12 | #include "arch.hh"
|
---|
13 | #include "time/time.hh"
|
---|
14 | #include <stdlib.h>
|
---|
15 |
|
---|
16 | // Event summary :
|
---|
17 | /*
|
---|
18 |
|
---|
19 | all events should be derived from i4_event.
|
---|
20 | All events should have a type() and copy() function defined. Since all user application events
|
---|
21 | should be be OBJECT_MESSAGE or USER_MESSAGE type does not need to be defined.
|
---|
22 |
|
---|
23 | An object_message is usefull for scoping object messages to yourself specifically. Each object
|
---|
24 | can then have it's own event name-space. A USER_MESSAGE uses a global name-space and
|
---|
25 | should probably only be used in the main program.
|
---|
26 |
|
---|
27 | A events default to being sent ANYTIME, but be over-riding the when() function.
|
---|
28 | Events can be sent
|
---|
29 | LATER. (i.e. qued up and sent at another time... hence the need for a copy() function). or NOW.
|
---|
30 | If an event returns ANYTIME for when() the implementation choses. This currently default to NOW.
|
---|
31 |
|
---|
32 | Events should be sent through a channel and not directly. i.e.
|
---|
33 |
|
---|
34 | either :
|
---|
35 | i4_kernel.send_to(send_to,&ev);
|
---|
36 | or
|
---|
37 | i4_time_dev.request_event(send_to,&ev,time);
|
---|
38 |
|
---|
39 | note : events are passed as pointers to event.
|
---|
40 |
|
---|
41 | whenever you receive_event() you should first check it's
|
---|
42 | type throught the type() function. Then you
|
---|
43 | should CAST_PTR into the event type it actually is : example
|
---|
44 | void receive_event(i4_event *ev)
|
---|
45 | {
|
---|
46 | if (ev->type()==i4_event::KEY_PRESS)
|
---|
47 | {
|
---|
48 | CAST_PTR(key_ev,i4_key_press_event_class,ev);
|
---|
49 | printf("Key pressed %d\n",key_ev->key);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | IMPORTANT : if you are derived from a parent who has a receive_event()
|
---|
54 | you most likely want to call it
|
---|
55 | or you will not get any of it's default behaviors. This is especially true
|
---|
56 | with i4_window_class derivatives.
|
---|
57 |
|
---|
58 | Note that keycodes are defined in event/keys.hh
|
---|
59 | */
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | class i4_event
|
---|
64 | {
|
---|
65 | public:
|
---|
66 | enum event_type
|
---|
67 | {
|
---|
68 | MOUSE_MOVE,
|
---|
69 | MOUSE_BUTTON_DOWN,
|
---|
70 | MOUSE_BUTTON_UP,
|
---|
71 | KEY_PRESS,
|
---|
72 | KEY_RELEASE,
|
---|
73 | SYSTEM_SIGNAL, // CTRL-C, BUS, PIPE, etc
|
---|
74 | WINDOW_MESSAGE, // Events only seen by windows
|
---|
75 | DISPLAY_CHANGE, // When a refresh is need ore resolution changes
|
---|
76 | DISPLAY_CLOSE, // when close button on window is clicked, or the like
|
---|
77 | OBJECT_MESSAGE, // events specific to a specific instance (uses memory address to clarify)
|
---|
78 | QUERY_MESSAGE, // used by gui/ objects for querying and returning info
|
---|
79 | USER_MESSAGE, // global user evetns
|
---|
80 | DO_COMMAND,
|
---|
81 | END_COMMAND, // sent when key or menu item is depressed
|
---|
82 | IDLE_MESSAGE
|
---|
83 | } ;
|
---|
84 |
|
---|
85 | enum dispatch_time
|
---|
86 | {
|
---|
87 | ANYTIME,
|
---|
88 | NOW,
|
---|
89 | LATER
|
---|
90 | };
|
---|
91 |
|
---|
92 | // most events can be sent now or defered, if you need to be defered till later or sent
|
---|
93 | // immidately, this can be replaced
|
---|
94 | virtual dispatch_time when() { return ANYTIME; }
|
---|
95 |
|
---|
96 | virtual event_type type() = 0;
|
---|
97 | virtual i4_event *copy() = 0;
|
---|
98 | virtual ~i4_event() { ; }
|
---|
99 |
|
---|
100 | // translates any coordinates to client's window space
|
---|
101 | virtual void move(int x_offset, int y_offset) { ; }
|
---|
102 |
|
---|
103 | #ifndef I4_RETAIL
|
---|
104 | virtual char *name() = 0;
|
---|
105 | #endif
|
---|
106 | };
|
---|
107 |
|
---|
108 | class i4_mouse_move_event_class : public i4_event
|
---|
109 | {
|
---|
110 | public:
|
---|
111 | i4_coord lx,ly; // last x,y
|
---|
112 | i4_coord x,y;
|
---|
113 |
|
---|
114 | virtual event_type type() { return MOUSE_MOVE; }
|
---|
115 | virtual i4_event *copy() { return new i4_mouse_move_event_class(lx,ly,x,y); }
|
---|
116 | i4_mouse_move_event_class(i4_coord lx, i4_coord ly, i4_coord x, i4_coord y)
|
---|
117 | : lx(lx), ly(ly), x(x),y(y) {}
|
---|
118 | char *name() { return "mouse_move"; }
|
---|
119 |
|
---|
120 | void move(int x_offset, int y_offset)
|
---|
121 | {
|
---|
122 | x+=x_offset; y+=y_offset;
|
---|
123 | lx+=x_offset; ly+=y_offset;
|
---|
124 | }
|
---|
125 | } ;
|
---|
126 |
|
---|
127 |
|
---|
128 | class i4_mouse_button_event_class : public i4_event
|
---|
129 | {
|
---|
130 | public:
|
---|
131 | enum btype { LEFT, CENTER, RIGHT } but;
|
---|
132 | i4_coord x, y; // position mouse was at
|
---|
133 | i4_time_class time, last_time; // time pressed/depressed, time was last pressed/depressed
|
---|
134 | i4_bool double_click; // set by the window manager
|
---|
135 |
|
---|
136 | virtual event_type type() = 0;
|
---|
137 | virtual i4_event *copy() = 0;
|
---|
138 | #ifndef I4_RETAIL
|
---|
139 | virtual char *name() = 0;
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | i4_bool left() { return (i4_bool)(but==LEFT); }
|
---|
143 | i4_bool right() { return (i4_bool)(but==RIGHT); }
|
---|
144 | i4_bool center() { return (i4_bool)(but==CENTER); }
|
---|
145 |
|
---|
146 | i4_mouse_button_event_class(btype but,
|
---|
147 | i4_coord x, i4_coord y,
|
---|
148 | i4_time_class time, i4_time_class last_time,
|
---|
149 | i4_bool double_click=i4_F)
|
---|
150 | : but(but), x(x), y(y), time(time), last_time(last_time), double_click(double_click) {}
|
---|
151 |
|
---|
152 | void move(int x_offset, int y_offset) { x+=x_offset; y+=y_offset; }
|
---|
153 |
|
---|
154 | };
|
---|
155 |
|
---|
156 | class i4_mouse_button_down_event_class : public i4_mouse_button_event_class
|
---|
157 | {
|
---|
158 | public:
|
---|
159 | event_type type() { return MOUSE_BUTTON_DOWN; }
|
---|
160 |
|
---|
161 | i4_mouse_button_down_event_class(btype but,
|
---|
162 | i4_coord x, i4_coord y,
|
---|
163 | i4_time_class time, i4_time_class last_time,
|
---|
164 | i4_bool double_click=i4_F)
|
---|
165 | : i4_mouse_button_event_class(but,x,y, time, last_time, double_click) {}
|
---|
166 |
|
---|
167 | virtual i4_event *copy()
|
---|
168 | {
|
---|
169 | return new i4_mouse_button_down_event_class(but,x,y,time,last_time, double_click);
|
---|
170 | }
|
---|
171 |
|
---|
172 | char *name() { return "mouse_button_down"; }
|
---|
173 | } ;
|
---|
174 |
|
---|
175 | class i4_mouse_button_up_event_class : public i4_mouse_button_event_class
|
---|
176 | {
|
---|
177 | public:
|
---|
178 | virtual event_type type() { return MOUSE_BUTTON_UP; }
|
---|
179 | i4_mouse_button_up_event_class(btype but,
|
---|
180 | i4_coord x, i4_coord y,
|
---|
181 | i4_time_class time, i4_time_class last_time,
|
---|
182 | i4_bool double_click=i4_F)
|
---|
183 | : i4_mouse_button_event_class(but,x,y, time, last_time, double_click) {}
|
---|
184 |
|
---|
185 | virtual i4_event *copy()
|
---|
186 | {
|
---|
187 | return new i4_mouse_button_up_event_class(but,x,y,time,last_time, double_click);
|
---|
188 | }
|
---|
189 |
|
---|
190 | char *name() { return "mouse_button_up"; }
|
---|
191 | } ;
|
---|
192 |
|
---|
193 |
|
---|
194 | class i4_do_command_event_class : public i4_event
|
---|
195 | {
|
---|
196 | public:
|
---|
197 | i4_time_class time;
|
---|
198 | char command[64];
|
---|
199 | int command_id;
|
---|
200 |
|
---|
201 | i4_do_command_event_class(char *_command, int command_id);
|
---|
202 | i4_do_command_event_class(char *_command, int command_id, i4_time_class &time);
|
---|
203 | virtual event_type type() { return DO_COMMAND; }
|
---|
204 | virtual i4_event *copy();
|
---|
205 | char *name() { return "do_command"; }
|
---|
206 | } ;
|
---|
207 |
|
---|
208 |
|
---|
209 | class i4_end_command_event_class : public i4_event
|
---|
210 | {
|
---|
211 | public:
|
---|
212 | i4_time_class time;
|
---|
213 | char command[64];
|
---|
214 | int command_id;
|
---|
215 |
|
---|
216 | i4_end_command_event_class(char *command, int command_id, i4_time_class &time);
|
---|
217 | i4_end_command_event_class(char *command, int command_id);
|
---|
218 |
|
---|
219 |
|
---|
220 | virtual event_type type() { return END_COMMAND; }
|
---|
221 | virtual i4_event *copy() { return new i4_end_command_event_class(command, command_id, time); }
|
---|
222 | char *name() { return "end_command"; }
|
---|
223 | } ;
|
---|
224 |
|
---|
225 |
|
---|
226 | class i4_key_press_event_class : public i4_event
|
---|
227 | {
|
---|
228 | public:
|
---|
229 | i4_time_class time;
|
---|
230 |
|
---|
231 | w16 key, // includes shift info
|
---|
232 | key_code, // raw key code
|
---|
233 | modifiers; // includes shift, ctrl, alt, num-lock etc
|
---|
234 |
|
---|
235 | i4_key_press_event_class(w16 key, w16 key_code, w16 modifiers, i4_time_class &time)
|
---|
236 | : key(key), key_code(key_code), modifiers(modifiers), time(time) {}
|
---|
237 | virtual event_type type() { return KEY_PRESS; }
|
---|
238 | virtual i4_event *copy() { return new i4_key_press_event_class(key,key_code,modifiers,time); }
|
---|
239 | char *name() { return "key_press"; }
|
---|
240 | } ;
|
---|
241 |
|
---|
242 | class i4_key_release_event_class : public i4_event
|
---|
243 | {
|
---|
244 | public:
|
---|
245 | i4_time_class time;
|
---|
246 |
|
---|
247 | w16 key, key_code, modifiers;
|
---|
248 |
|
---|
249 | i4_key_release_event_class(w16 key, w16 key_code, w16 modifiers, i4_time_class &time)
|
---|
250 | : key(key), key_code(key_code), modifiers(modifiers), time(time) {}
|
---|
251 | virtual event_type type() { return KEY_RELEASE; }
|
---|
252 | virtual i4_event *copy() { return new i4_key_release_event_class(key,key_code,modifiers,time); }
|
---|
253 | char *name() { return "key_release"; }
|
---|
254 | } ;
|
---|
255 |
|
---|
256 | class i4_display_class;
|
---|
257 | class i4_display_change_event_class : public i4_event
|
---|
258 | {
|
---|
259 | public:
|
---|
260 | i4_display_class *display;
|
---|
261 | enum change_type
|
---|
262 | {
|
---|
263 | SIZE_CHANGE, // resolution change
|
---|
264 | PALETTE_CHANGE, // color mapping changed (not implemented yet)
|
---|
265 | LOCATION_CHANGE // screen changed location (i.e. to another window or server)
|
---|
266 | };
|
---|
267 | change_type change;
|
---|
268 |
|
---|
269 | i4_display_change_event_class(i4_display_class *display, change_type change)
|
---|
270 | : display(display), change(change) {}
|
---|
271 |
|
---|
272 | virtual dispatch_time when() { return NOW; }
|
---|
273 | virtual event_type type() { return DISPLAY_CHANGE; }
|
---|
274 | virtual i4_event *copy() { return new i4_display_change_event_class(display,change); }
|
---|
275 | char *name() { return "display_change"; }
|
---|
276 | };
|
---|
277 |
|
---|
278 | class i4_display_close_event_class : public i4_event
|
---|
279 | {
|
---|
280 | public:
|
---|
281 | i4_display_class *display;
|
---|
282 |
|
---|
283 | i4_display_close_event_class(i4_display_class *display) : display(display) {}
|
---|
284 | virtual dispatch_time when() { return LATER; }
|
---|
285 | virtual event_type type() { return DISPLAY_CLOSE; }
|
---|
286 | virtual i4_event *copy() { return new i4_display_close_event_class(display); }
|
---|
287 | char *name() { return "display_close"; }
|
---|
288 | };
|
---|
289 |
|
---|
290 | class i4_user_message_event_class : public i4_event
|
---|
291 | {
|
---|
292 | public:
|
---|
293 | w32 sub_type;
|
---|
294 |
|
---|
295 | virtual event_type type() { return USER_MESSAGE; }
|
---|
296 | i4_user_message_event_class(w32 sub_type) : sub_type(sub_type) {}
|
---|
297 | virtual i4_event *copy() { return new i4_user_message_event_class(sub_type); }
|
---|
298 | char *name() { return "user_message"; }
|
---|
299 | } ;
|
---|
300 |
|
---|
301 | class i4_query_message_event_class : public i4_event
|
---|
302 | {
|
---|
303 | public:
|
---|
304 | virtual event_type type() { return QUERY_MESSAGE; }
|
---|
305 | virtual i4_event *copy() = 0;
|
---|
306 | virtual dispatch_time when() { return NOW; }
|
---|
307 | char *name() { return "query_message"; }
|
---|
308 | } ;
|
---|
309 |
|
---|
310 | class i4_object_message_event_class : public i4_event
|
---|
311 | {
|
---|
312 | public:
|
---|
313 | dispatch_time dtime;
|
---|
314 | void *object;
|
---|
315 | w32 sub_type;
|
---|
316 |
|
---|
317 | virtual dispatch_time when() { return dtime; }
|
---|
318 | virtual event_type type() { return OBJECT_MESSAGE; }
|
---|
319 | i4_object_message_event_class(void *object, w32 sub_type=0, dispatch_time when=ANYTIME)
|
---|
320 | : object(object), sub_type(sub_type), dtime(when) {}
|
---|
321 | virtual i4_event *copy() { return new i4_object_message_event_class(object, sub_type); }
|
---|
322 | char *name() { return "object_message"; }
|
---|
323 | } ;
|
---|
324 |
|
---|
325 | class i4_system_signal_event_class : public i4_event
|
---|
326 | {
|
---|
327 | public:
|
---|
328 | enum signal_type
|
---|
329 | {
|
---|
330 | HUP, INTERRUPT, QUIT, ILL, TRAP, ABORT, IOT, BUS, FPE,
|
---|
331 | KILL, USR1, SEG_FAULT, USR2, PIPE, ALARM, TERM, CHILD, CONTINUE,
|
---|
332 | STOP, TSTP, TTIN, TTOU, IO, URG, CPU, XFSZ, VTALRM,
|
---|
333 | PROF, WINCH
|
---|
334 | };
|
---|
335 | signal_type signal_number;
|
---|
336 |
|
---|
337 | virtual event_type type() { return SYSTEM_SIGNAL; }
|
---|
338 | virtual i4_event *copy() { return new i4_system_signal_event_class(signal_number); }
|
---|
339 |
|
---|
340 | i4_system_signal_event_class(signal_type sig) : signal_number(sig) {}
|
---|
341 | char *name() { return "signal"; }
|
---|
342 | } ;
|
---|
343 |
|
---|
344 |
|
---|
345 |
|
---|
346 | class i4_user_idle_event_class : public i4_event
|
---|
347 | {
|
---|
348 | public:
|
---|
349 | virtual event_type type() { return IDLE_MESSAGE; }
|
---|
350 | virtual i4_event *copy() { return new i4_user_idle_event_class; }
|
---|
351 | char *name() { return "idle_message"; }
|
---|
352 | } ;
|
---|
353 |
|
---|
354 | #endif
|
---|
355 |
|
---|