1
0
Fork 0
spectre/include/Spectre/System/Event.h

76 lines
1.2 KiB
C++

#ifndef SPECTRE_SYSTEM_EVENT_H
#define SPECTRE_SYSTEM_EVENT_H
#include <Spectre/Input/Mouse.h>
#include <Spectre/Input/Keyboard.h>
namespace sp {
class Window;
struct Event
{
public :
enum Type {
Unknown,
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
{
Window *window;
int width;
int height;
};
Type type;
union {
struct SizeEvent size;
struct KeyEvent key;
struct MouseMoveEvent mouseMove;
struct MouseButtonEvent mouseButton;
};
Event(Type type = Unknown);
std::string toString() const;
// Helper methods
static Event createSize(Window *window, 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 */