1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __I_EVENT_RECEIVER_H_INCLUDED__
\r
6 #define __I_EVENT_RECEIVER_H_INCLUDED__
\r
9 #include "Keycodes.h"
\r
10 #include "irrString.h"
\r
14 //! Enumeration for all event types there are.
\r
17 //! An event of the graphical user interface.
\r
18 /** GUI events are created by the GUI environment or the GUI elements in response
\r
19 to mouse or keyboard events. When a GUI element receives an event it will either
\r
20 process it and return true, or pass the event to its parent. If an event is not absorbed
\r
21 before it reaches the root element then it will then be passed to the user receiver. */
\r
24 //! A mouse input event.
\r
25 /** Mouse events are created by the device and passed to IrrlichtDevice::postEventFromUser
\r
26 in response to mouse input received from the operating system.
\r
27 Mouse events are first passed to the user receiver, then to the GUI environment and its elements,
\r
28 then finally the input receiving scene manager where it is passed to the active camera.
\r
30 EET_MOUSE_INPUT_EVENT,
\r
32 //! A key input event.
\r
33 /** Like mouse events, keyboard events are created by the device and passed to
\r
34 IrrlichtDevice::postEventFromUser. They take the same path as mouse events. */
\r
35 EET_KEY_INPUT_EVENT,
\r
37 //! A touch input event.
\r
38 EET_TOUCH_INPUT_EVENT,
\r
40 //! A accelerometer event.
\r
41 EET_ACCELEROMETER_EVENT,
\r
43 //! A gyroscope event.
\r
44 EET_GYROSCOPE_EVENT,
\r
46 //! A device motion event.
\r
47 EET_DEVICE_MOTION_EVENT,
\r
49 //! A joystick (joypad, gamepad) input event.
\r
50 /** Joystick events are created by polling all connected joysticks once per
\r
51 device run() and then passing the events to IrrlichtDevice::postEventFromUser.
\r
52 They take the same path as mouse events.
\r
53 Windows, SDL: Implemented.
\r
54 Linux: Implemented, with POV hat issues.
\r
55 MacOS / Other: Not yet implemented.
\r
57 EET_JOYSTICK_INPUT_EVENT,
\r
60 /** Log events are only passed to the user receiver if there is one. If they are absorbed by the
\r
61 user receiver then no text will be sent to the console. */
\r
64 //! A user event with user data.
\r
65 /** This is not used by Irrlicht and can be used to send user
\r
66 specific data though the system. The Irrlicht 'window handle'
\r
67 can be obtained from IrrlichtDevice::getExposedVideoData()
\r
68 The usage and behavior depends on the operating system:
\r
69 Windows: send a WM_USER message to the Irrlicht Window; the
\r
70 wParam and lParam will be used to populate the
\r
71 UserData1 and UserData2 members of the SUserEvent.
\r
72 Linux: send a ClientMessage via XSendEvent to the Irrlicht
\r
73 Window; the data.l[0] and data.l[1] members will be
\r
74 cast to s32 and used as UserData1 and UserData2.
\r
75 MacOS: Not yet implemented
\r
79 //! Pass on raw events from the OS
\r
82 //! Application state events like a resume, pause etc.
\r
83 EET_APPLICATION_EVENT,
\r
85 //! This enum is never used, it only forces the compiler to
\r
86 //! compile these enumeration values to 32 bit.
\r
87 EGUIET_FORCE_32_BIT = 0x7fffffff
\r
91 //! Enumeration for all mouse input events
\r
92 enum EMOUSE_INPUT_EVENT
\r
94 //! Left mouse button was pressed down.
\r
95 EMIE_LMOUSE_PRESSED_DOWN = 0,
\r
97 //! Right mouse button was pressed down.
\r
98 EMIE_RMOUSE_PRESSED_DOWN,
\r
100 //! Middle mouse button was pressed down.
\r
101 EMIE_MMOUSE_PRESSED_DOWN,
\r
103 //! Left mouse button was left up.
\r
104 EMIE_LMOUSE_LEFT_UP,
\r
106 //! Right mouse button was left up.
\r
107 EMIE_RMOUSE_LEFT_UP,
\r
109 //! Middle mouse button was left up.
\r
110 EMIE_MMOUSE_LEFT_UP,
\r
112 //! The mouse cursor changed its position.
\r
115 //! The mouse wheel was moved. Use Wheel value in event data to find out
\r
116 //! in what direction and how fast.
\r
119 //! Left mouse button double click.
\r
120 //! This event is generated after the second EMIE_LMOUSE_PRESSED_DOWN event.
\r
121 EMIE_LMOUSE_DOUBLE_CLICK,
\r
123 //! Right mouse button double click.
\r
124 //! This event is generated after the second EMIE_RMOUSE_PRESSED_DOWN event.
\r
125 EMIE_RMOUSE_DOUBLE_CLICK,
\r
127 //! Middle mouse button double click.
\r
128 //! This event is generated after the second EMIE_MMOUSE_PRESSED_DOWN event.
\r
129 EMIE_MMOUSE_DOUBLE_CLICK,
\r
131 //! Left mouse button triple click.
\r
132 //! This event is generated after the third EMIE_LMOUSE_PRESSED_DOWN event.
\r
133 EMIE_LMOUSE_TRIPLE_CLICK,
\r
135 //! Right mouse button triple click.
\r
136 //! This event is generated after the third EMIE_RMOUSE_PRESSED_DOWN event.
\r
137 EMIE_RMOUSE_TRIPLE_CLICK,
\r
139 //! Middle mouse button triple click.
\r
140 //! This event is generated after the third EMIE_MMOUSE_PRESSED_DOWN event.
\r
141 EMIE_MMOUSE_TRIPLE_CLICK,
\r
143 //! Mouse enters canvas used for rendering.
\r
144 //! Only generated on emscripten
\r
145 EMIE_MOUSE_ENTER_CANVAS,
\r
147 //! Mouse leaves canvas used for rendering.
\r
148 //! Only generated on emscripten
\r
149 EMIE_MOUSE_LEAVE_CANVAS,
\r
151 //! No real event. Just for convenience to get number of events
\r
155 //! Masks for mouse button states
\r
156 enum E_MOUSE_BUTTON_STATE_MASK
\r
159 EMBSM_RIGHT = 0x02,
\r
160 EMBSM_MIDDLE = 0x04,
\r
162 //! currently only on windows
\r
163 EMBSM_EXTRA1 = 0x08,
\r
165 //! currently only on windows
\r
166 EMBSM_EXTRA2 = 0x10,
\r
168 EMBSM_FORCE_32_BIT = 0x7fffffff
\r
171 //! Enumeration for all touch input events
\r
172 enum ETOUCH_INPUT_EVENT
\r
174 //! Touch was pressed down.
\r
175 ETIE_PRESSED_DOWN = 0,
\r
177 //! Touch was left up.
\r
180 //! The touch changed its position.
\r
183 //! No real event. Just for convenience to get number of events
\r
187 enum ESYSTEM_EVENT_TYPE
\r
189 //! From Android command handler for native activity messages
\r
190 ESET_ANDROID_CMD = 0,
\r
192 // TODO: for example ESET_WINDOWS_MESSAGE for win32 message loop events
\r
194 //! No real event, but to get number of event types
\r
198 //! Enumeration for a commonly used application state events (it's useful mainly for mobile devices)
\r
199 enum EAPPLICATION_EVENT_TYPE
\r
201 //! The application will be resumed.
\r
202 EAET_WILL_RESUME = 0,
\r
204 //! The application has been resumed.
\r
207 //! The application will be paused.
\r
210 //! The application has been paused.
\r
213 //! The application will be terminated.
\r
214 EAET_WILL_TERMINATE,
\r
216 //! The application received a memory warning.
\r
217 EAET_MEMORY_WARNING,
\r
219 //! No real event, but to get number of event types.
\r
228 //! Enumeration for all events which are sendable by the gui system
\r
229 enum EGUI_EVENT_TYPE
\r
231 //! A gui element has lost its focus.
\r
232 /** GUIEvent.Caller is losing the focus to GUIEvent.Element.
\r
233 If the event is absorbed then the focus will not be changed. */
\r
234 EGET_ELEMENT_FOCUS_LOST = 0,
\r
236 //! A gui element has got the focus.
\r
237 /** If the event is absorbed then the focus will not be changed. */
\r
238 EGET_ELEMENT_FOCUSED,
\r
240 //! The mouse cursor hovered over a gui element.
\r
241 /** If an element has sub-elements you also get this message for the subelements */
\r
242 EGET_ELEMENT_HOVERED,
\r
244 //! The mouse cursor left the hovered element.
\r
245 /** If an element has sub-elements you also get this message for the subelements */
\r
248 //! An element would like to close.
\r
249 /** Windows and context menus use this event when they would like to close,
\r
250 this can be canceled by absorbing the event. */
\r
251 EGET_ELEMENT_CLOSED,
\r
253 //! A button was clicked.
\r
254 EGET_BUTTON_CLICKED,
\r
256 //! A scrollbar has changed its position.
\r
257 EGET_SCROLL_BAR_CHANGED,
\r
259 //! A checkbox has changed its check state.
\r
260 EGET_CHECKBOX_CHANGED,
\r
262 //! A new item in a listbox was selected.
\r
263 /** NOTE: You also get this event currently when the same item was clicked again after more than 500 ms. */
\r
264 EGET_LISTBOX_CHANGED,
\r
266 //! An item in the listbox was selected, which was already selected.
\r
267 /** NOTE: You get the event currently only if the item was clicked again within 500 ms or selected by "enter" or "space". */
\r
268 EGET_LISTBOX_SELECTED_AGAIN,
\r
270 //! A file has been selected in the file dialog
\r
271 EGET_FILE_SELECTED,
\r
273 //! A directory has been selected in the file dialog
\r
274 EGET_DIRECTORY_SELECTED,
\r
276 //! A file open dialog has been closed without choosing a file
\r
277 EGET_FILE_CHOOSE_DIALOG_CANCELLED,
\r
279 //! 'Yes' was clicked on a messagebox
\r
280 EGET_MESSAGEBOX_YES,
\r
282 //! 'No' was clicked on a messagebox
\r
283 EGET_MESSAGEBOX_NO,
\r
285 //! 'OK' was clicked on a messagebox
\r
286 EGET_MESSAGEBOX_OK,
\r
288 //! 'Cancel' was clicked on a messagebox
\r
289 EGET_MESSAGEBOX_CANCEL,
\r
291 //! In an editbox 'ENTER' was pressed
\r
292 EGET_EDITBOX_ENTER,
\r
294 //! The text in an editbox was changed. This does not include automatic changes in text-breaking.
\r
295 EGET_EDITBOX_CHANGED,
\r
297 //! The marked area in an editbox was changed.
\r
298 EGET_EDITBOX_MARKING_CHANGED,
\r
300 //! The tab was changed in an tab control
\r
303 //! A menu item was selected in a (context) menu
\r
304 EGET_MENU_ITEM_SELECTED,
\r
306 //! The selection in a combo box has been changed
\r
307 EGET_COMBO_BOX_CHANGED,
\r
309 //! The value of a spin box has changed
\r
310 EGET_SPINBOX_CHANGED,
\r
312 //! A table has changed
\r
313 EGET_TABLE_CHANGED,
\r
314 EGET_TABLE_HEADER_CHANGED,
\r
315 EGET_TABLE_SELECTED_AGAIN,
\r
317 //! A tree view node lost selection. See IGUITreeView::getLastEventNode().
\r
318 EGET_TREEVIEW_NODE_DESELECT,
\r
320 //! A tree view node was selected. See IGUITreeView::getLastEventNode().
\r
321 EGET_TREEVIEW_NODE_SELECT,
\r
323 //! A tree view node was expanded. See IGUITreeView::getLastEventNode().
\r
324 EGET_TREEVIEW_NODE_EXPAND,
\r
326 //! A tree view node was collapsed. See IGUITreeView::getLastEventNode().
\r
327 EGET_TREEVIEW_NODE_COLLAPSE,
\r
329 //! deprecated - use EGET_TREEVIEW_NODE_COLLAPSE instead. This
\r
330 //! may be removed by Irrlicht 1.9
\r
331 EGET_TREEVIEW_NODE_COLLAPS = EGET_TREEVIEW_NODE_COLLAPSE,
\r
333 //! No real event. Just for convenience to get number of events
\r
336 } // end namespace gui
\r
339 //! SEvents hold information about an event. See irr::IEventReceiver for details on event handling.
\r
342 //! Any kind of GUI event.
\r
345 //! IGUIElement who called the event
\r
346 gui::IGUIElement* Caller;
\r
348 //! If the event has something to do with another element, it will be held here.
\r
349 gui::IGUIElement* Element;
\r
351 //! Type of GUI Event
\r
352 gui::EGUI_EVENT_TYPE EventType;
\r
356 //! Any kind of mouse event.
\r
359 //! X position of mouse cursor
\r
362 //! Y position of mouse cursor
\r
365 //! mouse wheel delta, often 1.0 or -1.0, but can have other values < 0.f or > 0.f;
\r
366 /** Only valid if event was EMIE_MOUSE_WHEEL */
\r
369 //! True if shift was also pressed
\r
372 //! True if ctrl was also pressed
\r
375 //! A bitmap of button states. You can use isButtonPressed() to determine
\r
376 //! if a button is pressed or not.
\r
377 //! Currently only valid if the event was EMIE_MOUSE_MOVED
\r
380 //! Is the left button pressed down?
\r
381 bool isLeftPressed() const { return 0 != ( ButtonStates & EMBSM_LEFT ); }
\r
383 //! Is the right button pressed down?
\r
384 bool isRightPressed() const { return 0 != ( ButtonStates & EMBSM_RIGHT ); }
\r
386 //! Is the middle button pressed down?
\r
387 bool isMiddlePressed() const { return 0 != ( ButtonStates & EMBSM_MIDDLE ); }
\r
389 //! Type of mouse event
\r
390 EMOUSE_INPUT_EVENT Event;
\r
393 //! Any kind of keyboard event.
\r
396 //! Character corresponding to the key (0, if not a character, value undefined in key releases)
\r
399 //! Key which has been pressed or released
\r
402 //! System dependent code. Only set for systems which are described below, otherwise undefined.
\r
403 //! Android: int32_t with physical key as returned by AKeyEvent_getKeyCode
\r
406 //! If not true, then the key was left up
\r
407 bool PressedDown:1;
\r
409 //! True if shift was also pressed
\r
412 //! True if ctrl was also pressed
\r
416 //! Any kind of touch event.
\r
422 // X position of simple touch.
\r
425 // Y position of simple touch.
\r
428 //! Type of touch event.
\r
429 ETOUCH_INPUT_EVENT Event;
\r
432 //! Any kind of accelerometer event.
\r
433 struct SAccelerometerEvent
\r
445 //! Any kind of gyroscope event.
\r
446 struct SGyroscopeEvent
\r
458 //! Any kind of device motion event.
\r
459 struct SDeviceMotionEvent
\r
464 // Y angle - pitch.
\r
471 //! A joystick event.
\r
472 /** Unlike other events, joystick events represent the result of polling
\r
473 * each connected joystick once per run() of the device. Joystick events will
\r
474 * not be generated by default. If joystick support is available for the
\r
475 * active device, _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ is defined, and
\r
476 * @ref irr::IrrlichtDevice::activateJoysticks() has been called, an event of
\r
477 * this type will be generated once per joystick per @ref IrrlichtDevice::run()
\r
478 * regardless of whether the state of the joystick has actually changed. */
\r
479 struct SJoystickEvent
\r
483 NUMBER_OF_BUTTONS = 32,
\r
485 AXIS_X = 0, // e.g. analog stick 1 left to right
\r
486 AXIS_Y, // e.g. analog stick 1 top to bottom
\r
487 AXIS_Z, // e.g. throttle, or analog 2 stick 2 left to right
\r
488 AXIS_R, // e.g. rudder, or analog 2 stick 2 top to bottom
\r
491 NUMBER_OF_AXES=18 // (please tell Irrlicht maintainers if you absolutely need more axes)
\r
494 /** A bitmap of button states. You can use IsButtonPressed() to
\r
495 ( check the state of each button from 0 to (NUMBER_OF_BUTTONS - 1) */
\r
498 /** For AXIS_X, AXIS_Y, AXIS_Z, AXIS_R, AXIS_U and AXIS_V
\r
499 * Values are in the range -32768 to 32767, with 0 representing
\r
500 * the center position. You will receive the raw value from the
\r
501 * joystick, and so will usually want to implement a dead zone around
\r
502 * the center of the range. Axes not supported by this joystick will
\r
503 * always have a value of 0. On Linux, POV hats are represented as axes,
\r
504 * usually the last two active axis.
\r
506 s16 Axis[NUMBER_OF_AXES];
\r
508 /** The POV represents the angle of the POV hat in degrees * 100,
\r
509 * from 0 to 35,900. A value of 65535 indicates that the POV hat
\r
510 * is centered (or not present).
\r
511 * This value is only supported on Windows. On Linux, the POV hat
\r
512 * will be sent as 2 axes instead. */
\r
515 //! The ID of the joystick which generated this event.
\r
516 /** This is an internal Irrlicht index; it does not map directly
\r
517 * to any particular hardware joystick. */
\r
520 //! A helper function to check if a button is pressed.
\r
521 bool IsButtonPressed(u32 button) const
\r
523 if(button >= (u32)NUMBER_OF_BUTTONS)
\r
526 return (ButtonStates & (1 << button)) ? true : false;
\r
530 //! Any kind of log event.
\r
533 //! Pointer to text which has been logged
\r
536 //! Log level in which the text has been logged
\r
540 //! Any kind of user event.
\r
543 //! Some user specified data as int
\r
546 //! Another user specified data as int
\r
550 // Raw events from the OS
\r
551 struct SSystemEvent
\r
553 //! Android command handler native activity messages.
\r
556 //! APP_CMD_ enums defined in android_native_app_glue.h from the Android NDK
\r
560 // TOOD: more structs for iphone, Windows, X11, etc.
\r
562 ESYSTEM_EVENT_TYPE EventType;
\r
565 struct SAndroidCmd AndroidCmd;
\r
569 // Application state event
\r
570 struct SApplicationEvent
\r
572 EAPPLICATION_EVENT_TYPE EventType;
\r
575 EEVENT_TYPE EventType;
\r
578 struct SGUIEvent GUIEvent;
\r
579 struct SMouseInput MouseInput;
\r
580 struct SKeyInput KeyInput;
\r
581 struct STouchInput TouchInput;
\r
582 struct SAccelerometerEvent AccelerometerEvent;
\r
583 struct SGyroscopeEvent GyroscopeEvent;
\r
584 struct SDeviceMotionEvent DeviceMotionEvent;
\r
585 struct SJoystickEvent JoystickEvent;
\r
586 struct SLogEvent LogEvent;
\r
587 struct SUserEvent UserEvent;
\r
588 struct SSystemEvent SystemEvent;
\r
589 struct SApplicationEvent ApplicationEvent;
\r
594 //! Interface of an object which can receive events.
\r
595 /** Many of the engine's classes inherit IEventReceiver so they are able to
\r
596 process events. Events usually start at a postEventFromUser function and are
\r
597 passed down through a chain of event receivers until OnEvent returns true. See
\r
598 irr::EEVENT_TYPE for a description of where each type of event starts, and the
\r
599 path it takes through the system. */
\r
600 class IEventReceiver
\r
605 virtual ~IEventReceiver() {}
\r
607 //! Called if an event happened.
\r
608 /** Please take care that you should only return 'true' when you want to _prevent_ Irrlicht
\r
609 * from processing the event any further. So 'true' does mean that an event is completely done.
\r
610 * Therefore your return value for all unprocessed events should be 'false'.
\r
611 \return True if the event was processed.
\r
613 virtual bool OnEvent(const SEvent& event) = 0;
\r
617 //! Information on a joystick, returned from @ref irr::IrrlichtDevice::activateJoysticks()
\r
618 struct SJoystickInfo
\r
620 //! The ID of the joystick
\r
621 /** This is an internal Irrlicht index; it does not map directly
\r
622 * to any particular hardware joystick. It corresponds to the
\r
623 * irr::SJoystickEvent Joystick ID. */
\r
626 //! The name that the joystick uses to identify itself.
\r
627 core::stringc Name;
\r
629 //! The number of buttons that the joystick has.
\r
632 //! The number of axes that the joystick has, i.e. X, Y, Z, R, U, V.
\r
633 /** Note: with a Linux device, the POV hat (if any) will use two axes. These
\r
634 * will be included in this count. */
\r
637 //! An indication of whether the joystick has a POV hat.
\r
638 /** A Windows device will identify the presence or absence of the POV hat.
\r
639 * A Linux device cannot, and will always return POV_HAT_UNKNOWN. */
\r
642 //! A hat is definitely present.
\r
645 //! A hat is definitely not present.
\r
648 //! The presence or absence of a hat cannot be determined.
\r
651 }; // struct SJoystickInfo
\r
654 } // end namespace irr
\r