From b7ec9b8cb1b8417a19caf09366488357335e1053 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Thu, 16 May 2024 09:47:44 -0400 Subject: [PATCH 1/6] DOCS/man/options.rst: recommend --osd-scale-by-window for UI scale This recommends querying the value of this option when drawing UI elements. This allows a greater level of consistency by using a single flag which already controls the scaling behavior of the OSD to control the behavior of all scripts. Also fix a capitalization nearby. --- DOCS/man/options.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 8ef6a65a0e491..bc4dd56ad0c1d 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -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=`` 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=`` From bd3e1e3536a29e180a557fe996cbbbbcff596016 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Thu, 16 May 2024 09:54:34 -0400 Subject: [PATCH 2/6] osc.lua: add auto value to vidscale option This adds auto to vidscale script option, which lets the scale be inherited from OSD --osd-scale-by-window option. --- DOCS/interface-changes/osdscale.txt | 1 + DOCS/man/osc.rst | 6 ++++-- player/lua/osc.lua | 11 +++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 DOCS/interface-changes/osdscale.txt diff --git a/DOCS/interface-changes/osdscale.txt b/DOCS/interface-changes/osdscale.txt new file mode 100644 index 0000000000000..edae2a60772e0 --- /dev/null +++ b/DOCS/interface-changes/osdscale.txt @@ -0,0 +1 @@ +change `vidscale` script option type to string for osc.lua diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index 0a9b54c5cfb25..58387cd9b07ec 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -250,8 +250,10 @@ Configurable Options ``vidscale`` Default: yes - 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 diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 6388c3e988eff..34ac3709565dc 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -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 = "yes", -- 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 @@ -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 From 514875befe5a88b8fe675c715d32240967820316 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Thu, 16 May 2024 10:08:06 -0400 Subject: [PATCH 3/6] stats.lua: add add auto value to vidscale option This adds auto to vidscale script option, which lets the scale be inherited from OSD --osd-scale-by-window option. --- DOCS/interface-changes/osdscale.txt | 1 + DOCS/man/stats.rst | 2 ++ player/lua/stats.lua | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/DOCS/interface-changes/osdscale.txt b/DOCS/interface-changes/osdscale.txt index edae2a60772e0..8108ef1df0155 100644 --- a/DOCS/interface-changes/osdscale.txt +++ b/DOCS/interface-changes/osdscale.txt @@ -1 +1,2 @@ change `vidscale` script option type to string for osc.lua +change `vidscale` script option type to string for stats.lua diff --git a/DOCS/man/stats.rst b/DOCS/man/stats.rst index 8bc0a3c651837..fc95e8d6f226c 100644 --- a/DOCS/man/stats.rst +++ b/DOCS/man/stats.rst @@ -203,6 +203,8 @@ Configurable Options 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). diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 1c9f1aac3734c..b044f01f3e562 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -60,7 +60,7 @@ local o = { shadow_y_offset = 0.0, shadow_color = "", alpha = "11", - vidscale = true, + vidscale = "yes", -- Custom header for ASS tags to style the text output. -- Specifying this will ignore the text style values above and just @@ -1354,9 +1354,16 @@ local function print_page(page, after_scroll) end 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 From 1dd46559180e3ee3099de131f32b596871c3e11c Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Thu, 16 May 2024 10:56:46 -0400 Subject: [PATCH 4/6] {stats,osc}.lua: respect --osd-scale-by-window by default This lets these scripts scale the elements with OSD by default. --- DOCS/interface-changes/osdscale.txt | 1 + DOCS/man/osc.rst | 2 +- DOCS/man/stats.rst | 2 +- player/lua/osc.lua | 2 +- player/lua/stats.lua | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DOCS/interface-changes/osdscale.txt b/DOCS/interface-changes/osdscale.txt index 8108ef1df0155..38eec1afc8a09 100644 --- a/DOCS/interface-changes/osdscale.txt +++ b/DOCS/interface-changes/osdscale.txt @@ -1,2 +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 diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index 58387cd9b07ec..dc8dad7c2ff6b 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -248,7 +248,7 @@ 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. diff --git a/DOCS/man/stats.rst b/DOCS/man/stats.rst index fc95e8d6f226c..30ce0796dfe8c 100644 --- a/DOCS/man/stats.rst +++ b/DOCS/man/stats.rst @@ -199,7 +199,7 @@ 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. diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 34ac3709565dc..d1ad14a84aa7e 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -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 = "yes", -- 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 diff --git a/player/lua/stats.lua b/player/lua/stats.lua index b044f01f3e562..d056d0e4e0c44 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -60,7 +60,7 @@ local o = { shadow_y_offset = 0.0, shadow_color = "", alpha = "11", - vidscale = "yes", + vidscale = "auto", -- Custom header for ASS tags to style the text output. -- Specifying this will ignore the text style values above and just From 8594b91fee1cedda1fbc18334d9a07722d7aa428 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Thu, 16 May 2024 12:30:52 -0400 Subject: [PATCH 5/6] stats.lua: handle osd-scale-by-window runtime update Allows the scale mode to be changed at runtime if vidscale is set to auto. --- player/lua/stats.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/player/lua/stats.lua b/player/lua/stats.lua index d056d0e4e0c44..e58a7f5bb0485 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -1353,7 +1353,7 @@ 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") @@ -1376,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 @@ -1604,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) From b0bc818377625aa3fe082822cd0d4cf502c0d8d3 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Thu, 16 May 2024 12:34:59 -0400 Subject: [PATCH 6/6] osc.lua: handle osd-scale-by-window runtime update Allows the scale mode to be changed at runtime if vidscale is set to auto. --- player/lua/osc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index d1ad14a84aa7e..0859afc9ba603 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -2851,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({