diff --git a/imgui.cpp b/imgui.cpp index 4350b241f..30d657a9f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2826,6 +2826,14 @@ ImVec2 ImGui::GetMousePos() return GImGui->IO.MousePos; } +ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup() +{ + ImGuiState& g = *GImGui; + if (g.CurrentPopupStack.Size > 0) + return g.OpenedPopupStack[g.CurrentPopupStack.Size-1].MousePosOnOpen; + return g.IO.MousePos; +} + ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold) { ImGuiState& g = *GImGui; @@ -2982,7 +2990,7 @@ void ImGui::OpenPopup(const char* str_id) ImGuiWindow* window = GetCurrentWindow(); ImGuiID id = window->GetID(str_id); int current_stack_size = g.CurrentPopupStack.Size; - ImGuiPopupRef popup_ref = ImGuiPopupRef(id, window, window->GetID("##menus")); // Tagged as new ref because constructor sets Window to NULL (we are passing the ParentWindow info here) + ImGuiPopupRef popup_ref = ImGuiPopupRef(id, window, window->GetID("##menus"), g.IO.MousePos); // Tagged as new ref because constructor sets Window to NULL (we are passing the ParentWindow info here) if (g.OpenedPopupStack.Size < current_stack_size + 1) g.OpenedPopupStack.push_back(popup_ref); else if (g.OpenedPopupStack[current_stack_size].PopupID != id) diff --git a/imgui.h b/imgui.h index 3ef093dbd..2dab96b3e 100644 --- a/imgui.h +++ b/imgui.h @@ -398,6 +398,7 @@ namespace ImGui IMGUI_API bool IsMouseHoveringRect(const ImVec2& pos_min, const ImVec2& pos_max); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup. IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls + IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // dragging amount since clicking, also see: GetItemActiveDragDelta(). if lock_threshold < -1.0f uses io.MouseDraggingThreshold IMGUI_API void ResetMouseDragDelta(int button = 0); // IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you diff --git a/imgui_internal.h b/imgui_internal.h index 9e09fd309..1ecacba42 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -305,8 +305,9 @@ struct ImGuiPopupRef ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() ImGuiWindow* ParentWindow; // Set on OpenPopup() ImGuiID ParentMenuSet; // Set on OpenPopup() + ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup - ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set) { PopupID = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; } + ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupID = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; } }; // Main state for ImGui