Skip to content

Commit

Permalink
osc: refactor osc message scaling
Browse files Browse the repository at this point in the history
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 mpv-player#4081, mpv-player#4083, mpv-player#4102
  • Loading branch information
wiiaboo committed Feb 3, 2017
1 parent bbf0134 commit 3d63691
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions player/lua/osc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
}

Expand Down Expand Up @@ -94,6 +95,7 @@ local state = {
message_text,
message_timeout,
fullscreen = false,
forcedwindow = false,
timer = nil,
cache_idle = false,
idle = false,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 3d63691

Please sign in to comment.