diff options
author | wm4 <wm4@nowhere> | 2016-03-07 22:20:51 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-03-07 22:22:18 +0100 |
commit | 5fa45fb5641c95a5dc65faac2087d842333b5425 (patch) | |
tree | 0807f5cff191b18427b36ebf5d30de25620ae033 /player/lua/osc.lua | |
parent | b7617f42d873adceebd3904d906e4eff818240ed (diff) | |
download | mpv-5fa45fb5641c95a5dc65faac2087d842333b5425.tar.bz2 mpv-5fa45fb5641c95a5dc65faac2087d842333b5425.tar.xz |
osd, lua: remove weird OSD scaling
Do not scale OSD mouse input to the ASS OSD script resolution. The
original idea of this mechanism was that the user doesn't have to care
about the actual resolution of anything, and can just use the OSD
resolution consistently. But this made things worse.
Remove the implicit scaling, and always use the screen resolution.
(Except with --vo=xv, where additional scaling is forced upon
everything.)
Drop get_osd_resolution(). There is no replacement. Rename
get_screen_size() and get_screen_margins() to use "osd" instead of
"screen". For anything but --vo=xv these are equivalent, but with
--vo=xv the OSD resolution has additional implicit scaling.
Add code to osc.lua which emulates the old behavior.
Note that none of the changed functions were public API, so implicit
breakage of scripts which used it is just going to happen.
Diffstat (limited to 'player/lua/osc.lua')
-rw-r--r-- | player/lua/osc.lua | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 24afeef970..f3beee85dd 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -99,6 +99,27 @@ local state = { -- Helperfunctions -- +-- scale factor for translating between real and virtual ASS coordinates +function get_virt_scale_factor() + local w, h = mp.get_osd_size() + if w <= 0 or h <= 0 then + return 0, 0 + end + return osc_param.playresx / w, osc_param.playresy / h +end + +-- return mouse position in virtual ASS coordinates (playresx/y) +function get_virt_mouse_pos() + local sx, sy = get_virt_scale_factor() + local x, y = mp.get_mouse_pos() + return x * sx, y * sy +end + +function set_virt_mouse_area(x0, y0, x1, y1, name) + local sx, sy = get_virt_scale_factor() + mp.set_mouse_area(x0 * sx, y0 * sy, x1 * sx, y1 * sy) +end + function scale_value(x0, x1, y0, y1, val) local m = (y1 - y0) / (x1 - x0) local b = y0 - (m * x0) @@ -141,7 +162,7 @@ function mouse_hit(element) end function mouse_hit_coords(bX1, bY1, bX2, bY2) - local mX, mY = mp.get_mouse_pos() + local mX, mY = get_virt_mouse_pos() return (mX >= bX1 and mX <= bX2 and mY >= bY1 and mY <= bY2) end @@ -182,7 +203,7 @@ end -- get value at current mouse position function get_slider_value(element) - return get_slider_value_at(element, mp.get_mouse_pos()) + return get_slider_value_at(element, get_virt_mouse_pos()) end function countone(val) @@ -589,7 +610,7 @@ function render_elements(master_ass) end elem_ass:new_event() - elem_ass:pos(mp.get_mouse_pos(), ty) + elem_ass:pos(get_virt_mouse_pos(), ty) elem_ass:an(an) elem_ass:append(slider_lo.tooltip_style) elem_ass:append(tooltiplabel) @@ -1298,7 +1319,7 @@ function osc_init() -- set canvas resolution according to display aspect and scaling setting local baseResY = 720 - local display_w, display_h, display_aspect = mp.get_screen_size() + local display_w, display_h, display_aspect = mp.get_osd_size() local scale = 1 if (mp.get_property("video") == "no") then -- dummy/forced window @@ -1718,8 +1739,8 @@ end function render() msg.debug("rendering") - local current_screen_sizeX, current_screen_sizeY, aspect = mp.get_screen_size() - local mouseX, mouseY = mp.get_mouse_pos() + local current_screen_sizeX, current_screen_sizeY, aspect = mp.get_osd_size() + local mouseX, mouseY = get_virt_mouse_pos() local now = mp.get_time() -- check if display changed, if so request reinit @@ -1782,7 +1803,7 @@ function render() --mouse show/hide area for k,cords in pairs(osc_param.areas["showhide"]) do - mp.set_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide") + set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide") end do_enable_keybindings() @@ -1791,7 +1812,7 @@ function render() for _,cords in ipairs(osc_param.areas["input"]) do if state.osc_visible then -- activate only when OSC is actually visible - mp.set_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "input") + set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "input") end if state.osc_visible ~= state.input_enabled then if state.osc_visible then @@ -1887,7 +1908,7 @@ function process_event(source, what) state.mouse_down_counter = 0 elseif source == "mouse_move" then - local mouseX, mouseY = mp.get_mouse_pos() + local mouseX, mouseY = get_virt_mouse_pos() if (user_opts.minmousemove == 0) or (not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and ((math.abs(mouseX - state.last_mouseX) >= user_opts.minmousemove) |