Prepering event handling from application side

dev
anulax1225 ago%!(EXTRA string=1 year)
parent 89345a3168
commit 508b36bd71
  1. 6
      bakara/src/bakara/core/application.cpp
  2. 6
      bakara/src/bakara/core/application.h
  3. 15
      bakara/src/bakara/events/event.h
  4. 8
      bakara/src/bakara/events/window_event.h

@ -4,10 +4,16 @@ namespace Bk {
Application::Application()
{
p_window = Window::create_window();
p_window->set_event_callback(BK_BIND_EVENT_FN(Application::on_event));
}
Application::~Application() { }
void Application::on_event(Event& e)
{
BK_CORE_INFO("Event : {0}", EVENT_STRING(e));
}
void Application::run()
{
while (p_running)

@ -2,14 +2,18 @@
#include <bkpch.h>
#include "window.h"
#include <bakara/events/event.h>
namespace Bk {
#define BK_BIND_EVENT_FN(fn) std::bind(&fn, this, std::placeholders::_1)
class Application
{
public:
Application();
virtual ~Application();
void on_event(Event& e);
void run();
private:
std::unique_ptr<Window> p_window;

@ -40,8 +40,16 @@ namespace Bk {
virtual const char* get_name() const override { return BK_STRINGIFY(type); }
#define EVENT_CLASS_CATEGORY(category) virtual int get_category_flags() const override { return category; }
#ifdef BK_DEBUG
#define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return format(str, __VA_ARGS__); }
#define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return format(str, __VA_ARGS__); }
#define EVENT_STRING(event) event.to_string()
#else
#define EVENT_STRINGIFY(str, ...)
#define EVENT_STRING(event)
#endif
class Event
{
@ -62,11 +70,6 @@ namespace Bk {
}
};
inline std::ostream& operator<<(std::ostream& os, Event& e)
{
return os << e.to_string();
}
class EventDispatcher
{
public:

@ -25,9 +25,11 @@ namespace Bk {
class WindowCloseEvent : public Event
{
WindowCloseEvent() = default;
public:
WindowCloseEvent() = default;
EVENT_CLASS_TYPE(WindowClose)
EVENT_CLASS_CATEGORY(AppCategory)
EVENT_CLASS_TYPE(WindowClose)
EVENT_CLASS_CATEGORY(AppCategory)
EVENT_STRINGIFY("Window closing%s", ".")
};
}
Loading…
Cancel
Save