Add EventBase and EventHandleBase

This commit is contained in:
Kirigaya Kazuto 2017-04-05 08:34:01 +08:00
parent f1d9f79ba5
commit 660ae74c52
2 changed files with 74 additions and 2 deletions

View File

@ -1 +1,53 @@
#include "MiniEngine_Event.h"
void EventBase::update(const EventBase& ev)
{
e=ev.e;
}
void MouseMotionEvent::update(const EventBase& ev)
{
EventBase::update(ev);
x=e.motion.x;
y=e.motion.y;
}
void MouseButtonEvent::update(const EventBase& ev)
{
EventBase::update(ev);
x=e.button.x;
y=e.button.y;
}
bool EventHandlerBase::event(const EventBase& ev)
{
switch(ev.e.type)
{
case SDL_MOUSEBUTTONDOWN:
{
MouseButtonEvent eb;
eb.update(ev);
return onMouseDown(eb);
}
break;
case SDL_MOUSEBUTTONUP:
{
MouseButtonEvent eb;
eb.update(ev);
return onMouseUp(eb);
}
break;
}
return false;
}
bool EventHandlerBase::onMouseDown()
{
return false;
}
bool EventHandlerBase::onMouseUp()
{
return false;
}

View File

@ -5,10 +5,30 @@ class EventBase
{
protected:
SDL_Event e;
virtual void update(const EventBase&);
friend class EventHandlerBase;
};
class EventHandler
class MouseMotionEvent : public EventBase
{
public:
virtual bool event(const EventBase&)=0;
int x,y;
void update(const EventBase&);
};
class MouseButtonEvent : public EventBase
{
public:
int x,y;
int button;
void update(const EventBase&);
};
class EventHandlerBase
{
public:
virtual bool event(const EventBase&);
protected:
virtual bool onMouseDown(const MouseButtonEvent&);
virtual bool onMouseUp(const MouseButtonEvent&);
};