Skip to content

Commit

Permalink
simple popup check
Browse files Browse the repository at this point in the history
completely dropped complexity
  • Loading branch information
lightmanLP committed Dec 27, 2024
1 parent e16544f commit f02012c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/controller/controldevice/controller/ControllerButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi
if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) {
mapping = std::make_shared<KeyboardKeyToButtonMapping>(mPortIndex, bitmask, mKeyboardScancodeForNewMapping);
} else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() &&
mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) {
Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() &&
mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) {
mapping = std::make_shared<MouseButtonToButtonMapping>(mPortIndex, bitmask, mMouseButtonForNewMapping);
} else {
mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask);
Expand Down
3 changes: 2 additions & 1 deletion src/controller/controldevice/controller/ControllerStick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct
mapping = std::make_shared<KeyboardKeyToAxisDirectionMapping>(mPortIndex, mStickIndex, direction,
mKeyboardScancodeForNewMapping);
} else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() &&
mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) {
Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() &&
mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) {
mapping = std::make_shared<MouseButtonToAxisDirectionMapping>(mPortIndex, mStickIndex, direction,
mMouseButtonForNewMapping);
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/window/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,18 @@ bool Gui::IsMouseOverAnyGuiItem() {
return ImGui::IsAnyItemHovered();
}

bool Gui::IsMouseOverActivePopup() {
ImGuiContext* ctx = ImGui::GetCurrentContext();
if (ctx->OpenPopupStack.Size == 0 || ctx->HoveredWindow == NULL) {
return false;
}
ImGuiPopupData data = ctx->OpenPopupStack.back();
if (data.Window == NULL) {
return false;
}
return (ctx->HoveredWindow->ID == data.Window->ID);
}

std::shared_ptr<GuiWindow> Gui::GetMenu() {
return mMenu;
}
Expand Down
1 change: 1 addition & 0 deletions src/window/gui/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Gui {
std::shared_ptr<GuiWindow> GetMenu();
bool GetMenuOrMenubarVisible();
bool IsMouseOverAnyGuiItem();
bool IsMouseOverActivePopup();

bool GamepadNavigationEnabled();
void BlockGamepadNavigation();
Expand Down

0 comments on commit f02012c

Please sign in to comment.