Irrlicht_0.1源码学习(4)—include/irrTypes.h & include/IeventReceiver.h
irrTypes.h这个文件做的事很简单,通过一系列typedef操作定义了Irrlicht引擎中的所有基本数据类型,以保证引擎的可移植性。
IeventReceiver.h则定义了一些用于事件系统中的枚举和结构/类。其中包含了EEVENT_TYPE、EMOUSE_INPUT_EVENT、EGUI_EVENT_TYPE三种枚举类型以及SEvent结构和IEventReceiver类。
EEVENT_TYPE:用于枚举irrlicht引擎中所有的事件类型(gui事件、鼠标事件、键盘事件)
//! Enumeration for all event types there are. enum EEVENT_TYPE { //! An event of the graphical user interface. EET_GUI_EVENT = 0, //! A mouse input event. EET_MOUSE_INPUT_EVENT, //! A key input evant. EET_KEY_INPUT_EVENT };
EMOUSE_INPUT_EVENT:用于枚举所有的鼠标输入事件
//! Enumeration for all mouse input events enum EMOUSE_INPUT_EVENT { //! Left mouse button was pressed down. EMIE_LMOUSE_PRESSED_DOWN = 0, //! Right mouse button was pressed down. EMIE_RMOUSE_PRESSED_DOWN, //! Middle mouse button was pressed down. EMIE_MMOUSE_PRESSED_DOWN, //! Left mouse button was left up. EMIE_LMOUSE_LEFT_UP, //! Right mouse button was left up. EMIE_RMOUSE_LEFT_UP, //! Middle mouse button was left up. EMIE_MMOUSE_LEFT_UP, //! The mouse cursor changed its position. EMIE_MOUSE_MOVED };
EGUI_EVENT_TYPE:用于枚举所有由gui系统投递出的事件
//! Enumeration for all events which are sendable by the gui system enum EGUI_EVENT_TYPE { //! A gui element has lost its key focus. EGET_ELEMENT_KEY_FOCUS_LOST = 0, //! A gui element has lost its mouse focus. EGET_ELEMENT_MOUSE_FOCUS_LOST, //! A gui element was hovered. EGET_ELEMENT_HOVERED, //! A button was clicked. EGET_BUTTON_CLICKED, //! A scrollbar has changed its position. EGET_SCROLL_BAR_CHANGED, //! A checkbox has changed its check state. EGET_CHECKBOX_CHANGED, //! A new item in a listbox was seleted. EGET_LISTBOX_CHANGED, /! An item in the listbox was selected, which was already selected. EGET_LISTBOX_SELECTED_AGAIN, };
SEvent:用于储存各类事件相关数据的结构体,其实现中使用union优化内存占用情况
//! Struct for holding event data. An event can be a gui, mouse or keyboard event. struct SEvent { EEVENT_TYPE EventType; union { struct { gui::IGUIElement* Caller; gui::EGUI_EVENT_TYPE EventType; } GUIEvent; struct { s32 X, Y; // mouse positions; EMOUSE_INPUT_EVENT Event; } MouseInput; struct { s32 Key; // TODO key bool PressedDown; // if not pressed, then left up } KeyInput; }; };
IEventReceiver:所有能够接收事件的对象必须实现的接口类,内部声明了一个处理各类事件的纯虚函数(OnEvent)
//! Interface of an object wich can receive events. class IEventReceiver { public: //! called if an event happened. returns true if event was processed virtual bool OnEvent(SEvent event) = 0; };