feat: event system
This commit is contained in:
@@ -5,10 +5,34 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
enum class EventType {
|
||||
INPUT,
|
||||
enum class EventType : unsigned int {
|
||||
// ----- INPUT -----
|
||||
INPUT = 1 << 0,
|
||||
// Mouse
|
||||
MOUSE = 1 << 1,
|
||||
MOUSE_MOVED = 1 << 2,
|
||||
};
|
||||
|
||||
constexpr EventType operator|(EventType a, EventType b) {
|
||||
return static_cast<EventType>(
|
||||
static_cast<unsigned int>(a) |
|
||||
static_cast<unsigned int>(b)
|
||||
);
|
||||
}
|
||||
|
||||
constexpr EventType operator&(EventType a, EventType b) {
|
||||
return static_cast<EventType>(
|
||||
static_cast<unsigned int>(a) &
|
||||
static_cast<unsigned int>(b)
|
||||
);
|
||||
}
|
||||
|
||||
constexpr EventType operator~(EventType a) {
|
||||
return static_cast<EventType>(
|
||||
~static_cast<unsigned int>(a)
|
||||
);
|
||||
}
|
||||
|
||||
struct Event {
|
||||
public:
|
||||
Event();
|
||||
|
||||
@@ -13,4 +13,25 @@ public:
|
||||
EventType GetType() const override;
|
||||
};
|
||||
|
||||
struct MouseEvent : public InputEvent {
|
||||
public:
|
||||
MouseEvent(EventType type);
|
||||
~MouseEvent() = default;
|
||||
|
||||
public:
|
||||
EventType GetType() const override;
|
||||
|
||||
private:
|
||||
EventType m_mouse_type;
|
||||
};
|
||||
|
||||
struct MouseMoveEvent : public MouseEvent {
|
||||
public:
|
||||
MouseMoveEvent(size_t x, size_t y);
|
||||
~MouseMoveEvent() = default;
|
||||
public:
|
||||
size_t x;
|
||||
size_t y;
|
||||
};
|
||||
|
||||
#endif // H_INPUT_EVENT_
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
|
||||
#include "input.h"
|
||||
|
||||
#include <vector>
|
||||
#include <wayland-client-protocol.h>
|
||||
|
||||
#include "event.h"
|
||||
|
||||
class WaylandInputHandler : public InputHandlerImpl {
|
||||
private:
|
||||
static void handle_pointer_enter(void *data,
|
||||
@@ -67,6 +70,8 @@ private:
|
||||
struct wl_pointer_listener m_pointer_listener;
|
||||
wl_fixed_t m_surface_x;
|
||||
wl_fixed_t m_surface_y;
|
||||
private:
|
||||
std::vector<Event*> m_event_queue;
|
||||
};
|
||||
|
||||
#endif // H_WAYLAND_INPUT_
|
||||
|
||||
Reference in New Issue
Block a user