Skip to content

Commit 34dd684

Browse files
committed
ImGui input fixes
modifier keys, picked object leaks
1 parent b2df981 commit 34dd684

3 files changed

Lines changed: 33 additions & 22 deletions

File tree

src/Editor/Editor.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,22 @@ std::unique_ptr<ClosestNotMeConvexResultCallback> Editor::convexSweepTestDown(Mo
540540
return resultCallback;
541541
}
542542

543+
void Editor::applyPendingPick() {
544+
// hasPendingPick distinguishes "no pick happened this frame" from "user clicked empty space"
545+
if (!hasPendingPick) {
546+
return;
547+
}
548+
hasPendingPick = false;
549+
if (pickedObject != nullptr) {
550+
pickedObject->removeTag(HardCodedTags::PICKED_OBJECT);
551+
}
552+
pickedObject = pendingPickedObject;
553+
pendingPickedObject = nullptr;
554+
if (pickedObject != nullptr) {
555+
pickedObject->addTag(HardCodedTags::PICKED_OBJECT);
556+
}
557+
}
558+
543559
void Editor::renderEditor(std::shared_ptr<GraphicsProgram> graphicsProgram) {
544560

545561
imgGuiHelper->NewFrame(graphicsProgram);

src/ImGuiHelper.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,23 @@ bool ImGuiHelper::ProcessEvent(InputHandler& inputHandler) {
157157
if(inputStates.getInputEvents(InputActions::TEXT_INPUT)) {
158158
io.AddInputCharactersUTF8(inputStates.getText());
159159
}
160-
if(inputStates.getInputEvents(InputActions::KEY_SHIFT)) {
161-
io.KeyShift = ((SDL_GetModState() & SDL_KMOD_SHIFT) != 0);
162-
}
163-
if(inputStates.getInputEvents(InputActions::KEY_SUPER)) {
164-
io.KeySuper = ((SDL_GetModState() & SDL_KMOD_GUI) != 0);
165-
}
166-
if(inputStates.getInputEvents(InputActions::KEY_CTRL)) {
167-
io.KeyCtrl = ((SDL_GetModState() & SDL_KMOD_CTRL) != 0);
168-
}
169-
if(inputStates.getInputEvents(InputActions::KEY_ALT)) {
170-
io.KeyAlt = ((SDL_GetModState() & SDL_KMOD_ALT) != 0);
171-
}
160+
// ImGui 1.91.5+ removed the legacy io.KeyCtrl propagation path. io.KeyMods is now
161+
// derived from ImGuiKey_ModCtrl etc. (ImGuiKey_ReservedForModCtrl), NOT from
162+
// ImGuiKey_LeftCtrl, so we must deliver the virtual modifier keys explicitly.
163+
SDL_Keymod sdlMods = SDL_GetModState();
164+
io.AddKeyEvent(ImGuiMod_Ctrl, (sdlMods & SDL_KMOD_CTRL) != 0);
165+
io.AddKeyEvent(ImGuiMod_Shift, (sdlMods & SDL_KMOD_SHIFT) != 0);
166+
io.AddKeyEvent(ImGuiMod_Alt, (sdlMods & SDL_KMOD_ALT) != 0);
167+
io.AddKeyEvent(ImGuiMod_Super, (sdlMods & SDL_KMOD_GUI) != 0);
172168
int numKeys;
173169
const bool* sdlKeyStates = SDL_GetKeyboardState(&numKeys);
174170
for (int i = 0; i < numKeys; i++) {
175-
ImGuiKey key = SDL2KeyEventToImGuiKey(SDL_SCANCODE_TO_KEYCODE(i));
171+
// SDL3 keycodes for "legacy" keys (Backspace=0x08, Delete=0x7F, letters='a'-'z', etc.)
172+
// are plain ASCII values — NOT scancode-masked. SDL_SCANCODE_TO_KEYCODE() always sets
173+
// bit 30, so it produces wrong values for those keys. SDL_GetKeyFromScancode() returns
174+
// the correct keycode in both cases.
175+
SDL_Keycode sdlKeycode = SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(i), SDL_KMOD_NONE, false);
176+
ImGuiKey key = SDL2KeyEventToImGuiKey(static_cast<uint32_t>(sdlKeycode));
176177
if (key != ImGuiKey_None) {
177178
io.AddKeyEvent(key, sdlKeyStates[i] != 0);
178179
}

src/World.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,8 @@ World::fillRouteInformation(std::vector<LimonTypes::GenericParameter> parameters
570570
if(inputHandler.getInputStates().getInputEvents(InputActions::MOUSE_BUTTON_LEFT)) {
571571
if(inputHandler.getInputStates().getInputStatus(InputActions::MOUSE_BUTTON_LEFT)) {
572572
GameObject *gameObject = getPointedObject(COLLIDE_EVERYTHING, ~(COLLIDE_NOTHING));
573-
if (gameObject != nullptr) {//FIXME this looks like a left over
574-
if(editor->pickedObject != nullptr ) {
575-
editor->pickedObject->removeTag(HardCodedTags::PICKED_OBJECT);
576-
}
577-
editor->pickedObject = gameObject;
578-
editor->pickedObject->addTag(HardCodedTags::PICKED_OBJECT);
579-
} else {
580-
editor->pickedObject = nullptr;
581-
}
573+
editor->pendingPickedObject = gameObject; // nullptr if nothing was hit
574+
editor->hasPendingPick = true;
582575
}
583576
}
584577

@@ -877,6 +870,7 @@ void World::ImGuiFrameSetup(std::shared_ptr<GraphicsProgram> graphicsProgram, co
877870
graphicsProgram->setUniform("renderModelIMGUI", 0);
878871
}
879872
editor->renderEditor(graphicsProgram);
873+
editor->applyPendingPick();
880874
}
881875

882876
void World::removeActiveCustomAnimation(const AnimationCustom &animationToRemove,

0 commit comments

Comments
 (0)