mirror of
https://github.com/mpv-player/mpv
synced 2025-01-02 21:12:23 +00:00
osc: simplify checks in key handler
Use a helper function for these safety checks.
This commit is contained in:
parent
82bf4567f9
commit
e870b7ad66
@ -2045,24 +2045,29 @@ end
|
|||||||
-- Eventhandling
|
-- Eventhandling
|
||||||
--
|
--
|
||||||
|
|
||||||
|
local function element_has_action(element, action)
|
||||||
|
return element and element.eventresponder and
|
||||||
|
element.eventresponder[action]
|
||||||
|
end
|
||||||
|
|
||||||
function process_event(source, what)
|
function process_event(source, what)
|
||||||
|
local action = string.format("%s%s", source,
|
||||||
|
what and ("_" .. what) or "")
|
||||||
|
|
||||||
if what == "down" then
|
if what == "down" then
|
||||||
|
|
||||||
for n = 1, #elements do
|
for n = 1, #elements do
|
||||||
|
|
||||||
if not (elements[n].eventresponder == nil) then
|
if mouse_hit(elements[n]) and
|
||||||
if not (elements[n].eventresponder[source .. "_up"] == nil)
|
elements[n].eventresponder and
|
||||||
or not (elements[n].eventresponder[source .. "_down"] == nil) then
|
(elements[n].eventresponder[source .. "_up"] or
|
||||||
|
elements[n].eventresponder[action]) then
|
||||||
|
|
||||||
if mouse_hit(elements[n]) then
|
state.active_element = n
|
||||||
state.active_element = n
|
state.active_event_source = source
|
||||||
state.active_event_source = source
|
-- fire the down event if the element has one
|
||||||
-- fire the down event if the element has one
|
if element_has_action(elements[n], action) then
|
||||||
if not (elements[n].eventresponder[source .. "_" .. what] == nil) then
|
elements[n].eventresponder[action](elements[n])
|
||||||
elements[n].eventresponder[source .. "_" .. what](elements[n])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -2070,24 +2075,19 @@ function process_event(source, what)
|
|||||||
|
|
||||||
elseif what == "up" then
|
elseif what == "up" then
|
||||||
|
|
||||||
if not (state.active_element == nil) then
|
if elements[state.active_element] then
|
||||||
|
|
||||||
local n = state.active_element
|
local n = state.active_element
|
||||||
|
|
||||||
if n == 0 then
|
if n == 0 then
|
||||||
--click on background (does not work)
|
--click on background (does not work)
|
||||||
elseif n > 0 and not (n > #elements) and
|
elseif element_has_action(elements[n], action) and
|
||||||
not (elements[n].eventresponder == nil) and
|
mouse_hit(elements[n]) then
|
||||||
not (elements[n].eventresponder[source .. "_" .. what] == nil) then
|
|
||||||
|
|
||||||
if mouse_hit(elements[n]) then
|
elements[n].eventresponder[action](elements[n])
|
||||||
elements[n].eventresponder[source .. "_" .. what](elements[n])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--reset active element
|
--reset active element
|
||||||
if not (n > #elements) and elements[n].eventresponder ~= nil and
|
if element_has_action(elements[n], "reset") then
|
||||||
elements[n].eventresponder["reset"] ~= nil then
|
|
||||||
elements[n].eventresponder["reset"](elements[n])
|
elements[n].eventresponder["reset"](elements[n])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2096,6 +2096,7 @@ function process_event(source, what)
|
|||||||
state.mouse_down_counter = 0
|
state.mouse_down_counter = 0
|
||||||
|
|
||||||
elseif source == "mouse_move" then
|
elseif source == "mouse_move" then
|
||||||
|
|
||||||
local mouseX, mouseY = get_virt_mouse_pos()
|
local mouseX, mouseY = get_virt_mouse_pos()
|
||||||
if (user_opts.minmousemove == 0) or
|
if (user_opts.minmousemove == 0) or
|
||||||
(not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and
|
(not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and
|
||||||
@ -2107,15 +2108,9 @@ function process_event(source, what)
|
|||||||
end
|
end
|
||||||
state.last_mouseX, state.last_mouseY = mouseX, mouseY
|
state.last_mouseX, state.last_mouseY = mouseX, mouseY
|
||||||
|
|
||||||
if not (state.active_element == nil) then
|
local n = state.active_element
|
||||||
|
if element_has_action(elements[n], action) then
|
||||||
local n = state.active_element
|
elements[n].eventresponder[action](elements[n])
|
||||||
|
|
||||||
if not (n > #elements) and not (elements[n].eventresponder == nil) then
|
|
||||||
if not (elements[n].eventresponder[source] == nil) then
|
|
||||||
elements[n].eventresponder[source](elements[n])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
tick()
|
tick()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user