Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give mods access to imgui context #109

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/imgui_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ static std::vector<MenuEntry> menuentries;
static std::mutex menuentrieslock;
static std::vector<std::shared_ptr<ActiveWindow>> activeWindows;
static std::mutex activeWindowsLock;
static std::vector<std::function<void()>> onDrawCallbacks;
static std::mutex onDrawCallbacksLock;

static void convertEntries(std::vector<MenuEntry>& menuentries, size_t length, MenuEntryABI* entries) {
for(size_t i = 0; i < length; i++) {
Expand Down Expand Up @@ -280,6 +282,16 @@ void mcpelauncher_close_window(const char *title) {
activeWindowsLock.unlock();
}

void mcpelauncher_add_draw_callback(void* user, void(*onDraw)(void* user)) {
onDrawCallbacksLock.lock();
onDrawCallbacks.push_back(std::bind(onDraw, user));
onDrawCallbacksLock.unlock();
}

struct ImGuiContext* mcpelauncher_get_imgui_context() {
return ImGui::GetCurrentContext();
}

void ImGuiUIInit(GameWindow* window) {
if(!glGetString) {
return;
Expand Down Expand Up @@ -928,6 +940,12 @@ void ImGuiUIDrawFrame(GameWindow* window) {
activeWindowsLock.unlock();
}

onDrawCallbacksLock.lock();
for(size_t i = 0; i < onDrawCallbacks.size(); i++) {
onDrawCallbacks[i]();
}
onDrawCallbacksLock.unlock();

// Rendering
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
Expand Down
6 changes: 5 additions & 1 deletion src/imgui_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ struct control
};
void mcpelauncher_show_window(const char* title, int isModal, void* user, void(*onClose)(void* user), int count, control* controls);

void mcpelauncher_close_window(const char *title);
void mcpelauncher_close_window(const char *title);

void mcpelauncher_add_draw_callback(void* user, void(*onDraw)(void* user));

struct ImGuiContext* mcpelauncher_get_imgui_context();
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ Hardware : Qualcomm Technologies, Inc MSM8998
{ "mcpelauncher_addmenu", (void*)mcpelauncher_addmenu },
{ "mcpelauncher_show_window", (void*)mcpelauncher_show_window },
{ "mcpelauncher_close_window", (void*)mcpelauncher_close_window },
{ "mcpelauncher_add_draw_callback", (void*)mcpelauncher_add_draw_callback },
{ "mcpelauncher_get_imgui_context", (void*)mcpelauncher_get_imgui_context },
});

ModLoader modLoader;
Expand Down
Loading