From 3d636910472bb605b90fa6020fab21a541368024 Mon Sep 17 00:00:00 2001 From: Ricardo Constantino Date: Fri, 3 Feb 2017 01:57:39 +0000 Subject: [PATCH] osc: refactor osc message scaling Will still hide playlist items with long enough filenames and osd-font-size but not as soon. osc messages should now preserve their scaling with fullscreen toggling and cycling through audio-only files and files with video. Closes #4081, #4083, #4102 --- player/lua/osc.lua | 63 ++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 160457458c4f7..a37d53078fa6b 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -54,6 +54,7 @@ local osc_param = { -- calculated by osc_init() playresy = 0, -- canvas size Y playresx = 0, -- canvas size X display_aspect = 1, + unscaled_y = 0, areas = {}, } @@ -94,6 +95,7 @@ local state = { message_text, message_timeout, fullscreen = false, + forcedwindow = false, timer = nil, cache_idle = false, idle = false, @@ -691,7 +693,7 @@ function limited_list(prop, pos) end local fs = tonumber(mp.get_property('options/osd-font-size')) - local max = math.ceil(720 / fs) + local max = math.ceil(osc_param.unscaled_y*0.75 / fs) if max % 2 == 0 then max = max - 1 end @@ -762,47 +764,30 @@ function show_message(text, duration) text = string.sub(text, 0, 4000) -- replace actual linebreaks with ASS linebreaks - -- and get the amount of lines along the way - local lines - text, lines = string.gsub(text, "\n", "\\N") + text = string.gsub(text, "\n", "\\N") - -- append a Zero-Width-Space to . and _ to enable - -- linebreaking of long filenames - text = string.gsub(text, "%.", ".\226\128\139") - text = string.gsub(text, "_", "_\226\128\139") - - local scale = 1 - if (mp.get_property("video") == "no") then - scale = user_opts.scaleforcedwindow - elseif state.fullscreen then - scale = user_opts.scalefullscreen - else - scale = user_opts.scalewindowed - end - - -- scale the fontsize for longer multi-line output - local fontsize = tonumber(mp.get_property("options/osd-font-size")) / scale - local outline = tonumber(mp.get_property("options/osd-border-size")) / scale - - - if lines > 12 then - fontsize, outline = fontsize / 1.5, outline / 1.25 - elseif lines > 8 then - fontsize, outline = fontsize / 1.25, outline / 1.125 - end - - local style = "{\\bord" .. outline .. "\\fs" .. fontsize .. "}" - - state.message_text = style .. text + state.message_text = text state.message_timeout = mp.get_time() + duration end function render_message(ass) if not(state.message_timeout == nil) and not(state.message_text == nil) and state.message_timeout > mp.get_time() then + local _, lines = string.gsub(state.message_text, "\\N", "") + + local fontsize = tonumber(mp.get_property("options/osd-font-size")) + local outline = tonumber(mp.get_property("options/osd-border-size")) + local maxlines = math.ceil(osc_param.unscaled_y*0.75 / fontsize) + local counterscale = osc_param.playresy / osc_param.unscaled_y + + fontsize = fontsize * counterscale / math.max(0.5 + math.min(lines/maxlines, 1), 1) + outline = outline * counterscale / math.max(0.5 + math.min(lines/maxlines, 1)/2, 1) + + local style = "{\\bord" .. outline .. "\\fs" .. fontsize .. "}" + ass:new_event() - ass:append(state.message_text) + ass:append(style .. state.message_text) else state.message_text = nil state.message_timeout = nil @@ -1489,7 +1474,7 @@ function osc_init() local display_w, display_h, display_aspect = mp.get_osd_size() local scale = 1 - if (mp.get_property("video") == "no") then -- dummy/forced window + if state.forcedwindow then -- dummy/forced window scale = user_opts.scaleforcedwindow elseif state.fullscreen then scale = user_opts.scalefullscreen @@ -1498,10 +1483,11 @@ function osc_init() end if user_opts.vidscale then - osc_param.playresy = baseResY / scale + osc_param.unscaled_y = baseResY else - osc_param.playresy = display_h / scale + osc_param.unscaled_y = displayH end + osc_param.playresy = osc_param.unscaled_y / scale osc_param.playresx = osc_param.playresy * display_aspect osc_param.display_aspect = display_aspect @@ -2241,6 +2227,11 @@ mp.observe_property("vo-configured", "bool", function(name, val) mp.unregister_event(tick) end end) +mp.observe_property("video", "native", + function(name,val) + state.forcedwindow = (type(val) ~= "number") + end +) -- mouse show/hide bindings mp.set_key_bindings({