mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Switch to a custom event system, where SDL pumps into
To do this we needed to take ThreadVariant out of love.thread, and move it to common. This also changes event names, instead of 1/2-letter abbreviations, full names!
This commit is contained in:
+26
-54
@@ -24,77 +24,49 @@
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include <common/StringMap.h>
|
||||
#include <common/Variant.h>
|
||||
#include <keyboard/Keyboard.h>
|
||||
#include <mouse/Mouse.h>
|
||||
|
||||
// STL
|
||||
#include <queue>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
class Message : public Object
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
Variant **args;
|
||||
int nargs;
|
||||
|
||||
public:
|
||||
Message(std::string name, int nargs, ...);
|
||||
~Message();
|
||||
|
||||
int toLua(lua_State *L);
|
||||
static Message *fromLua(lua_State *L, int n);
|
||||
};
|
||||
|
||||
class Event : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
TYPE_INVALID,
|
||||
TYPE_KEY_PRESSED,
|
||||
TYPE_KEY_RELEASED,
|
||||
TYPE_MOUSE_PRESSED,
|
||||
TYPE_MOUSE_RELEASED,
|
||||
TYPE_JOYSTICK_RELEASED,
|
||||
TYPE_JOYSTICK_PRESSED,
|
||||
TYPE_FOCUS,
|
||||
TYPE_QUIT,
|
||||
TYPE_MAX_ENUM = 32
|
||||
};
|
||||
|
||||
union Message
|
||||
{
|
||||
Type type;
|
||||
|
||||
struct
|
||||
{
|
||||
Type type;
|
||||
love::mouse::Mouse::Button b;
|
||||
unsigned x;
|
||||
unsigned y;
|
||||
} mouse;
|
||||
|
||||
struct
|
||||
{
|
||||
Type type;
|
||||
unsigned index;
|
||||
unsigned button;
|
||||
} joystick;
|
||||
|
||||
struct
|
||||
{
|
||||
Type type;
|
||||
love::keyboard::Keyboard::Key k;
|
||||
unsigned short u;
|
||||
} keyboard;
|
||||
|
||||
struct
|
||||
{
|
||||
Type type;
|
||||
bool f;
|
||||
} focus;
|
||||
};
|
||||
|
||||
virtual ~Event();
|
||||
|
||||
static bool getConstant(const char * in, Type & out);
|
||||
static bool getConstant(Type in, const char *& out);
|
||||
void push(Message *msg);
|
||||
bool poll(Message *&msg);
|
||||
|
||||
virtual void pump() = 0;
|
||||
|
||||
static bool getConstant(const char * in, love::mouse::Mouse::Button & out);
|
||||
static bool getConstant(love::mouse::Mouse::Button in, const char *& out);
|
||||
static bool getConstant(const char * in, love::keyboard::Keyboard::Key & out);
|
||||
static bool getConstant(love::keyboard::Keyboard::Key in, const char *& out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, TYPE_MAX_ENUM> types;
|
||||
protected:
|
||||
std::queue<Message*> queue;
|
||||
static StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry buttonEntries[];
|
||||
static StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM> buttons;
|
||||
static StringMap<love::keyboard::Keyboard::Key, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry keyEntries[];
|
||||
|
||||
Reference in New Issue
Block a user