parent
f346726644
commit
ee4df2592a
6 changed files with 126 additions and 59 deletions
@ -1,24 +0,0 @@ |
||||
#include "event.h" |
||||
|
||||
namespace Bk { |
||||
EventDispatcher::EventDispatcher(Event& event)
|
||||
{ |
||||
p_event = event; |
||||
} |
||||
|
||||
bool ventDispatcher::Dispatch(const F& func) |
||||
{ |
||||
if (p_event.GetEventType() == T::GetStaticType()) |
||||
{ |
||||
p_event.handled |= func(static_cast<T&>(p_event)); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, Event& e)
|
||||
{ |
||||
return os << e.ToString(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,59 @@ |
||||
#pragma once |
||||
|
||||
|
||||
#include <bakara/core/key_codes.h> |
||||
#include "event.h" |
||||
|
||||
namespace Bk { |
||||
class KeyEvent : public Event
|
||||
{ |
||||
public: |
||||
KeyCode get_key() const { return m_key; } |
||||
|
||||
EVENT_CLASS_CATEGORY(KeyboardEvent) |
||||
|
||||
protected:
|
||||
KeyEvent(const KeyCode key) |
||||
: m_key(key) {} |
||||
|
||||
KeyCode m_key; |
||||
};
|
||||
|
||||
class KeyPressEvent : public KeyEvent
|
||||
{ |
||||
public: |
||||
KeyPressEvent(KeyCode key, bool is_repeated = false) |
||||
: KeyEvent(key), p_is_repeated(is_repeated) {} |
||||
|
||||
EVENT_CLASS_TYPE(KeyPress) |
||||
|
||||
EVENT_STRINGIFY("KeyPressEvent: %d repeat : %b", m_key, p_is_repeated) |
||||
|
||||
bool is_repeated() { return p_is_repeated; } |
||||
|
||||
private:
|
||||
bool p_is_repeated; |
||||
}; |
||||
|
||||
class KeyReleaseEvent : public KeyEvent
|
||||
{ |
||||
public: |
||||
KeyReleaseEvent(KeyCode key) |
||||
: KeyEvent(key) {} |
||||
|
||||
EVENT_CLASS_TYPE(KeyRelease) |
||||
|
||||
EVENT_STRINGIFY("KeyReleaseEvent: %d", m_key) |
||||
}; |
||||
|
||||
class KeyTypedEvent : public KeyEvent |
||||
{ |
||||
public: |
||||
KeyTypedEvent(const KeyCode keycode) |
||||
: KeyEvent(keycode) {} |
||||
|
||||
EVENT_CLASS_TYPE(KeyTyped) |
||||
|
||||
EVENT_STRINGIFY("KeyTypedEvent: %d", m_key) |
||||
}; |
||||
} |
@ -1,30 +1,34 @@ |
||||
pragma once |
||||
#pragma once |
||||
|
||||
#include <bkpch.h> |
||||
#include <format> |
||||
#include "event.h" |
||||
|
||||
namespace Bk { |
||||
class WindowResizeEvent : public Event
|
||||
{ |
||||
public: |
||||
WindowResizeEvent(uint width, uint height) |
||||
: p_width(width), p_height(height) {}; |
||||
|
||||
}
|
||||
uint get_width() const { return p_width; } |
||||
uint get_height() const { return p_height; } |
||||
|
||||
class WindowCloseEvent : public Event
|
||||
{ |
||||
EVENT_STRINGIFY("WindowResizeEvent : %d %d", p_width, p_height) |
||||
|
||||
} |
||||
EVENT_CLASS_TYPE(WindowResize) |
||||
EVENT_CLASS_CATEGORY(AppEvent) |
||||
|
||||
class WindowFocusEvent : public Event
|
||||
{ |
||||
|
||||
} |
||||
private:
|
||||
uint p_width; |
||||
uint p_height; |
||||
};
|
||||
|
||||
class WindowLostFocusEvent : public Event
|
||||
class WindowCloseEvent : public Event
|
||||
{ |
||||
WindowCloseEvent() = default; |
||||
|
||||
} |
||||
|
||||
class WindowMoveEvent : public Event
|
||||
{ |
||||
|
||||
} |
||||
EVENT_CLASS_TYPE(WindowClose) |
||||
EVENT_CLASS_CATEGORY(AppEvent) |
||||
}; |
||||
} |
Loading…
Reference in New Issue