Skip to content

Commit

Permalink
adjust to new mouse event semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Sep 26, 2023
1 parent 58e24f9 commit 572c3ab
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion devel/inspect-screen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function Inspect:onInput(keys)
if Inspect.super.onInput(self, keys) then
return true
end
if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if keys._MOUSE_L and not self:getMouseFramePos() then
self.subviews.freeze:cycle()
return true
end
Expand Down
4 changes: 2 additions & 2 deletions exportlegends.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ function LegendsOverlay:init()
end

function LegendsOverlay:onInput(keys)
if keys._MOUSE_L_DOWN and progress_percent < 0 and
if keys._MOUSE_L and progress_percent < 0 and
self.subviews.button_mask:getMousePos() and
self.subviews.do_export:getOptionValue()
then
Expand Down Expand Up @@ -1102,7 +1102,7 @@ end

function DoneMaskOverlay:onInput(keys)
if progress_percent >= 0 then
if keys.LEAVESCREEN or (keys._MOUSE_L_DOWN and self:getMousePos()) then
if keys.LEAVESCREEN or (keys._MOUSE_L and self:getMousePos()) then
return true
end
end
Expand Down
2 changes: 1 addition & 1 deletion gui/autochop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function BurrowSettings:commit()
end

function BurrowSettings:onInput(keys)
if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
self:hide()
return true
end
Expand Down
4 changes: 2 additions & 2 deletions gui/autodump.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ end

function Autodump:onInput(keys)
if Autodump.super.onInput(self, keys) then return true end
if keys._MOUSE_R_DOWN and self.mark then
if keys._MOUSE_R and self.mark then
self.mark = nil
self:updateLayout()
return true
elseif keys._MOUSE_L_DOWN then
elseif keys._MOUSE_L then
if self:getMouseFramePos() then return true end
local pos = dfhack.gui.getMousePos()
if not pos then
Expand Down
4 changes: 2 additions & 2 deletions gui/blueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ end
function Blueprint:onInput(keys)
if Blueprint.super.onInput(self, keys) then return true end

if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
if self:is_setting_start_pos() then
self.subviews.startpos.option_idx = 1
self.saved_cursor = nil
Expand All @@ -474,7 +474,7 @@ function Blueprint:onInput(keys)
end

local pos = nil
if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if keys._MOUSE_L and not self:getMouseFramePos() then
pos = dfhack.gui.getMousePos()
if pos then
guidm.setCursorPos(pos)
Expand Down
8 changes: 4 additions & 4 deletions gui/control-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ end

function ConfigPanel:onInput(keys)
local handled = ConfigPanel.super.onInput(self, keys)
if keys._MOUSE_L_DOWN then
if keys._MOUSE_L then
local list = self.subviews.list.list
local idx = list:getIdxUnderMouse()
if idx then
Expand Down Expand Up @@ -603,7 +603,7 @@ function IntegerInputDialog:onInput(keys)
if keys.SELECT then
self:hide(self.subviews.input_edit.text)
return true
elseif keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
elseif keys.LEAVESCREEN or keys._MOUSE_R then
self:hide()
return true
end
Expand Down Expand Up @@ -638,7 +638,7 @@ end
function Preferences:onInput(keys)
-- call grandparent's onInput since we don't want ConfigPanel's processing
local handled = Preferences.super.super.onInput(self, keys)
if keys._MOUSE_L_DOWN then
if keys._MOUSE_L then
local list = self.subviews.list.list
local idx = list:getIdxUnderMouse()
if idx then
Expand Down Expand Up @@ -787,7 +787,7 @@ end
function RepeatAutostart:onInput(keys)
-- call grandparent's onInput since we don't want ConfigPanel's processing
local handled = RepeatAutostart.super.super.onInput(self, keys)
if keys._MOUSE_L_DOWN then
if keys._MOUSE_L then
local list = self.subviews.list.list
local idx = list:getIdxUnderMouse()
if idx then
Expand Down
6 changes: 3 additions & 3 deletions gui/design.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ function Design:onInput(keys)
-- return
-- end

if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
-- Close help window if open
if view.help_window.visible then self:dismiss_help() return true end

Expand Down Expand Up @@ -1438,15 +1438,15 @@ function Design:onInput(keys)


local pos = nil
if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if keys._MOUSE_L and not self:getMouseFramePos() then
pos = getMousePoint()
if not pos then return true end
guidm.setCursorPos(dfhack.gui.getMousePos())
elseif keys.SELECT then
pos = Point(guidm.getCursorPos())
end

