2020-11-10 15:26:38 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
#include "imgui.h"
|
|
|
|
|
2020-11-12 09:38:52 +01:00
|
|
|
#include "event.hpp"
|
|
|
|
|
2020-11-16 00:07:42 +01:00
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
class View {
|
|
|
|
public:
|
|
|
|
View() { }
|
|
|
|
virtual ~View() { }
|
|
|
|
|
|
|
|
virtual void createView() = 0;
|
|
|
|
virtual void createMenu() { }
|
2020-11-11 14:41:44 +01:00
|
|
|
virtual bool handleShortcut(int key, int mods) { return false; }
|
2020-11-12 09:38:52 +01:00
|
|
|
|
2020-11-16 00:07:42 +01:00
|
|
|
static std::vector<std::function<void()>>& getDeferedCalls() {
|
|
|
|
return View::s_deferedCalls;
|
|
|
|
}
|
|
|
|
|
2020-11-12 09:38:52 +01:00
|
|
|
protected:
|
|
|
|
void subscribeEvent(Events eventType, std::function<void(void*)> callback) {
|
|
|
|
View::s_eventManager.subscribe(eventType, this, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unsubscribeEvent(Events eventType) {
|
|
|
|
View::s_eventManager.unsubscribe(eventType, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void postEvent(Events eventType, void *userData = nullptr) {
|
|
|
|
View::s_eventManager.post(eventType, userData);
|
|
|
|
}
|
|
|
|
|
2020-11-16 00:07:42 +01:00
|
|
|
void doLater(std::function<void()> &&function) {
|
|
|
|
View::s_deferedCalls.push_back(function);
|
|
|
|
}
|
|
|
|
|
2020-11-12 09:38:52 +01:00
|
|
|
private:
|
|
|
|
static inline EventManager s_eventManager;
|
2020-11-16 00:07:42 +01:00
|
|
|
static inline std::vector<std::function<void()>> s_deferedCalls;
|
2020-11-10 15:26:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|