#pragma once #include #include "imgui.h" #include "event.hpp" #include #include #include namespace hex { class View { public: View(std::string viewName) : m_viewName(viewName) { } virtual ~View() { } virtual void createView() = 0; virtual void createMenu() { } virtual bool handleShortcut(int key, int mods) { return false; } static std::vector>& getDeferedCalls() { return View::s_deferedCalls; } static void postEvent(Events eventType, const void *userData = nullptr) { View::s_eventManager.post(eventType, userData); } bool& getWindowOpenState() { return this->m_windowOpen; } const std::string getName() const { return this->m_viewName; } protected: void subscribeEvent(Events eventType, std::function callback) { View::s_eventManager.subscribe(eventType, this, callback); } void unsubscribeEvent(Events eventType) { View::s_eventManager.unsubscribe(eventType, this); } void doLater(std::function &&function) { View::s_deferedCalls.push_back(function); } private: std::string m_viewName; bool m_windowOpen = false; static inline EventManager s_eventManager; static inline std::vector> s_deferedCalls; }; }