Merge branch 'maint-platform' into dev
This commit is contained in:
commit
f86a1ae90c
45 changed files with 1091 additions and 1001 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 */
|
||||
23
include/Spectre/System/EventListener.h
Normal file
23
include/Spectre/System/EventListener.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
#ifndef SYSTEM_EVENT_LISTENER_H
|
||||
#define SYSTEM_EVENT_LISTENER_H
|
||||
|
||||
#include <Spectre/System/Event.h>
|
||||
#include <Spectre/Input/Mouse.h>
|
||||
#include <Spectre/Input/Keyboard.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Display;
|
||||
|
||||
class EventListener
|
||||
{
|
||||
public :
|
||||
virtual void onSizeChanged(Display* display, int width, int height);
|
||||
|
||||
virtual void onEvent(const Event& event);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SYSTEM_EVENT_LISTENER_H */
|
||||
|
|
@ -2,16 +2,25 @@
|
|||
#ifndef SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||
#define SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||
|
||||
#include "SystemEvent.h"
|
||||
#include <vector>
|
||||
#include "EventListener.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Display;
|
||||
|
||||
class MessageHandler
|
||||
class MessageHandler : public EventListener
|
||||
{
|
||||
public :
|
||||
|
||||
void registerListener(EventListener *listener);
|
||||
|
||||
void unregisterListener(EventListener *listener);
|
||||
|
||||
virtual void onSizeChanged(Display* display, int width, int height);
|
||||
|
||||
virtual void onEvent(const Event& event);
|
||||
|
||||
protected :
|
||||
std::vector<EventListener*> m_listeners;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -2,22 +2,29 @@
|
|||
#ifndef SPECTRE_MESSAGE_QUEUE_H
|
||||
#define SPECTRE_MESSAGE_QUEUE_H
|
||||
|
||||
#include <Spectre/System/SystemEvent.h>
|
||||
#include <Spectre/System/Event.h>
|
||||
#include <queue>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class PlatformEventQueue;
|
||||
|
||||
class MessageQueue
|
||||
{
|
||||
public :
|
||||
void postEvent(SysEvent event);
|
||||
MessageQueue();
|
||||
~MessageQueue();
|
||||
|
||||
bool pollEvent(SysEvent& event);
|
||||
void postEvent(Event event);
|
||||
|
||||
bool pollEvent(Event& event);
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
protected :
|
||||
std::deque<SysEvent> m_queue;
|
||||
std::deque<Event> m_queue;
|
||||
|
||||
PlatformEventQueue* m_impl;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -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