Skip to content

Commit

Permalink
Client: Improve the double-click camera reset logic
Browse files Browse the repository at this point in the history
When releasing the mouse button and immediately clicking, the view is always reset - even if the button was pressed a long time ago (or, as in the test case, never). This is unintuitive, as the unspoken convention used by the client currently is that a keypress should be triggered on "press" and never "release".

Ideally, that'd be configurable but it's not that important right now.
  • Loading branch information
rdw-software committed Aug 14, 2023
1 parent 4296c1f commit 219a0b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Core/NativeClient/NativeClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ function NativeClient:MOUSECLICK_STATUS_UPDATED(eventID, payload)

if wasButtonPressed then
C_Camera.StartAdjustingView()
C_Cursor.SetClickTime(now)
else
C_Camera.StopAdjustingView()
end
C_Cursor.SetClickTime(now)
end
end

Expand Down
24 changes: 24 additions & 0 deletions Tests/NativeClient/NativeClient.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@ describe("NativeClient", function()

assertFalse(C_Camera.GetHorizontalRotationAngle() == C_Camera.DEFAULT_HORIZONTAL_ROTATION)
end)

it("should not reset the horizontal camera rotation if a right-click follows a release", function()
local event = ffi.new("deferred_event_t")
C_Cursor.SetClickTime(-2 * C_Cursor.DOUBLE_CLICK_TIME_IN_MILLISECONDS * 10E5)
C_Camera.ApplyHorizontalRotation(37) -- Arbitrary non-default rotation

-- RBUTTON released (here implied: a long time after it was first pressed)
event.mouse_button_details.button = glfw.bindings.glfw_find_constant("GLFW_MOUSE_BUTTON_RIGHT")
event.mouse_button_details.action = glfw.bindings.glfw_find_constant("GLFW_RELEASE")
NativeClient:MOUSECLICK_STATUS_UPDATED("MOUSECLICK_STATUS_UPDATED", event)

assertFalse(C_Camera.GetHorizontalRotationAngle() == C_Camera.DEFAULT_HORIZONTAL_ROTATION)

-- Another RCLICK received -> should NOT reset angle since the original GLFW_PRESS no longer counts
event.mouse_button_details.button = glfw.bindings.glfw_find_constant("GLFW_MOUSE_BUTTON_RIGHT")
event.mouse_button_details.action = glfw.bindings.glfw_find_constant("GLFW_PRESS")
NativeClient:MOUSECLICK_STATUS_UPDATED("MOUSECLICK_STATUS_UPDATED", event)

assertFalse(C_Camera.GetHorizontalRotationAngle() == C_Camera.DEFAULT_HORIZONTAL_ROTATION)

event.mouse_button_details.button = glfw.bindings.glfw_find_constant("GLFW_MOUSE_BUTTON_RIGHT")
event.mouse_button_details.action = glfw.bindings.glfw_find_constant("GLFW_RELEASE")
NativeClient:MOUSECLICK_STATUS_UPDATED("MOUSECLICK_STATUS_UPDATED", event)
end)
end)

describe("SCROLL_STATUS_CHANGED", function()
Expand Down

0 comments on commit 219a0b8

Please sign in to comment.