if keys._MOUSE_L_DOWN and pos then
if keys._MOUSE_L and pos then
-- TODO Refactor this a bit
if self.shape.max_points and #self.marks == self.shape.max_points and self.placing_mark.active then
self.marks[self.placing_mark.index] = pos
Expand Down
2 changes: 1 addition & 1 deletion gui/gm-editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ end
function GmEditorUi:onInput(keys)
if GmEditorUi.super.onInput(self, keys) then return true end

if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
if dfhack.internal.getModifiers().shift then
return false
end
Expand Down
2 changes: 1 addition & 1 deletion gui/gm-unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ end
function Editor_Unit:onInput(keys)
local pages = self.subviews.pages
if pages:getSelected() == 1 or
(not keys.LEAVESCREEN and not keys._MOUSE_R_DOWN) then
(not keys.LEAVESCREEN and not keys._MOUSE_R) then
return Editor_Unit.super.onInput(self, keys)
end
local page = pages:getSelectedPage()
Expand Down
6 changes: 3 additions & 3 deletions gui/liquids.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function SpawnLiquid:onRenderFrame(dc, rect)
local mouse_pos = dfhack.gui.getMousePos()

if self.is_dragging then
if df.global.enabler.mouse_lbut == 0 then
if df.global.enabler.mouse_lbut_down == 0 then
self.is_dragging = false
elseif mouse_pos and not self:getMouseFramePos() then
self:spawn(mouse_pos)
Expand All @@ -228,7 +228,7 @@ end
function SpawnLiquid:onInput(keys)
if SpawnLiquid.super.onInput(self, keys) then return true end

if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if keys._MOUSE_L and not self:getMouseFramePos() then
local mouse_pos = dfhack.gui.getMousePos()

if self.paint_mode == SpawnLiquidPaintMode.CLICK and mouse_pos then
Expand Down Expand Up @@ -258,7 +258,7 @@ function SpawnLiquid:onInput(keys)
end

-- TODO: Holding the mouse down causes event spam.
if keys._MOUSE_L and not self:getMouseFramePos() then
if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if self.paint_mode == SpawnLiquidPaintMode.DRAG then
self.is_dragging = true
return true
Expand Down
4 changes: 2 additions & 2 deletions gui/mass-remove.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ end
function MassRemove:onInput(keys)
if MassRemove.super.onInput(self, keys) then return true end

if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
if self.mark then
self.mark = nil
self:updateLayout()
Expand All @@ -185,7 +185,7 @@ function MassRemove:onInput(keys)
end

local pos = nil
if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if keys._MOUSE_L and not self:getMouseFramePos() then
pos = dfhack.gui.getMousePos()
end
if not pos then return false end
Expand Down
2 changes: 1 addition & 1 deletion gui/masspit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ end
function Masspit:onInput(keys)
if Masspit.super.onInput(self, keys) then return true end

if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if keys._MOUSE_L and not self:getMouseFramePos() then
if self.subviews.pages:getSelected() == 1 then
local building = dfhack.buildings.findAtTile(dfhack.gui.getMousePos())

Expand Down
4 changes: 2 additions & 2 deletions gui/overlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DraggablePanel.ATTRS{
}

function DraggablePanel:onInput(keys)
if keys._MOUSE_L_DOWN then
if keys._MOUSE_L then
local rect = self.frame_rect
local x,y = self:getMousePos(gui.ViewRect{rect=rect})
if x then
Expand Down Expand Up @@ -281,7 +281,7 @@ function OverlayConfig:onInput(keys)
return true
end
end
if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
self:dismiss()
return true
end
Expand Down
6 changes: 3 additions & 3 deletions gui/quickfort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end

function BlueprintDetails:onInput(keys)
if keys.CUSTOM_CTRL_D or keys.SELECT
or keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
or keys.LEAVESCREEN or keys._MOUSE_R then
self:dismiss()
end
end
Expand Down Expand Up @@ -211,7 +211,7 @@ function BlueprintDialog:onInput(keys)
details:show()
-- for testing
self._details = details
elseif keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
elseif keys.LEAVESCREEN or keys._MOUSE_R then
self:dismiss()
if self.on_cancel then
self.on_cancel()
Expand Down Expand Up @@ -606,7 +606,7 @@ function Quickfort:onInput(keys)
return true
end

