mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
Make sure important data is synchronized between ImHex and plugins
This commit is contained in:
71
plugins/libimhex/include/helpers/shared_data.hpp
Normal file
71
plugins/libimhex/include/helpers/shared_data.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <helpers/event.hpp>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace hex { class SharedData; }
|
||||
|
||||
namespace hex::plugin::internal {
|
||||
void initializePlugin(SharedData &sharedData);
|
||||
}
|
||||
|
||||
namespace hex {
|
||||
|
||||
namespace prv { class Provider; }
|
||||
|
||||
class SharedData {
|
||||
SharedData() = default;
|
||||
public:
|
||||
SharedData(const SharedData&) = delete;
|
||||
SharedData(SharedData&&) = delete;
|
||||
|
||||
static auto& get() {
|
||||
static SharedData instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
friend void hex::plugin::internal::initializePlugin(SharedData &sharedData);
|
||||
friend class Window;
|
||||
|
||||
private:
|
||||
|
||||
void initializeData() {
|
||||
static std::vector<EventHandler> eventHandlersStorage;
|
||||
static std::vector<std::function<void()>> deferredCallsStorage;
|
||||
static prv::Provider *currentProviderStorage;
|
||||
static ImVec2 windowPosStorage, windowSizeStorage;
|
||||
|
||||
this->imguiContext = ImGui::GetCurrentContext();
|
||||
this->eventHandlers = &eventHandlersStorage;
|
||||
this->deferredCalls = &deferredCallsStorage;
|
||||
this->currentProvider = ¤tProviderStorage;
|
||||
|
||||
this->windowPos = &windowPosStorage;
|
||||
this->windowSize = &windowSizeStorage;
|
||||
}
|
||||
|
||||
void initializeData(const SharedData &other) {
|
||||
this->imguiContext = other.imguiContext;
|
||||
this->eventHandlers = other.eventHandlers;
|
||||
this->deferredCalls = other.deferredCalls;
|
||||
this->currentProvider = other.currentProvider;
|
||||
|
||||
this->windowPos = other.windowPos;
|
||||
this->windowSize = other.windowSize;
|
||||
}
|
||||
|
||||
public:
|
||||
ImGuiContext *imguiContext;
|
||||
std::vector<EventHandler> *eventHandlers;
|
||||
std::vector<std::function<void()>> *deferredCalls;
|
||||
prv::Provider **currentProvider;
|
||||
|
||||
ImVec2 *windowPos;
|
||||
ImVec2 *windowSize;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user