/** AsterTrack Configurator Copyright (C) 2023 Seneral and contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #include "imgui.h" #endif #include "imgui_internal.h" #include "imgui_onDemand.hpp" #include "backends/imgui_impl_opengl3.h" #include "GL/glew.h" std::vector onDemandStack; void OnDemandNewFrame() { onDemandStack.clear(); } OnDemandState &MarkOnDemandArea(const ImRect &bb) { OnDemandState state; state.pos = bb.Min; state.clipMin = bb.Min; state.clipMax = bb.Max; state.viewport = ImGui::GetWindowViewport(); onDemandStack.push_back(state); return onDemandStack.back(); } OnDemandState &AddOnDemandItem(ImGuiID id, const ImRect &bb) { ImGui::ItemSize(bb, 0.0f); ImGui::ItemAdd(bb, id); return MarkOnDemandArea(bb); } void AddOnDemandRender(ImGuiID id, const ImVec4 &bb, ImDrawCallback RenderCallback, void *userData) { ImGuiWindow* window = ImGui::GetCurrentWindow(); if (window->SkipItems) return; OnDemandState &state = AddOnDemandItem(id, ImRect(bb)); state.userData = userData; window->DrawList->AddCallback(RenderCallback, &state); window->DrawList->AddCallback(ImDrawCallback_ResetRenderState, nullptr); } void AddOnDemandText(const char* maxText, ImDrawCallback RenderCallback) { ImGuiWindow* window = ImGui::GetCurrentWindow(); if (window->SkipItems) return; const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); const ImVec2 text_size = ImGui::CalcTextSize(maxText, NULL, true, 0.0f); OnDemandState &state = AddOnDemandItem(ImGui::GetID(maxText), ImRect(text_pos, text_pos + text_size)); state.font = ImGui::GetFont(); state.fontSize = ImGui::GetFontSize(); window->DrawList->AddCallback(RenderCallback, &state); } void RenderOnDemandText(const OnDemandState &state, const char* fmt, ...) { va_list args; va_start(args, fmt); RenderOnDemandTextV(state, fmt, args); va_end(args); } void RenderOnDemandTextV(const OnDemandState &state, const char* fmt, va_list args) { const char* text, *text_end; ImFormatStringToTempBufferV(&text, &text_end, fmt, args); static ImDrawList onDemandDrawList(ImGui::GetDrawListSharedData()); onDemandDrawList._ResetForNewFrame(); onDemandDrawList.PushClipRect(state.clipMin, state.clipMax, false); onDemandDrawList.PushTextureID(state.font->ContainerAtlas->TexID); onDemandDrawList.AddText(state.font, state.fontSize, state.pos, ImGui::GetColorU32(ImGuiCol_Text), text, text_end); onDemandDrawList.PopTextureID(); onDemandDrawList.PopClipRect(); ImGui_ImplOpenGL3_RenderDrawList(state.viewport, &onDemandDrawList); }