mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-24 20:57:00 +00:00
IO: apply same flooring as UpdateMouseInputs() in dupe event processing. (#4858) + provision for test engine.
This commit is contained in:
parent
7374b96f5c
commit
90a6961638
@ -3946,7 +3946,7 @@ static void ImGui::UpdateMouseInputs()
|
|||||||
|
|
||||||
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
|
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
|
||||||
if (IsMousePosValid(&io.MousePos))
|
if (IsMousePosValid(&io.MousePos))
|
||||||
io.MousePos = g.MouseLastValidPos = ImFloor(io.MousePos);
|
io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos);
|
||||||
|
|
||||||
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
|
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
|
||||||
if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev))
|
if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev))
|
||||||
@ -7732,12 +7732,15 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
|||||||
const ImGuiInputEvent* e = &g.InputEventsQueue[event_n];
|
const ImGuiInputEvent* e = &g.InputEventsQueue[event_n];
|
||||||
if (e->Type == ImGuiInputEventType_MousePos)
|
if (e->Type == ImGuiInputEventType_MousePos)
|
||||||
{
|
{
|
||||||
if (io.MousePos.x != e->MousePos.PosX || io.MousePos.y != e->MousePos.PosY)
|
ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY);
|
||||||
|
if (IsMousePosValid(&event_pos))
|
||||||
|
event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs()
|
||||||
|
if (io.MousePos.x != event_pos.x || io.MousePos.y != event_pos.y)
|
||||||
{
|
{
|
||||||
// Trickling Rule: Stop processing queued events if we already handled a mouse button change
|
// Trickling Rule: Stop processing queued events if we already handled a mouse button change
|
||||||
if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || key_mods_changed || text_inputed))
|
if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || key_mods_changed || text_inputed))
|
||||||
break;
|
break;
|
||||||
io.MousePos = ImVec2(e->MousePos.PosX, e->MousePos.PosY);
|
io.MousePos = event_pos;
|
||||||
mouse_moved = true;
|
mouse_moved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,6 +441,7 @@ static inline float ImInvLength(const ImVec2& lhs, float fail_value)
|
|||||||
static inline float ImFloor(float f) { return (float)(int)(f); }
|
static inline float ImFloor(float f) { return (float)(int)(f); }
|
||||||
static inline float ImFloorSigned(float f) { return (float)((f >= 0 || (float)(int)f == f) ? (int)f : (int)f - 1); } // Decent replacement for floorf()
|
static inline float ImFloorSigned(float f) { return (float)((f >= 0 || (float)(int)f == f) ? (int)f : (int)f - 1); } // Decent replacement for floorf()
|
||||||
static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)(v.x), (float)(int)(v.y)); }
|
static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)(v.x), (float)(int)(v.y)); }
|
||||||
|
static inline ImVec2 ImFloorSigned(const ImVec2& v) { return ImVec2(ImFloorSigned(v.x), ImFloorSigned(v.y)); }
|
||||||
static inline int ImModPositive(int a, int b) { return (a + b) % b; }
|
static inline int ImModPositive(int a, int b) { return (a + b) % b; }
|
||||||
static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; }
|
static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; }
|
||||||
static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); }
|
static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); }
|
||||||
@ -936,6 +937,7 @@ struct ImGuiInputEvent
|
|||||||
{
|
{
|
||||||
ImGuiInputEventType Type;
|
ImGuiInputEventType Type;
|
||||||
ImGuiInputSource Source;
|
ImGuiInputSource Source;
|
||||||
|
bool SubmittedByTestEngine;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
ImGuiInputEventMousePos MousePos; // if Type == ImGuiInputEventType_MousePos
|
ImGuiInputEventMousePos MousePos; // if Type == ImGuiInputEventType_MousePos
|
||||||
|
Loading…
Reference in New Issue
Block a user