System/SystemEvent: Merge with Input/InputEvent into just Event.
This commit is contained in:
parent
858e721451
commit
10198484e7
12 changed files with 152 additions and 80 deletions
74
include/Spectre/System/Event.h
Normal file
74
include/Spectre/System/Event.h
Normal 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 */
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
#ifndef SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||
#define SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||
|
||||
#include "SystemEvent.h"
|
||||
#include <Spectre/System/Event.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#ifndef SPECTRE_MESSAGE_QUEUE_H
|
||||
#define SPECTRE_MESSAGE_QUEUE_H
|
||||
|
||||
#include <Spectre/System/SystemEvent.h>
|
||||
#include <Spectre/System/Event.h>
|
||||
#include <queue>
|
||||
|
||||
namespace sp {
|
||||
|
|
@ -15,14 +15,14 @@ public :
|
|||
MessageQueue();
|
||||
~MessageQueue();
|
||||
|
||||
void postEvent(SysEvent event);
|
||||
void postEvent(Event event);
|
||||
|
||||
bool pollEvent(SysEvent& event);
|
||||
bool pollEvent(Event& event);
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
protected :
|
||||
std::deque<SysEvent> m_queue;
|
||||
std::deque<Event> m_queue;
|
||||
|
||||
PlatformEventQueue* m_impl;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
|
||||
#ifndef SYSTEM_EVENT_H
|
||||
#define SYSTEM_EVENT_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Display;
|
||||
|
||||
struct SysEvent
|
||||
{
|
||||
public :
|
||||
|
||||
enum Type {
|
||||
None,
|
||||
Quit,
|
||||
Size,
|
||||
};
|
||||
|
||||
Type type;
|
||||
|
||||
struct Size
|
||||
{
|
||||
Display *display;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
union {
|
||||
struct Size size;
|
||||
};
|
||||
|
||||
SysEvent(Type type = None);
|
||||
|
||||
// Helper methods
|
||||
|
||||
static SysEvent sizeEvent(Display *display, int width, int height);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SYSTEM_EVENT_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue