Merge pull request #2414 from myk002/myk_mouse_buttons

Make mouse button event behavior conform to docs
develop
Myk 2022-11-23 11:29:20 -08:00 committed by GitHub
commit a900b1789a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 14 deletions

@ -116,6 +116,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``widgets.EditField`` now allows other widgets to process characters that the ``on_char`` callback rejects.
- ``gui.Screen.show()`` now returns ``self`` as a convenience
- ``gui.View.getMousePos()`` now takes an optional ``ViewRect`` parameter in case the caller wants to get the mouse pos relative to a rect that is not the frame_body (such as the frame_rect)
- Lua mouse events now conform to documented behavior in `lua-api` -- ``_MOUSE_L_DOWN`` will be sent exactly once per mouse click and ``_MOUSE_L`` will be sent repeatedly as long as the button is held down. Similarly for right mouse button events.
## Internals
- MSVC warning level upped to /W3, and /WX added to make warnings cause compilations to fail.

@ -156,21 +156,21 @@ void DFHack::Lua::PushInterfaceKeys(lua_State *L,
if (df::global::enabler) {
if (df::global::enabler->mouse_lbut_down) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "_MOUSE_L");
lua_setfield(L, -2, "_MOUSE_L_DOWN");
}
if (df::global::enabler->mouse_rbut_down) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "_MOUSE_R");
lua_setfield(L, -2, "_MOUSE_R_DOWN");
}
if (df::global::enabler->mouse_lbut) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "_MOUSE_L_DOWN");
df::global::enabler->mouse_lbut = 0;
lua_setfield(L, -2, "_MOUSE_L");
df::global::enabler->mouse_lbut_down = 0;
}
if (df::global::enabler->mouse_rbut) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "_MOUSE_R_DOWN");
df::global::enabler->mouse_rbut = 0;
lua_setfield(L, -2, "_MOUSE_R");
df::global::enabler->mouse_rbut_down = 0;
}
}
}

@ -334,7 +334,7 @@ function EditField:onInput(keys)
elseif keys._MOUSE_L then
local mouse_x, mouse_y = self:getMousePos()
if mouse_x then
self:setCursor(self.start_pos + mouse_x)
self:setCursor(self.start_pos + mouse_x - (self.text_offset or 0))
return true
end
elseif keys._STRING then
@ -496,7 +496,7 @@ function Scrollbar:onRenderBody(dc)
if self.is_dragging then
scrollbar_do_drag(self)
end
if df.global.enabler.mouse_lbut_down == 0 then
if df.global.enabler.mouse_lbut == 0 then
self.last_scroll_ms = 0
self.is_dragging = false
self.scroll_spec = nil
@ -928,7 +928,7 @@ end
function HotkeyLabel:onInput(keys)
if HotkeyLabel.super.onInput(self, keys) then
return true
elseif keys._MOUSE_L and self:getMousePos() then
elseif keys._MOUSE_L_DOWN and self:getMousePos() then
self.on_activate()
return true
end
@ -1009,7 +1009,7 @@ end
function CycleHotkeyLabel:onInput(keys)
if CycleHotkeyLabel.super.onInput(self, keys) then
return true
elseif keys._MOUSE_L and self:getMousePos() then
elseif keys._MOUSE_L_DOWN and self:getMousePos() then
self:cycle()
return true
end
@ -1274,7 +1274,7 @@ function List:onInput(keys)
elseif self.on_submit2 and keys.SEC_SELECT then
self:submit2()
return true
elseif keys._MOUSE_L then
elseif keys._MOUSE_L_DOWN then
local idx = self:getIdxUnderMouse()
if idx then
self:setSelected(idx)

@ -207,7 +207,7 @@ function MenuScreen:onInput(keys)
elseif keys.STANDARDSCROLL_RIGHT then
self:onSubmit2(self.subviews.list:getSelected())
return true
elseif keys._MOUSE_L then
elseif keys._MOUSE_L_DOWN then
local list = self.subviews.list
local x = list:getMousePos()
if x == 0 then -- clicked on icon

@ -5,7 +5,7 @@ function test.hotkeylabel_click()
local l = widgets.HotkeyLabel{key='SELECT', on_activate=func}
mock.patch(l, 'getMousePos', mock.func(0), function()
l:onInput{_MOUSE_L=true}
l:onInput{_MOUSE_L_DOWN=true}
expect.eq(1, func.call_count)
end)
end
@ -31,7 +31,7 @@ function test.togglehotkeylabel_click()
local l = widgets.ToggleHotkeyLabel{}
expect.true_(l:getOptionValue())
mock.patch(l, 'getMousePos', mock.func(0), function()
l:onInput{_MOUSE_L=true}
l:onInput{_MOUSE_L_DOWN=true}
expect.false_(l:getOptionValue())
end)
end