1
0
Fork 0

System/SystemEvent: Merge with Input/InputEvent into just Event.

This commit is contained in:
Henrik Hautakoski 2020-01-30 22:40:09 +01:00
parent 858e721451
commit 10198484e7
No known key found for this signature in database
GPG key ID: 96765B12FEAC4745
12 changed files with 152 additions and 80 deletions

View file

@ -0,0 +1,74 @@
#ifndef SPECTRE_SYSTEM_EVENT_H
#define SPECTRE_SYSTEM_EVENT_H
#include <Spectre/Input/Mouse.h>
#include <Spectre/Input/Keyboard.h>
namespace sp {
class Display;
struct Event
{
public :
enum Type {
None,
Quit,
Size,
Key,
MouseButton,
MouseMove
};
struct KeyEvent {
Keyboard::Key code;
bool pressed; /* true if pressed, false if released. */
std::string getKeyName() const; /* Get the key name */
};
struct MouseButtonEvent {
Mouse::Button button;
bool pressed; /* true if pressed, false if released. */
std::string getName() const;
};
struct MouseMoveEvent {
unsigned int x;
unsigned int y;
};
struct SizeEvent
{
Display *display;
int width;
int height;
};
Type type;
union {
struct SizeEvent size;
struct KeyEvent key;
struct MouseMoveEvent mouseMove;
struct MouseButtonEvent mouseButton;
};
Event(Type type = None);
// Helper methods
static Event createSize(Display *display, int width, int height);
static Event createKey(Keyboard::Key code, bool pressed);
static Event createMouseButton(Mouse::Button button, bool pressed);
static Event createMouseMove(unsigned int x, unsigned int y);
};
} // namespace sp
#endif /* SPECTRE_SYSTEM_EVENT_H */