osc: add feature to bottombar to not cover the video

Normally I use the OSC like this: not at all, but have a key binding
that does "cycle osc" to show it. And in that case, I don't really want
it to overlap the damn video.

I could use the zoom/pan options to move the video out of the way, but
this is also sort of annoying. Likewise, you could write a script or so
which does this automatically if the OSC appears, but that's still
annoying, and computing values for these options such that the video is
moved correctly is tricky.

So I added a bunch of options that set explicit video borders (previous
commit), and a option for the OSC to use them (this commit).

Disabled by default, since I'm afraid this is too awkward and
unpolished, especially with OSC default settings.

I'm also using "osc-visibility=always". Effectively, making the OSC
appear will box the video, and making it disappear (by unloading
osc.lua) will restore the video back to normal.
This commit is contained in:
wm4 2019-06-15 18:02:54 +02:00
parent 0b4790f23f
commit 530b203e5d
2 changed files with 67 additions and 1 deletions

View File

@ -321,6 +321,26 @@ Configurable Options
default is conservative to allow wide fonts to be used without overflow.
However, with many common fonts a bigger number can be used. YMMV.
``boxvideo``
Default: no
Whether to overlay the osc over the video (``no``), or to box the video
within the areas not covered by the osc (``yes``). If this option is set,
the osc may overwrite the ``--video-margin-ratio-*`` options, even if the
user has set them. (It will not overwrite them if all of them are set to
default values.)
Currently, this is supported for the ``bottombar`` layout only. The other
layouts do not change if this option is set.
The border is static and appears even if the OSC is configured to appear
only on mouse interaction. If the OSC is invisible, the border is simply
filled with the background color (black by default).
This currently still makes the OSC overlap with subtitles (if the
``--sub-use-margins`` option is set to ``yes``, the default). This may be
fixed later.
Script Commands
~~~~~~~~~~~~~~~

View File

@ -44,6 +44,7 @@ local user_opts = {
timems = false, -- display timecodes with milliseconds?
visibility = "auto", -- only used at init to set visibility_mode(...)
boxmaxchars = 80, -- title crop threshold for box layout
boxvideo = false, -- apply osc_param.video_margins to video
}
-- read_options may modify hidetimeout, so save the original default value in
@ -62,6 +63,9 @@ local osc_param = { -- calculated by osc_init()
display_aspect = 1,
unscaled_y = 0,
areas = {},
video_margins = {
l = 0, r = 0, t = 0, b = 0, -- left/right/top/bottom
},
}
local osc_styles = {
@ -108,6 +112,7 @@ local state = {
input_enabled = true,
showhide_enabled = false,
dmx_cache = 0,
using_video_margins = false,
}
@ -117,6 +122,13 @@ local state = {
-- Helperfunctions
--
local margins_opts = {
{"l", "video-margin-ratio-left"},
{"r", "video-margin-ratio-right"},
{"t", "video-margin-ratio-top"},
{"b", "video-margin-ratio-bottom"},
}
-- scale factor for translating between real and virtual ASS coordinates
function get_virt_scale_factor()
local w, h = mp.get_osd_size()
@ -1408,6 +1420,8 @@ layouts["bottombar"] = function()
lo.slider.tooltip_an = 5
lo.slider.stype = user_opts["seekbarstyle"]
lo.slider.rtype = user_opts["seekrangestyle"]
osc_param.video_margins.b = osc_geo.h / osc_param.playresy
end
layouts["topbar"] = function()
@ -1998,9 +2012,40 @@ function osc_init()
--do something with the elements
prepare_elements()
if user_opts.boxvideo then
-- check whether any margin option has a non-default value
local margins_used = false
for _, opt in ipairs(margins_opts) do
if mp.get_property_number(opt[2], 0.0) ~= 0.0 then
margins_used = true
end
end
if not margins_used then
local margins = osc_param.video_margins
for _, opt in ipairs(margins_opts) do
local v = margins[opt[1]]
if v ~= 0 then
mp.set_property_number(opt[2], v)
state.using_video_margins = true
end
end
end
else
reset_margins()
end
end
function reset_margins()
if state.using_video_margins then
for _, opt in ipairs(margins_opts) do
mp.set_property_number(opt[2], 0.0)
end
state.using_video_margins = false
end
end
--
-- Other important stuff
@ -2386,6 +2431,7 @@ end
validate_user_opts()
mp.register_event("shutdown", reset_margins)
mp.register_event("start-file", request_init)
mp.register_event("tracks-changed", request_init)
mp.observe_property("playlist", nil, request_init)