mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1).
We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2.
This commit is contained in:
30
imgui.cpp
30
imgui.cpp
@ -1001,6 +1001,7 @@ ImGuiIO::ImGuiIO()
|
||||
{
|
||||
// Most fields are initialized with zero
|
||||
memset(this, 0, sizeof(*this));
|
||||
IM_STATIC_ASSERT(IM_ARRAYSIZE(MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(MouseClicked) == ImGuiMouseButton_COUNT);
|
||||
|
||||
// Settings
|
||||
ConfigFlags = ImGuiConfigFlags_None;
|
||||
@ -4278,14 +4279,14 @@ bool ImGui::IsKeyReleased(int user_key_index)
|
||||
return g.IO.KeysDownDurationPrev[user_key_index] >= 0.0f && !g.IO.KeysDown[user_key_index];
|
||||
}
|
||||
|
||||
bool ImGui::IsMouseDown(int button)
|
||||
bool ImGui::IsMouseDown(ImGuiMouseButton button)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
return g.IO.MouseDown[button];
|
||||
}
|
||||
|
||||
bool ImGui::IsMouseClicked(int button, bool repeat)
|
||||
bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
@ -4300,18 +4301,17 @@ bool ImGui::IsMouseClicked(int button, bool repeat)
|
||||
if (amount > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGui::IsMouseReleased(int button)
|
||||
bool ImGui::IsMouseReleased(ImGuiMouseButton button)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
return g.IO.MouseReleased[button];
|
||||
}
|
||||
|
||||
bool ImGui::IsMouseDoubleClicked(int button)
|
||||
bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
@ -4319,7 +4319,7 @@ bool ImGui::IsMouseDoubleClicked(int button)
|
||||
}
|
||||
|
||||
// [Internal] This doesn't test if the button is pressed
|
||||
bool ImGui::IsMouseDragPastThreshold(int button, float lock_threshold)
|
||||
bool ImGui::IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
@ -4328,7 +4328,7 @@ bool ImGui::IsMouseDragPastThreshold(int button, float lock_threshold)
|
||||
return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold;
|
||||
}
|
||||
|
||||
bool ImGui::IsMouseDragging(int button, float lock_threshold)
|
||||
bool ImGui::IsMouseDragging(ImGuiMouseButton button, float lock_threshold)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
@ -4375,7 +4375,7 @@ bool ImGui::IsAnyMouseDown()
|
||||
// Return the delta from the initial clicking position while the mouse button is clicked or was just released.
|
||||
// This is locked and return 0.0f until the mouse moves past a distance threshold at least once.
|
||||
// NB: This is only valid if IsMousePosValid(). Back-ends in theory should always keep mouse position valid when dragging even outside the client window.
|
||||
ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
|
||||
ImVec2 ImGui::GetMouseDragDelta(ImGuiMouseButton button, float lock_threshold)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
@ -4388,7 +4388,7 @@ ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
|
||||
return ImVec2(0.0f, 0.0f);
|
||||
}
|
||||
|
||||
void ImGui::ResetMouseDragDelta(int button)
|
||||
void ImGui::ResetMouseDragDelta(ImGuiMouseButton button)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
@ -4464,7 +4464,7 @@ bool ImGui::IsItemFocused()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGui::IsItemClicked(int mouse_button)
|
||||
bool ImGui::IsItemClicked(ImGuiMouseButton mouse_button)
|
||||
{
|
||||
return IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_None);
|
||||
}
|
||||
@ -7563,7 +7563,7 @@ void ImGui::EndPopup()
|
||||
g.WithinEndChild = false;
|
||||
}
|
||||
|
||||
bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button)
|
||||
bool ImGui::OpenPopupOnItemClick(const char* str_id, ImGuiMouseButton mouse_button)
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
||||
@ -7579,7 +7579,7 @@ bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button)
|
||||
// This is a helper to handle the simplest case of associating one named popup to one given widget.
|
||||
// You may want to handle this on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters).
|
||||
// You can pass a NULL str_id to use the identifier of the last item.
|
||||
bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button)
|
||||
bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiMouseButton mouse_button)
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
if (window->SkipItems)
|
||||
@ -7591,7 +7591,7 @@ bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button)
|
||||
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextWindow(const char* str_id, int mouse_button, bool also_over_items)
|
||||
bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiMouseButton mouse_button, bool also_over_items)
|
||||
{
|
||||
if (!str_id)
|
||||
str_id = "window_context";
|
||||
@ -7602,7 +7602,7 @@ bool ImGui::BeginPopupContextWindow(const char* str_id, int mouse_button, bool a
|
||||
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
|
||||
bool ImGui::BeginPopupContextVoid(const char* str_id, ImGuiMouseButton mouse_button)
|
||||
{
|
||||
if (!str_id)
|
||||
str_id = "void_context";
|
||||
@ -8796,7 +8796,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
|
||||
bool source_drag_active = false;
|
||||
ImGuiID source_id = 0;
|
||||
ImGuiID source_parent_id = 0;
|
||||
int mouse_button = 0;
|
||||
ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
|
||||
if (!(flags & ImGuiDragDropFlags_SourceExtern))
|
||||
{
|
||||
source_id = window->DC.LastItemId;
|
||||
|
Reference in New Issue
Block a user