Recreate imgui environment when scale or zoom changes
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
96c64ba7a9
commit
4d7b1fc40f
2 changed files with 36 additions and 21 deletions
|
|
@ -75,6 +75,7 @@ struct ImGuiWidget::PrivateData {
|
||||||
bool useMonospacedFont = false;
|
bool useMonospacedFont = false;
|
||||||
float originalScaleFactor = 0.0f;
|
float originalScaleFactor = 0.0f;
|
||||||
float scaleFactor = 0.0f;
|
float scaleFactor = 0.0f;
|
||||||
|
double lastFrameTime = 0.0;
|
||||||
|
|
||||||
PrivateData()
|
PrivateData()
|
||||||
{
|
{
|
||||||
|
|
@ -135,6 +136,32 @@ struct ImGuiWidget::PrivateData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resetEverything(const bool doInit)
|
||||||
|
{
|
||||||
|
if (created)
|
||||||
|
{
|
||||||
|
ImGui::SetCurrentContext(context);
|
||||||
|
ImGui_ImplOpenGL2_Shutdown();
|
||||||
|
created = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fontGenerated = false;
|
||||||
|
originalScaleFactor = 0.0f;
|
||||||
|
scaleFactor = 0.0f;
|
||||||
|
lastFrameTime = 0.0;
|
||||||
|
ImGui::DestroyContext(context);
|
||||||
|
|
||||||
|
context = ImGui::CreateContext();
|
||||||
|
ImGui::SetCurrentContext(context);
|
||||||
|
setupIO();
|
||||||
|
|
||||||
|
if (doInit)
|
||||||
|
{
|
||||||
|
ImGui_ImplOpenGL2_Init();
|
||||||
|
created = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void resetStyle()
|
void resetStyle()
|
||||||
{
|
{
|
||||||
ImGuiStyle& style(ImGui::GetStyle());
|
ImGuiStyle& style(ImGui::GetStyle());
|
||||||
|
|
@ -351,32 +378,17 @@ void ImGuiWidget::onSelectText(const SelectTextEvent& e)
|
||||||
|
|
||||||
void ImGuiWidget::drawFramebuffer()
|
void ImGuiWidget::drawFramebuffer()
|
||||||
{
|
{
|
||||||
const float scaleFactor = APP->window->pixelRatio;
|
const float scaleFactor = APP->window->pixelRatio * std::max(1.0f, APP->scene->rack->getAbsoluteZoom());
|
||||||
|
|
||||||
|
if (d_isNotEqual(imData->scaleFactor, scaleFactor))
|
||||||
|
imData->resetEverything(true);
|
||||||
|
|
||||||
drawFramebufferCommon(getFramebufferSize(), scaleFactor);
|
drawFramebufferCommon(getFramebufferSize(), scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiWidget::drawFramebufferForBrowserPreview()
|
void ImGuiWidget::drawFramebufferForBrowserPreview()
|
||||||
{
|
{
|
||||||
if (imData->created)
|
imData->resetEverything(true);
|
||||||
{
|
|
||||||
ImGui::SetCurrentContext(imData->context);
|
|
||||||
ImGui_ImplOpenGL2_Shutdown();
|
|
||||||
ImGui::DestroyContext(imData->context);
|
|
||||||
|
|
||||||
imData->created = false;
|
|
||||||
imData->fontGenerated = false;
|
|
||||||
imData->originalScaleFactor = 0.0f;
|
|
||||||
imData->scaleFactor = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
imData->context = ImGui::CreateContext();
|
|
||||||
ImGui::SetCurrentContext(imData->context);
|
|
||||||
setupIO();
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL2_Init();
|
|
||||||
imData->created = true;
|
|
||||||
|
|
||||||
drawFramebufferCommon(box.size.mult(oversample), oversample);
|
drawFramebufferCommon(box.size.mult(oversample), oversample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,7 +434,9 @@ void ImGuiWidget::drawFramebufferCommon(const Vec& fbSize, const float scaleFact
|
||||||
imData->created = true;
|
imData->created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO io.DeltaTime
|
const double time = glfwGetTime();
|
||||||
|
io.DeltaTime = time - imData->lastFrameTime;
|
||||||
|
imData->lastFrameTime = time;
|
||||||
|
|
||||||
ImGui_ImplOpenGL2_NewFrame();
|
ImGui_ImplOpenGL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ protected:
|
||||||
void onButton(const ButtonEvent& e) override;
|
void onButton(const ButtonEvent& e) override;
|
||||||
void onSelectKey(const SelectKeyEvent& e) override;
|
void onSelectKey(const SelectKeyEvent& e) override;
|
||||||
void onSelectText(const SelectTextEvent& e) override;
|
void onSelectText(const SelectTextEvent& e) override;
|
||||||
|
|
||||||
void setAsCurrentContext();
|
void setAsCurrentContext();
|
||||||
void setUseMonospaceFont(bool useMonoFont = true);
|
void setUseMonospaceFont(bool useMonoFont = true);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue