1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Mon, 1 Sep 2025 17:22:56 +0200
Subject: Fix build with imgui 1.92
---
libs/filagui/src/ImGuiHelper.cpp | 4 +-
libs/viewer/src/SimpleViewer.cpp | 83 +++++++++++++++++++++++++---------------
2 files changed, 55 insertions(+), 32 deletions(-)
diff --git a/libs/filagui/src/ImGuiHelper.cpp b/libs/filagui/src/ImGuiHelper.cpp
index 91b2a4e..8b2d131 100644
--- a/libs/filagui/src/ImGuiHelper.cpp
+++ b/libs/filagui/src/ImGuiHelper.cpp
@@ -217,9 +217,9 @@ void ImGuiHelper::processImGuiCommands(ImDrawData* commands, const ImGuiIO& io)
materialInstance->setScissor( pcmd.ClipRect.x, fbheight - pcmd.ClipRect.w,
(uint16_t) (pcmd.ClipRect.z - pcmd.ClipRect.x),
(uint16_t) (pcmd.ClipRect.w - pcmd.ClipRect.y));
- if (pcmd.TextureId) {
+ if (pcmd.GetTexID()) {
TextureSampler sampler(MinFilter::LINEAR, MagFilter::LINEAR);
- materialInstance->setParameter("albedo", (Texture const*)pcmd.TextureId, sampler);
+ materialInstance->setParameter("albedo", (Texture const*)pcmd.GetTexID(), sampler);
}
rbuilder
.geometry(primIndex, RenderableManager::PrimitiveType::TRIANGLES,
diff --git a/libs/viewer/src/SimpleViewer.cpp b/libs/viewer/src/SimpleViewer.cpp
index ec78013..2e774a6 100644
--- a/libs/viewer/src/SimpleViewer.cpp
+++ b/libs/viewer/src/SimpleViewer.cpp
@@ -94,6 +94,48 @@ static float getRangePlotValue(int series, void* data, int index) {
return ((float*) data)[series * 1024 + index];
}
+static ImGuiKey keyCodeToImGui(int keyCode)
+{
+ switch (keyCode) {
+ case 8:
+ return ImGuiKey_Backspace;
+ case 9:
+ return ImGuiKey_Tab;
+ case 13:
+ return ImGuiKey_Enter;
+ case 27:
+ return ImGuiKey_Escape;
+ case 35:
+ return ImGuiKey_End;
+ case 36:
+ return ImGuiKey_Home;
+ case 37:
+ return ImGuiKey_LeftArrow;
+ case 38:
+ return ImGuiKey_UpArrow;
+ case 39:
+ return ImGuiKey_RightArrow;
+ case 40:
+ return ImGuiKey_DownArrow;
+ case 46:
+ return ImGuiKey_Delete;
+ case 65:
+ return ImGuiKey_A;
+ case 67:
+ return ImGuiKey_C;
+ case 86:
+ return ImGuiKey_V;
+ case 88:
+ return ImGuiKey_X;
+ case 89:
+ return ImGuiKey_Y;
+ case 90:
+ return ImGuiKey_Z;
+ default:
+ return ImGuiKey_None;
+ }
+}
+
inline float3 curves(float3 v, float3 shadowGamma, float3 midPoint, float3 highlightScale) {
float3 d = 1.0f / (pow(midPoint, shadowGamma - 1.0f));
float3 dark = pow(v, shadowGamma) * d;
@@ -426,26 +468,6 @@ void SimpleViewer::renderUserInterface(float timeStepInSeconds, View* guiView, f
auto& io = ImGui::GetIO();
- // The following table uses normal ANSI codes, which is consistent with the keyCode that
- // comes from a web "keydown" event.
- io.KeyMap[ImGuiKey_Tab] = 9;
- io.KeyMap[ImGuiKey_LeftArrow] = 37;
- io.KeyMap[ImGuiKey_RightArrow] = 39;
- io.KeyMap[ImGuiKey_UpArrow] = 38;
- io.KeyMap[ImGuiKey_DownArrow] = 40;
- io.KeyMap[ImGuiKey_Home] = 36;
- io.KeyMap[ImGuiKey_End] = 35;
- io.KeyMap[ImGuiKey_Delete] = 46;
- io.KeyMap[ImGuiKey_Backspace] = 8;
- io.KeyMap[ImGuiKey_Enter] = 13;
- io.KeyMap[ImGuiKey_Escape] = 27;
- io.KeyMap[ImGuiKey_A] = 65;
- io.KeyMap[ImGuiKey_C] = 67;
- io.KeyMap[ImGuiKey_V] = 86;
- io.KeyMap[ImGuiKey_X] = 88;
- io.KeyMap[ImGuiKey_Y] = 89;
- io.KeyMap[ImGuiKey_Z] = 90;
-
// TODO: this is not the best way to handle high DPI in ImGui, but it is fine when using the
// proggy font. Users need to refresh their window when dragging between displays with
// different pixel ratios.
@@ -465,25 +487,26 @@ void SimpleViewer::mouseEvent(float mouseX, float mouseY, bool mouseButton, floa
bool control) {
if (mImGuiHelper) {
ImGuiIO& io = ImGui::GetIO();
- io.MousePos.x = mouseX;
- io.MousePos.y = mouseY;
- io.MouseWheel += mouseWheelY;
- io.MouseDown[0] = mouseButton != 0;
- io.MouseDown[1] = false;
- io.MouseDown[2] = false;
+ io.AddMousePosEvent(mouseX, mouseY);
+ io.AddMouseWheelEvent(0, mouseWheelY);
+ io.AddMouseButtonEvent(0, mouseButton);
io.KeyCtrl = control;
}
}
void SimpleViewer::keyDownEvent(int keyCode) {
- if (mImGuiHelper && keyCode < IM_ARRAYSIZE(ImGui::GetIO().KeysDown)) {
- ImGui::GetIO().KeysDown[keyCode] = true;
+ if (mImGuiHelper) {
+ ImGuiKey key = keyCodeToImGui(keyCode);
+ if (key != ImGuiKey_None)
+ ImGui::GetIO().AddKeyEvent(key, true);
}
}
void SimpleViewer::keyUpEvent(int keyCode) {
- if (mImGuiHelper && keyCode < IM_ARRAYSIZE(ImGui::GetIO().KeysDown)) {
- ImGui::GetIO().KeysDown[keyCode] = false;
+ if (mImGuiHelper) {
+ ImGuiKey key = keyCodeToImGui(keyCode);
+ if (key != ImGuiKey_None)
+ ImGui::GetIO().AddKeyEvent(key, false);
}
}
|