mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-19 04:36:45 +00:00
Split Event out to separate file.
This commit is contained in:
parent
96e456ee09
commit
2b5d574ac7
4 changed files with 40 additions and 30 deletions
|
@ -2,38 +2,12 @@
|
||||||
#define MANGLE_INPUT_DRIVER_H
|
#define MANGLE_INPUT_DRIVER_H
|
||||||
|
|
||||||
#include "../tools/shared_ptr.hpp"
|
#include "../tools/shared_ptr.hpp"
|
||||||
|
#include "event.hpp"
|
||||||
|
|
||||||
namespace Mangle
|
namespace Mangle
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace Input
|
||||||
{
|
{
|
||||||
/** Generic callback for input events. The meaning of the
|
|
||||||
parameters depend on the system producing the events.
|
|
||||||
*/
|
|
||||||
struct Event
|
|
||||||
{
|
|
||||||
/// Event types
|
|
||||||
enum EventType
|
|
||||||
{
|
|
||||||
EV_Unknown = -1, // Unknown event type
|
|
||||||
EV_KeyDown = 1, // Key, mouse or other button was pressed
|
|
||||||
EV_KeyUp = 2, // Key, mouse or other button was released
|
|
||||||
EV_MouseMove = 3, // Mouse movement (all axis movement?)
|
|
||||||
EV_Other = 4 // Other event
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Called upon all events. The first parameter give the event
|
|
||||||
type, the second gives additional data (usually the local
|
|
||||||
keysym as defined by the driver), and the pointer points to
|
|
||||||
the full custom event structure provided by the driver (the
|
|
||||||
type may vary depending on the EventType, this is defined in
|
|
||||||
the Driver documentation.)
|
|
||||||
*/
|
|
||||||
virtual void event(EventType type, int index, const void *p) = 0;
|
|
||||||
virtual ~Event() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Input::Driver is the main interface to any input system that
|
/** Input::Driver is the main interface to any input system that
|
||||||
handles keyboard and/or mouse input, along with any other
|
handles keyboard and/or mouse input, along with any other
|
||||||
input source like joysticks.
|
input source like joysticks.
|
||||||
|
@ -78,7 +52,7 @@ namespace Mangle
|
||||||
can also be called from the outside to "fake" events from
|
can also be called from the outside to "fake" events from
|
||||||
this driver.
|
this driver.
|
||||||
*/
|
*/
|
||||||
void makeEvent(Event::EventType type, int index, const void *p=NULL)
|
void makeEvent(Event::Type type, int index, const void *p=NULL)
|
||||||
{
|
{
|
||||||
if(event)
|
if(event)
|
||||||
event->event(type,index,p);
|
event->event(type,index,p);
|
||||||
|
|
36
input/event.hpp
Normal file
36
input/event.hpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef MANGLE_INPUT_EVENT_H
|
||||||
|
#define MANGLE_INPUT_EVENT_H
|
||||||
|
|
||||||
|
namespace Mangle
|
||||||
|
{
|
||||||
|
namespace Input
|
||||||
|
{
|
||||||
|
/** Generic callback for input events. The meaning of the
|
||||||
|
parameters depend on the system producing the events.
|
||||||
|
*/
|
||||||
|
struct Event
|
||||||
|
{
|
||||||
|
/// Event types
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
EV_Unknown = -1, // Unknown event type
|
||||||
|
EV_KeyDown = 1, // Key, mouse or other button was pressed
|
||||||
|
EV_KeyUp = 2, // Key, mouse or other button was released
|
||||||
|
EV_MouseMove = 3, // Mouse movement (all axis movement?)
|
||||||
|
EV_Other = 4 // Other event
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called upon all events. The first parameter give the event
|
||||||
|
type, the second gives additional data (usually the local
|
||||||
|
keysym as defined by the driver), and the pointer points to
|
||||||
|
the full custom event structure provided by the driver (the
|
||||||
|
type may vary depending on the EventType, this is defined in
|
||||||
|
the Driver documentation.)
|
||||||
|
*/
|
||||||
|
virtual void event(Type type, int index, const void *p) = 0;
|
||||||
|
virtual ~Event() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -10,7 +10,7 @@ void SDLDriver::capture()
|
||||||
SDL_Event evt;
|
SDL_Event evt;
|
||||||
while(SDL_PollEvent(&evt))
|
while(SDL_PollEvent(&evt))
|
||||||
{
|
{
|
||||||
Event::EventType type = Event::EV_Unknown;
|
Event::Type type = Event::EV_Unknown;
|
||||||
int index = -1;
|
int index = -1;
|
||||||
|
|
||||||
switch(evt.type)
|
switch(evt.type)
|
||||||
|
|
|
@ -8,7 +8,7 @@ Driver *input;
|
||||||
|
|
||||||
struct MyCB : Event
|
struct MyCB : Event
|
||||||
{
|
{
|
||||||
void event(Event::EventType type, int i, const void *p)
|
void event(Event::Type type, int i, const void *p)
|
||||||
{
|
{
|
||||||
cout << "got event: type=" << type << " index=" << i << endl;
|
cout << "got event: type=" << type << " index=" << i << endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue