ImHex/include/views/view.hpp

64 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include <hex.hpp>
#include "imgui.h"
#include "event.hpp"
2020-11-15 23:07:42 +00:00
#include <functional>
#include <string>
2020-11-15 23:07:42 +00:00
#include <vector>
namespace hex {
class View {
public:
View(std::string viewName) : m_viewName(viewName) { }
virtual ~View() { }
virtual void createView() = 0;
virtual void createMenu() { }
2020-11-11 13:41:44 +00:00
virtual bool handleShortcut(int key, int mods) { return false; }
2020-11-15 23:07:42 +00:00
static std::vector<std::function<void()>>& getDeferedCalls() {
return View::s_deferedCalls;
}
2020-11-17 12:58:50 +00:00
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:
2020-11-17 12:58:50 +00:00
void subscribeEvent(Events eventType, std::function<void(const void*)> callback) {
View::s_eventManager.subscribe(eventType, this, callback);
}
void unsubscribeEvent(Events eventType) {
View::s_eventManager.unsubscribe(eventType, this);
}
2020-11-15 23:07:42 +00:00
void doLater(std::function<void()> &&function) {
View::s_deferedCalls.push_back(function);
}
private:
std::string m_viewName;
bool m_windowOpen = false;
static inline EventManager s_eventManager;
2020-11-15 23:07:42 +00:00
static inline std::vector<std::function<void()>> s_deferedCalls;
};
}