Finished abstract event system

dev
anulax1225 ago%!(EXTRA string=1 year)
parent 7cdc79b2ee
commit ac3fdd070c
  1. 22
      bakara/src/bakara/core/io_codes.h
  2. 6
      bakara/src/bakara/events/app_event.h
  3. 16
      bakara/src/bakara/events/event.h
  4. 2
      bakara/src/bakara/events/key_event.h
  5. 79
      bakara/src/bakara/events/mouse_event.h
  6. 4
      bakara/src/bakara/events/window_event.h

@ -138,7 +138,27 @@ namespace Bk {
Menu = 348
};
}
using MouseCode = uint16_t;
namespace Mouse {
enum : MouseCode
{
// From glfw3.h
Button0 = 0,
Button1 = 1,
Button2 = 2,
Button3 = 3,
Button4 = 4,
Button5 = 5,
Button6 = 6,
Button7 = 7,
ButtonLast = Button7,
ButtonLeft = Button0,
ButtonRight = Button1,
ButtonMiddle = Button2
};
}
namespace Controller {
enum class Button
{

@ -8,7 +8,7 @@ namespace Bk {
AppTickEvent() = default;
EVENT_CLASS_TYPE(AppTick)
EVENT_CLASS_CATEGORY(AppEvent)
EVENT_CLASS_CATEGORY(AppCategory)
};
class AppRenderEvent : public Event
@ -16,7 +16,7 @@ namespace Bk {
AppRenderEvent() = default;
EVENT_CLASS_TYPE(AppRender)
EVENT_CLASS_CATEGORY(AppEvent)
EVENT_CLASS_CATEGORY(AppCategory)
};
class AppUpdateEvent : public Event
@ -24,6 +24,6 @@ namespace Bk {
AppUpdateEvent() = default;
EVENT_CLASS_TYPE(AppUpdate)
EVENT_CLASS_CATEGORY(AppEvent)
EVENT_CLASS_CATEGORY(AppCategory)
};
}

@ -25,21 +25,21 @@ namespace Bk {
MouseScroll
};
enum class EventCategory
enum EventCategory
{
None = 0,
AppEvent = BIT_SHIFT(0),
InputEvent = BIT_SHIFT(1),
KeyboardEvent = BIT_SHIFT(2),
MouseEvent = BIT_SHIFT(3),
MouseButtonEvent = BIT_SHIFT(4)
AppCategory = BIT_SHIFT(0),
InputCategory = BIT_SHIFT(1),
KeyboardCategory = BIT_SHIFT(2),
MouseCategory = BIT_SHIFT(3),
MouseButtonCategory = BIT_SHIFT(4)
};
#define EVENT_CLASS_TYPE(type) static EventType get_static_type() { return EventType::type; }\
virtual EventType get_event_type() const override { return get_static_type(); }\
virtual const char* get_name() const override { return #type; }
virtual const char* get_name() const override { return BK_STRINGIFY(type); }
#define EVENT_CLASS_CATEGORY(category) virtual int get_category_flags() const override { return (int)EventCategory::category; }
#define EVENT_CLASS_CATEGORY(category) virtual int get_category_flags() const override { return category; }
#define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return format(str, __VA_ARGS__); }

@ -10,7 +10,7 @@ namespace Bk {
public:
KeyCode get_key() const { return m_key; }
EVENT_CLASS_CATEGORY(KeyboardEvent)
EVENT_CLASS_CATEGORY(KeyboardCategory | InputCategory)
protected:
KeyEvent(const KeyCode key)

@ -0,0 +1,79 @@
#pragma once
#include "event.h"
#include <bakara/math/type.h>
#include <bakara/core/io_codes.h>
namespace Bk
{
class MouseMoveEvent : public Event
{
public:
MouseMoveEvent(const float x, const float y)
: p_mouse_x(x), p_mouse_y(y) {}
float get_x() const { return p_mouse_x; }
float get_y() const { return p_mouse_y; }
Vec2 get_pos() const { return Vec2(p_mouse_x, p_mouse_y); }
EVENT_STRINGIFY("MouseMouveEvent : (%f, %f)", p_mouse_x, p_mouse_y)
EVENT_CLASS_TYPE(MouseMove)
EVENT_CLASS_CATEGORY(MouseCategory | InputCategory)
private:
float p_mouse_x;
float p_mouse_y;
};
class MouseScrollEvent : public Event
{
public:
MouseScrollEvent(const float x, const float y)
: p_dx(x), p_dy(y) {}
float get_dx() const { return p_dx; }
float get_dy() const { return p_dy; }
EVENT_STRINGIFY("MouseScrollEvent : (%f, %f)", p_dx, p_dy)
EVENT_CLASS_TYPE(MouseMove)
EVENT_CLASS_CATEGORY(MouseCategory | InputCategory | MouseButtonCategory)
private:
float p_dx;
float p_dy;
};
class MouseButtonEvent : public Event
{
public:
MouseCode get_btn() { return m_btn; }
EVENT_CLASS_CATEGORY(MouseCategory | InputCategory)
protected:
MouseButtonEvent(MouseCode btn)
: m_btn(btn) {}
MouseCode m_btn;
};
class MouseButtonPressEvent : public MouseButtonEvent
{
public:
MouseButtonPressEvent(MouseCode btn)
: MouseButtonEvent(btn) {}
EVENT_STRINGIFY("MouseButtonPressEvent %d", m_btn)
EVENT_CLASS_TYPE(MouseButtonPress)
};
class MouseButtonReleaseEvent : public MouseButtonEvent
{
public:
MouseButtonReleaseEvent(MouseCode btn)
: MouseButtonEvent(btn) {}
EVENT_STRINGIFY("MouseButtonReleaseEvent %d", m_btn)
EVENT_CLASS_TYPE(MouseButtonRelease)
};
}

@ -17,7 +17,7 @@ namespace Bk {
EVENT_STRINGIFY("WindowResizeEvent : %d %d", p_width, p_height)
EVENT_CLASS_TYPE(WindowResize)
EVENT_CLASS_CATEGORY(AppEvent)
EVENT_CLASS_CATEGORY(AppCategory)
private:
uint p_width;
@ -29,6 +29,6 @@ namespace Bk {
WindowCloseEvent() = default;
EVENT_CLASS_TYPE(WindowClose)
EVENT_CLASS_CATEGORY(AppEvent)
EVENT_CLASS_CATEGORY(AppCategory)
};
}
Loading…
Cancel
Save