Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{stats,osc}.lua: respect --osd-scale-by-window by default #14158

Merged
merged 6 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DOCS/interface-changes/osdscale.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
change `vidscale` script option type to string for osc.lua
change `vidscale` script option type to string for stats.lua
change `vidscale` default from `yes` to `auto` for osc.lua and stats.lua
8 changes: 7 additions & 1 deletion DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4474,12 +4474,18 @@ OSD
are always in actual pixels. The effect is that changing the window size
won't change the OSD font size.

.. note::

For scripts which draw user interface elements, it is recommended to
respect the value of this option when deciding whether the elements
are scaled with window size or not.

``--osd-shadow-color=<color>``
See ``--sub-color``. Color used for OSD shadow.

.. note::

ignored when ``--osd-back-color`` is specified (or more exactly: when
Ignored when ``--osd-back-color`` is specified (or more exactly: when
that option is not set to completely transparent).

``--osd-shadow-offset=<size>``
Expand Down
8 changes: 5 additions & 3 deletions DOCS/man/osc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ Configurable Options
Scale factor of the OSC when fullscreen

``vidscale``
Default: yes
Default: auto

Scale the OSC with the video
``no`` tries to keep the OSC size constant as much as the window size allows
Scale the OSC with the video.
``no`` tries to keep the OSC size constant as much as the window size allows.
``auto`` scales the OSC with the OSD, which is scaled with the window or kept at a
constant size, depending on the ``--osd-scale-by-window`` option.

``valign``
Default: 0.8
Expand Down
4 changes: 3 additions & 1 deletion DOCS/man/stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ Configurable Options
Color used for drawing graphs.

``vidscale``
Default: yes
Default: auto

Scale the text and graphs with the video.
``no`` tries to keep the sizes constant.
``auto`` scales the text and graphs with the OSD, which is scaled with the
window or kept at a constant size, depending on the ``--osd-scale-by-window`` option.

Note: colors are given as hexadecimal values and use ASS tag order: BBGGRR
(blue green red).
Expand Down
12 changes: 10 additions & 2 deletions player/lua/osc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local user_opts = {
idlescreen = true, -- show mpv logo on idle
scalewindowed = 1, -- scaling of the controller when windowed
scalefullscreen = 1, -- scaling of the controller when fullscreen
vidscale = true, -- scale the controller with the video?
vidscale = "auto", -- scale the controller with the video?
valign = 0.8, -- vertical alignment, -1 (top) to 1 (bottom)
halign = 0, -- horizontal alignment, -1 (left) to 1 (right)
barmargin = 0, -- vertical margin of top/bottombar
Expand Down Expand Up @@ -1785,7 +1785,14 @@ function osc_init()
scale = user_opts.scalewindowed
end

if user_opts.vidscale then
local scale_with_video
if user_opts.vidscale == "auto" then
scale_with_video = mp.get_property_native("osd-scale-by-window")
else
scale_with_video = user_opts.vidscale == "yes"
end

if scale_with_video then
osc_param.unscaled_y = baseResY
else
osc_param.unscaled_y = display_h
Expand Down Expand Up @@ -2844,6 +2851,7 @@ mp.observe_property("osd-dimensions", "native", function()
-- we might have to worry about property update ordering)
request_init_resize()
end)
mp.observe_property('osd-scale-by-window', 'native', request_init_resize)

-- mouse show/hide bindings
mp.set_key_bindings({
Expand Down
25 changes: 21 additions & 4 deletions player/lua/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ local o = {
shadow_y_offset = 0.0,
shadow_color = "",
alpha = "11",
vidscale = true,
vidscale = "auto",

-- Custom header for ASS tags to style the text output.
-- Specifying this will ignore the text style values above and just
Expand Down Expand Up @@ -1353,10 +1353,17 @@ local function print_page(page, after_scroll)
end
end

local function update_scale(_, value)
local function update_scale(value)
local scale_with_video
if o.vidscale == "auto" then
scale_with_video = mp.get_property_native("osd-scale-by-window")
else
scale_with_video = o.vidscale == "yes"
end

-- Calculate scaled metrics.
local scale = 1
if not o.vidscale and value > 0 then
if not scale_with_video and value > 0 then
scale = 720 / value
end
font_size = o.font_size * scale
Expand All @@ -1369,6 +1376,15 @@ local function update_scale(_, value)
end
end

local function handle_osd_height_update(_, value)
update_scale(value)
end

local function handle_osd_scale_by_window_update()
local value = mp.get_property_native("osd-height")
update_scale(value)
end

local function clear_screen()
if o.persistent_overlay then mp.set_osd_ass(0, 0, "") else mp.osd_message("", 0) end
end
Expand Down Expand Up @@ -1597,4 +1613,5 @@ if o.bindlist ~= "no" then
end)
end

mp.observe_property('osd-height', 'native', update_scale)
mp.observe_property('osd-height', 'native', handle_osd_height_update)
mp.observe_property('osd-scale-by-window', 'native', handle_osd_scale_by_window_update)
Loading