if keys._MOUSE_L_DOWN and not self:getMouseFramePos() then
if keys._MOUSE_L and not self:getMouseFramePos() then
local pos = dfhack.gui.getMousePos()
if pos then
self:commit()
Expand Down
12 changes: 6 additions & 6 deletions gui/sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function Sandbox:init()
key='CUSTOM_SHIFT_U',
label="Spawn unit",
on_activate=function()
df.global.enabler.mouse_lbut = 0
df.global.enabler.mouse_lbut_down = 0
clear_arena_action()
view:sendInputToParent{ARENA_CREATE_CREATURE=true}
df.global.game.main_interface.arena_unit.editing_filter = true
Expand Down Expand Up @@ -162,7 +162,7 @@ function Sandbox:init()
key='CUSTOM_SHIFT_T',
label="Spawn tree",
on_activate=function()
df.global.enabler.mouse_lbut = 0
df.global.enabler.mouse_lbut_down = 0
clear_arena_action()
view:sendInputToParent{ARENA_CREATE_TREE=true}
df.global.game.main_interface.arena_tree.editing_filter = true
Expand All @@ -189,11 +189,11 @@ function Sandbox:init()
end

function Sandbox:onInput(keys)
if keys._MOUSE_R_DOWN and self:getMouseFramePos() then
if keys._MOUSE_R and self:getMouseFramePos() then
clear_arena_action()
return false
end
if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
if is_arena_action_in_progress() then
clear_arena_action()
return true
Expand All @@ -204,7 +204,7 @@ function Sandbox:onInput(keys)
if Sandbox.super.onInput(self, keys) then
return true
end
if keys._MOUSE_L then
if keys._MOUSE_L_DOWN then
if self:getMouseFramePos() then return true end
for _,mask_panel in ipairs(self.interface_masks) do
if mask_panel:getMousePos() then return true end
Expand Down Expand Up @@ -252,7 +252,7 @@ InterfaceMask.ATTRS{
}

function InterfaceMask:onInput(keys)
return keys._MOUSE_L and self:getMousePos()
return keys._MOUSE_L_DOWN and self:getMousePos()
end

---------------------
Expand Down
2 changes: 1 addition & 1 deletion gui/seedwatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function SeedSettings:commit()
end

function SeedSettings:onInput(keys)
if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
self:hide()
return true
end
Expand Down
2 changes: 1 addition & 1 deletion gui/unit-syndromes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ function UnitSyndromes:push_state()
end

function UnitSyndromes:onInput(keys)
if keys._MOUSE_R_DOWN then
if keys._MOUSE_R then
self:previous_page()
return true
end
Expand Down
2 changes: 1 addition & 1 deletion hide-tutorials.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function skip_tutorial_prompt(scr)
df.global.gps.mouse_y = 18
df.global.enabler.mouse_lbut = 1
df.global.enabler.mouse_lbut_down = 1
gui.simulateInput(scr, '_MOUSE_L_DOWN')
gui.simulateInput(scr, '_MOUSE_L')
end
end

Expand Down
6 changes: 3 additions & 3 deletions internal/caravan/trade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ end
function TradeScreen:onInput(keys)
if self.reset_pending then return false end
local handled = TradeScreen.super.onInput(self, keys)
if keys._MOUSE_L_DOWN and not self.trade_window:getMouseFramePos() then
if keys._MOUSE_L and not self.trade_window:getMouseFramePos() then
-- "trade" or "offer" buttons may have been clicked and we need to reset the cache
self.reset_pending = true
end
Expand Down Expand Up @@ -780,7 +780,7 @@ end
function TradeOverlay:onInput(keys)
if TradeOverlay.super.onInput(self, keys) then return true end

if keys._MOUSE_L_DOWN then
if keys._MOUSE_L then
if dfhack.internal.getModifiers().shift then
handle_shift_click_on_render = true
copyGoodflagState()
Expand Down Expand Up @@ -819,7 +819,7 @@ end
function TradeBannerOverlay:onInput(keys)
if TradeBannerOverlay.super.onInput(self, keys) then return true end

if keys._MOUSE_R_DOWN or keys.LEAVESCREEN then
if keys._MOUSE_R or keys.LEAVESCREEN then
if view then
view:dismiss()
end
Expand Down
2 changes: 1 addition & 1 deletion internal/gm-unit/editor_body.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function Editor_Body_Modifier:init(args)
end

function Editor_Body_Modifier:onInput(keys)
if keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if keys.LEAVESCREEN or keys._MOUSE_R then
self:setFocus(false)
self.visible = false
else
Expand Down
2 changes: 1 addition & 1 deletion test/gui/blueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function test.set_with_mouse()
mock.patch(dfhack.gui, 'getMousePos', mock.func(pos),
function()
local view = load_ui()
view:onInput({_MOUSE_L_DOWN=true})
view:onInput({_MOUSE_L=true})
expect.table_eq(pos, view.mark, comment)
send_keys('LEAVESCREEN') -- cancel selection
send_keys('LEAVESCREEN') -- cancel out of UI
Expand Down

0 comments on commit 572c3ab

Please sign in to comment.