1
0
mirror of synced 2024-12-14 16:52:53 +01:00
ImHex/plugins/libimhex/include/hex/api/event.hpp

47 lines
1.0 KiB
C++
Raw Normal View History

#pragma once
2021-01-11 21:11:03 +01:00
#include <hex.hpp>
2021-01-21 10:53:12 +01:00
#include <any>
#include <functional>
2021-01-21 10:53:12 +01:00
#include <vector>
namespace hex {
2021-01-11 21:11:03 +01:00
enum class Events : u32 {
FileLoaded,
DataChanged,
PatternChanged,
FileDropped,
WindowClosing,
RegionSelected,
SelectionChangeRequest,
AddBookmark,
AppendPatternLanguageCode,
ProjectFileStore,
ProjectFileLoad,
2021-01-11 21:11:03 +01:00
SettingsChanged,
/* This is not a real event but a flag to show all events after this one are plugin ones */
Events_BuiltinEnd
};
struct EventHandler {
void *owner;
Events eventType;
2021-01-21 10:53:12 +01:00
std::function<std::any(const std::any&)> callback;
};
class EventManager {
public:
2021-01-21 10:53:12 +01:00
static std::vector<std::any> post(Events eventType, const std::any &userData);
static void subscribe(Events eventType, void *owner, std::function<std::any(const std::any&)> callback);
static void unsubscribe(Events eventType, void *sender);
};
}