im ahving trouble understanding how to use the ieventreciever for gui events: here is the reciever:
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
// Enumeration for UP, DOWN, PRESSED and RELEASED key states. Also used for mouse button states.
enum keyStatesENUM {UP, DOWN, PRESSED, RELEASED};
// Keyboard key states.
keyStatesENUM keyState[KEY_KEY_CODES_COUNT];
// Mouse data.
struct mouseData
{
int X;
int Y;
bool LButtonDown;
bool RButtonDown;
bool MButtonDown;
float Wheel;
float WheelDelta;
};
struct mouseData m_Mouse;
int MouseX() { return m_Mouse.X; };
int MouseY() { return m_Mouse.Y; };
float MouseWheel() { return m_Mouse.Wheel; };
float MouseWheelDelta() { return m_Mouse.WheelDelta; };
MyEventReceiver(void)
{
for (int i = 0; i < KEY_KEY_CODES_COUNT; i++) keyState[i] = RELEASED;
m_Mouse.X = 0;
m_Mouse.Y = 0;
m_Mouse.Wheel = 0;
m_Mouse.WheelDelta = 0;
m_Mouse.LButtonDown = false;
m_Mouse.RButtonDown = false;
m_Mouse.MButtonDown = false;
};
virtual ~MyEventReceiver(void) {};
// keyboard events
virtual bool OnKeyInputEvent(const SEvent& e) { return false; };
virtual bool IsKeyPressed(char keycode) { return (keyState[keycode] == PRESSED); };
virtual bool IsKeyDown(char keycode) { return (keyState[keycode] == DOWN || keyState[keycode] == PRESSED); };
virtual bool IsKeyUp(char keycode) { return (keyState[keycode] == UP || keyState[keycode] == RELEASED); };
virtual bool IsKeyReleased(char keycode) { return (keyState[keycode] == RELEASED); };
// guievents
virtual bool OnButtonClicked(const SEvent& e) { return false; };
virtual bool OnScrollBarChanged(const SEvent& e) { return false; };
virtual bool OnCheckBoxChanged(const SEvent& e) { return false; };
virtual bool OnListBoxChanged(const SEvent& e) { return false; };
virtual bool OnListBoxSelectedAgain(const SEvent& e) { return false; };
virtual bool OnFileSelected(const SEvent& e) { return false; };
virtual bool OnMessageBoxYes(const SEvent& e) { return false; };
virtual bool OnMessageBoxNo(const SEvent& e) { return false; };
virtual bool OnMessageBoxOk(const SEvent& e) { return false; };
virtual bool OnMessageBoxCancel(const SEvent& e) { return false; };
virtual bool OnEditBoxEnter(const SEvent& e) { return false; };
virtual bool OnTabChanged(const SEvent& e) { return false; };
virtual bool OnComboBoxChanged(const SEvent& e) { return false; };
virtual bool OnSpinBoxChanged(const SEvent& e) { return false; };
// mouse events
virtual bool OnLMousePressedDown(const SEvent& e) { return false; };
virtual bool OnRMousePressedDown(const SEvent& e) { return false; };
virtual bool OnMMousePressedDown(const SEvent& e) { return false; };
virtual bool OnLMouseLeftUp(const SEvent& e) { return false; };
virtual bool OnRMouseLeftUp(const SEvent& e) { return false; };
virtual bool OnMMouseLeftUp(const SEvent& e) { return false; };
virtual bool OnMouseMoved(const SEvent& e) { return false; };
virtual bool OnMouseWheel(const SEvent& e) { return false; };
// user events
virtual bool OnUserEvent(const SEvent& e) { return false; };
virtual bool OnEvent(const SEvent& e)
{
switch (e.EventType)
{
case EET_KEY_INPUT_EVENT :
{
if (e.KeyInput.PressedDown == true)
{
if (keyState[e.KeyInput.Key] != DOWN)
keyState[e.KeyInput.Key] = PRESSED;
else keyState[e.KeyInput.Key] = DOWN;
}
else
if (keyState[e.KeyInput.Key] != UP)
keyState[e.KeyInput.Key] = RELEASED;
if (e.KeyInput.PressedDown == true) return OnKeyInputEvent(e);
} break;
case EET_GUI_EVENT :
{
switch (e.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED : return OnButtonClicked(e);
case EGET_SCROLL_BAR_CHANGED : return OnScrollBarChanged(e);
case EGET_CHECKBOX_CHANGED : return OnCheckBoxChanged(e);
case EGET_LISTBOX_CHANGED : return OnListBoxChanged(e);
case EGET_LISTBOX_SELECTED_AGAIN : return OnListBoxSelectedAgain(e);
case EGET_FILE_SELECTED : return OnFileSelected(e);
case EGET_MESSAGEBOX_YES : return OnMessageBoxYes(e);
case EGET_MESSAGEBOX_NO : return OnMessageBoxNo(e);
case EGET_MESSAGEBOX_OK : return OnMessageBoxOk(e);
case EGET_MESSAGEBOX_CANCEL : return OnMessageBoxCancel(e);
case EGET_EDITBOX_ENTER : return OnEditBoxEnter(e);
case EGET_TAB_CHANGED : return OnTabChanged(e);
case EGET_COMBO_BOX_CHANGED : return OnComboBoxChanged(e);
case EGET_SPINBOX_CHANGED : return OnSpinBoxChanged(e);
default : return false;
}
} break;
case EET_MOUSE_INPUT_EVENT :
{
m_Mouse.X = e.MouseInput.X;
m_Mouse.Y = e.MouseInput.Y;
switch (e.MouseInput.Event)
{
case EMIE_LMOUSE_PRESSED_DOWN : m_Mouse.LButtonDown = true; return OnLMousePressedDown(e);
case EMIE_RMOUSE_PRESSED_DOWN : m_Mouse.RButtonDown = true; return OnRMousePressedDown(e);
case EMIE_MMOUSE_PRESSED_DOWN : m_Mouse.MButtonDown = true; return OnMMousePressedDown(e);
case EMIE_LMOUSE_LEFT_UP : m_Mouse.LButtonDown = false; return OnLMouseLeftUp(e);
case EMIE_RMOUSE_LEFT_UP : m_Mouse.RButtonDown = false; return OnRMouseLeftUp(e);
case EMIE_MMOUSE_LEFT_UP : m_Mouse.MButtonDown = false; return OnMMouseLeftUp(e);
case EMIE_MOUSE_MOVED : return OnMouseMoved(e);
case EMIE_MOUSE_WHEEL :
{
m_Mouse.WheelDelta = m_Mouse.Wheel - e.MouseInput.Wheel;
m_Mouse.Wheel += e.MouseInput.Wheel;
return OnMouseWheel(e);
}
default : return false;
}
} break;
case EET_USER_EVENT :
{
return OnUserEvent(e);
default : return false;
} break;
}
return false;
}
};
e.g.
if(receiver.onguibtnclick(GUI_ID_OR_SOMETHING))
{
//do stuff
}
thanks,