Add MouseMotionEvent. Fix MouseButtonEvent

This commit is contained in:
Kirigaya Kazuto 2017-04-05 12:20:13 +08:00
parent 660ae74c52
commit 0d4b0a534d
2 changed files with 43 additions and 3 deletions

View File

@ -1,5 +1,29 @@
#include "MiniEngine_Event.h"
namespace _MiniEngine_Internal
{
MouseButton _mousebutton_event_enum_caster(int EventInt)
{
switch(EventInt)
{
case SDL_BUTTON_LEFT:
return MouseButton::Left;
case SDL_BUTTON_MIDDLE:
return MouseButton::Middle;
case SDL_BUTTON_RIGHT:
return MouseButton::Right;
case SDL_BUTTON_X1:
return MouseButton::X1;
case SDL_BUTTON_X2:
return MouseButton::X2;
/// If an error occurs, return Left by default.
default:
return MouseButton::Left;
}
}
}/// End of namespace _MiniEngine_Internal
void EventBase::update(const EventBase& ev)
{
e=ev.e;
@ -17,6 +41,7 @@ void MouseButtonEvent::update(const EventBase& ev)
EventBase::update(ev);
x=e.button.x;
y=e.button.y;
button=_MiniEngine_Internal::_mousebutton_event_enum_caster(e.button.button);
}
bool EventHandlerBase::event(const EventBase& ev)
@ -37,17 +62,29 @@ bool EventHandlerBase::event(const EventBase& ev)
return onMouseUp(eb);
}
break;
case SDL_MOUSEMOTION:
{
MouseMotionEvent eb;
eb.update(ev);
return onMouseMotion(eb);
}
break;
}
return false;
}
bool EventHandlerBase::onMouseDown()
bool EventHandlerBase::onMouseDown(const MouseButtonEvent& ev)
{
return false;
}
bool EventHandlerBase::onMouseUp()
bool EventHandlerBase::onMouseUp(const MouseButtonEvent& ev)
{
return false;
}
bool EventHandlerBase::onMouseMotion(const MouseMotionEvent& ev)
{
return false;
}

View File

@ -16,11 +16,13 @@ public:
void update(const EventBase&);
};
enum class MouseButton { Left, Middle, Right, X1, X2 };
class MouseButtonEvent : public EventBase
{
public:
int x,y;
int button;
MouseButton button;
void update(const EventBase&);
};
@ -31,4 +33,5 @@ public:
protected:
virtual bool onMouseDown(const MouseButtonEvent&);
virtual bool onMouseUp(const MouseButtonEvent&);
virtual bool onMouseMotion(const MouseMotionEvent&);
};