Irrlicht 3D Engine
IEventReceiver.h
Go to the documentation of this file.
00001 // Copyright (C) 2002-2012 Nikolaus Gebhardt
00002 // This file is part of the "Irrlicht Engine".
00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
00004 
00005 #ifndef __I_EVENT_RECEIVER_H_INCLUDED__
00006 #define __I_EVENT_RECEIVER_H_INCLUDED__
00007 
00008 #include "ILogger.h"
00009 #include "Keycodes.h"
00010 #include "irrString.h"
00011 
00012 namespace irr
00013 {
00015     enum EEVENT_TYPE
00016     {
00018 
00022         EET_GUI_EVENT = 0,
00023 
00025 
00030         EET_MOUSE_INPUT_EVENT,
00031 
00033 
00035         EET_KEY_INPUT_EVENT,
00036 
00038 
00045         EET_JOYSTICK_INPUT_EVENT,
00046 
00048 
00050         EET_LOG_TEXT_EVENT,
00051 
00053 
00065         EET_USER_EVENT,
00066 
00069         EGUIET_FORCE_32_BIT = 0x7fffffff
00070 
00071     };
00072 
00074     enum EMOUSE_INPUT_EVENT
00075     {
00077         EMIE_LMOUSE_PRESSED_DOWN = 0,
00078 
00080         EMIE_RMOUSE_PRESSED_DOWN,
00081 
00083         EMIE_MMOUSE_PRESSED_DOWN,
00084 
00086         EMIE_LMOUSE_LEFT_UP,
00087 
00089         EMIE_RMOUSE_LEFT_UP,
00090 
00092         EMIE_MMOUSE_LEFT_UP,
00093 
00095         EMIE_MOUSE_MOVED,
00096 
00099         EMIE_MOUSE_WHEEL,
00100 
00103         EMIE_LMOUSE_DOUBLE_CLICK,
00104 
00107         EMIE_RMOUSE_DOUBLE_CLICK,
00108 
00111         EMIE_MMOUSE_DOUBLE_CLICK,
00112 
00115         EMIE_LMOUSE_TRIPLE_CLICK,
00116 
00119         EMIE_RMOUSE_TRIPLE_CLICK,
00120 
00123         EMIE_MMOUSE_TRIPLE_CLICK,
00124 
00126         EMIE_COUNT
00127     };
00128 
00130     enum E_MOUSE_BUTTON_STATE_MASK
00131     {
00132         EMBSM_LEFT    = 0x01,
00133         EMBSM_RIGHT   = 0x02,
00134         EMBSM_MIDDLE  = 0x04,
00135 
00137         EMBSM_EXTRA1  = 0x08,
00138 
00140         EMBSM_EXTRA2  = 0x10,
00141 
00142         EMBSM_FORCE_32_BIT = 0x7fffffff
00143     };
00144 
00145     namespace gui
00146     {
00147 
00148         class IGUIElement;
00149 
00151         enum EGUI_EVENT_TYPE
00152         {
00154 
00156             EGET_ELEMENT_FOCUS_LOST = 0,
00157 
00159 
00160             EGET_ELEMENT_FOCUSED,
00161 
00163 
00164             EGET_ELEMENT_HOVERED,
00165 
00167 
00168             EGET_ELEMENT_LEFT,
00169 
00171 
00173             EGET_ELEMENT_CLOSED,
00174 
00176             EGET_BUTTON_CLICKED,
00177 
00179             EGET_SCROLL_BAR_CHANGED,
00180 
00182             EGET_CHECKBOX_CHANGED,
00183 
00185 
00186             EGET_LISTBOX_CHANGED,
00187 
00189 
00190             EGET_LISTBOX_SELECTED_AGAIN,
00191 
00193             EGET_FILE_SELECTED,
00194 
00196             EGET_DIRECTORY_SELECTED,
00197 
00199             EGET_FILE_CHOOSE_DIALOG_CANCELLED,
00200 
00202             EGET_MESSAGEBOX_YES,
00203 
00205             EGET_MESSAGEBOX_NO,
00206 
00208             EGET_MESSAGEBOX_OK,
00209 
00211             EGET_MESSAGEBOX_CANCEL,
00212 
00214             EGET_EDITBOX_ENTER,
00215 
00217             EGET_EDITBOX_CHANGED,
00218 
00220             EGET_EDITBOX_MARKING_CHANGED,
00221 
00223             EGET_TAB_CHANGED,
00224 
00226             EGET_MENU_ITEM_SELECTED,
00227 
00229             EGET_COMBO_BOX_CHANGED,
00230 
00232             EGET_SPINBOX_CHANGED,
00233 
00235             EGET_TABLE_CHANGED,
00236             EGET_TABLE_HEADER_CHANGED,
00237             EGET_TABLE_SELECTED_AGAIN,
00238 
00240             EGET_TREEVIEW_NODE_DESELECT,
00241 
00243             EGET_TREEVIEW_NODE_SELECT,
00244 
00246             EGET_TREEVIEW_NODE_EXPAND,
00247 
00249             EGET_TREEVIEW_NODE_COLLAPSE,
00250 
00253             EGET_TREEVIEW_NODE_COLLAPS = EGET_TREEVIEW_NODE_COLLAPSE,
00254 
00256             EGET_COUNT
00257         };
00258     } // end namespace gui
00259 
00260 
00262 struct SEvent
00263 {
00265     struct SGUIEvent
00266     {
00268         gui::IGUIElement* Caller;
00269 
00271         gui::IGUIElement* Element;
00272 
00274         gui::EGUI_EVENT_TYPE EventType;
00275 
00276     };
00277 
00279     struct SMouseInput
00280     {
00282         s32 X;
00283 
00285         s32 Y;
00286 
00288 
00289         f32 Wheel;
00290 
00292         bool Shift:1;
00293 
00295         bool Control:1;
00296 
00300         u32 ButtonStates;
00301 
00303         bool isLeftPressed() const { return 0 != ( ButtonStates & EMBSM_LEFT ); }
00304 
00306         bool isRightPressed() const { return 0 != ( ButtonStates & EMBSM_RIGHT ); }
00307 
00309         bool isMiddlePressed() const { return 0 != ( ButtonStates & EMBSM_MIDDLE ); }
00310 
00312         EMOUSE_INPUT_EVENT Event;
00313     };
00314 
00316     struct SKeyInput
00317     {
00319         wchar_t Char;
00320 
00322         EKEY_CODE Key;
00323 
00325         bool PressedDown:1;
00326 
00328         bool Shift:1;
00329 
00331         bool Control:1;
00332     };
00333 
00335 
00342     struct SJoystickEvent
00343     {
00344         enum
00345         {
00346             NUMBER_OF_BUTTONS = 32,
00347 
00348             AXIS_X = 0, // e.g. analog stick 1 left to right
00349             AXIS_Y,     // e.g. analog stick 1 top to bottom
00350             AXIS_Z,     // e.g. throttle, or analog 2 stick 2 left to right
00351             AXIS_R,     // e.g. rudder, or analog 2 stick 2 top to bottom
00352             AXIS_U,
00353             AXIS_V,
00354             NUMBER_OF_AXES
00355         };
00356 
00359         u32 ButtonStates;
00360 
00369         s16 Axis[NUMBER_OF_AXES];
00370 
00376         u16 POV;
00377 
00379 
00381         u8 Joystick;
00382 
00384         bool IsButtonPressed(u32 button) const
00385         {
00386             if(button >= (u32)NUMBER_OF_BUTTONS)
00387                 return false;
00388 
00389             return (ButtonStates & (1 << button)) ? true : false;
00390         }
00391     };
00392 
00393 
00395     struct SLogEvent
00396     {
00398         const c8* Text;
00399 
00401         ELOG_LEVEL Level;
00402     };
00403 
00405     struct SUserEvent
00406     {
00408         s32 UserData1;
00409 
00411         s32 UserData2;
00412     };
00413 
00414     EEVENT_TYPE EventType;
00415     union
00416     {
00417         struct SGUIEvent GUIEvent;
00418         struct SMouseInput MouseInput;
00419         struct SKeyInput KeyInput;
00420         struct SJoystickEvent JoystickEvent;
00421         struct SLogEvent LogEvent;
00422         struct SUserEvent UserEvent;
00423     };
00424 
00425 };
00426 
00428 
00433 class IEventReceiver
00434 {
00435 public:
00436 
00438     virtual ~IEventReceiver() {}
00439 
00441 
00446     virtual bool OnEvent(const SEvent& event) = 0;
00447 };
00448 
00449 
00451 struct SJoystickInfo
00452 {
00454 
00457     u8              Joystick;
00458 
00460     core::stringc   Name;
00461 
00463     u32             Buttons;
00464 
00466 
00468     u32             Axes;
00469 
00471 
00473     enum
00474     {
00476         POV_HAT_PRESENT,
00477 
00479         POV_HAT_ABSENT,
00480 
00482         POV_HAT_UNKNOWN
00483     } PovHat;
00484 }; // struct SJoystickInfo
00485 
00486 
00487 } // end namespace irr
00488 
00489 #endif
00490