mirror of https://github.com/mpv-player/mpv
stats.lua: add option to disable scale with video size
This adds a new configuration option vidscale, which controls whether stats display is scaled with video, similar to the option for OSC.lua.
This commit is contained in:
parent
d283688939
commit
db6b195f3f
|
@ -198,6 +198,12 @@ Configurable Options
|
|||
|
||||
Color used for drawing graphs.
|
||||
|
||||
``vidscale``
|
||||
Default: yes
|
||||
|
||||
Scale the text and graphs with the video.
|
||||
``no`` tries to keep the sizes constant.
|
||||
|
||||
Note: colors are given as hexadecimal values and use ASS tag order: BBGGRR
|
||||
(blue green red).
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ local o = {
|
|||
shadow_y_offset = 0.0,
|
||||
shadow_color = "",
|
||||
alpha = "11",
|
||||
vidscale = true,
|
||||
|
||||
-- Custom header for ASS tags to style the text output.
|
||||
-- Specifying this will ignore the text style values above and just
|
||||
|
@ -101,6 +102,12 @@ local format = string.format
|
|||
local max = math.max
|
||||
local min = math.min
|
||||
|
||||
-- Scaled metrics
|
||||
local font_size = o.font_size
|
||||
local border_size = o.border_size
|
||||
local shadow_x_offset = o.shadow_x_offset
|
||||
local shadow_y_offset = o.shadow_y_offset
|
||||
local plot_bg_border_width = o.plot_bg_border_width
|
||||
-- Function used to record performance data
|
||||
local recorder = nil
|
||||
-- Timer used for redrawing (toggling) and clearing the screen (oneshot)
|
||||
|
@ -162,7 +169,7 @@ local function text_style()
|
|||
if o.custom_header and o.custom_header ~= "" then
|
||||
return o.custom_header
|
||||
else
|
||||
local style = "{\\r\\an7\\fs" .. o.font_size .. "\\bord" .. o.border_size
|
||||
local style = "{\\r\\an7\\fs" .. font_size .. "\\bord" .. border_size
|
||||
|
||||
if o.font ~= "" then
|
||||
style = style .. "\\fn" .. o.font
|
||||
|
@ -180,8 +187,8 @@ local function text_style()
|
|||
style = style .. "\\4c&H" .. o.shadow_color .. "&\\4a&H" .. o.alpha .. "&"
|
||||
end
|
||||
|
||||
return style .. "\\xshad" .. o.shadow_x_offset ..
|
||||
"\\yshad" .. o.shadow_y_offset .. "}"
|
||||
return style .. "\\xshad" .. shadow_x_offset ..
|
||||
"\\yshad" .. shadow_y_offset .. "}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -211,8 +218,8 @@ local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics)
|
|||
end
|
||||
|
||||
local x_max = (len - 1) * x_tics
|
||||
local y_offset = o.border_size
|
||||
local y_max = o.font_size * 0.66
|
||||
local y_offset = border_size
|
||||
local y_max = font_size * 0.66
|
||||
local x = 0
|
||||
|
||||
if v_max > 0 then
|
||||
|
@ -237,7 +244,7 @@ local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics)
|
|||
s[#s+1] = format("%f %f %f %f", x, y_max, 0, y_max)
|
||||
|
||||
local bg_box = format("{\\bord%f}{\\3c&H%s&}{\\1c&H%s&}m 0 %f l %f %f %f 0 0 0",
|
||||
o.plot_bg_border_width, o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max)
|
||||
plot_bg_border_width, o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max)
|
||||
return format("%s{\\rDefault}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s",
|
||||
o.prefix_sep, y_offset, bg_box, o.plot_color, table.concat(s), text_style())
|
||||
end
|
||||
|
@ -300,7 +307,7 @@ local function scroll_hint(search)
|
|||
end
|
||||
hint = hint .. ")"
|
||||
if not o.use_ass then return " " .. hint end
|
||||
return format(" {\\fs%s}%s{\\fs%s}", o.font_size * 0.66, hint, o.font_size)
|
||||
return format(" {\\fs%s}%s{\\fs%s}", font_size * 0.66, hint, font_size)
|
||||
end
|
||||
|
||||
local function append_perfdata(header, s, dedicated_page, print_passes)
|
||||
|
@ -347,8 +354,8 @@ local function append_perfdata(header, s, dedicated_page, print_passes)
|
|||
local h = dedicated_page and header or s
|
||||
h[#h+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}%s",
|
||||
dedicated_page and "" or o.nl, dedicated_page and "" or o.indent,
|
||||
b("Frame Timings:"), o.prefix_sep, o.font_size * 0.66,
|
||||
"(last/average/peak μs)", o.font_size,
|
||||
b("Frame Timings:"), o.prefix_sep, font_size * 0.66,
|
||||
"(last/average/peak μs)", font_size,
|
||||
dedicated_page and scroll_hint() or "")
|
||||
|
||||
for _,frame in ipairs(sorted_keys(vo_p)) do -- ensure fixed display order
|
||||
|
@ -507,8 +514,8 @@ local function get_kbinfo_lines()
|
|||
local kpost = term and " " or format(" {\\fn%s}", o.font)
|
||||
local spre = term and kspaces .. " "
|
||||
or format("{\\q2\\fn%s}%s {\\fn%s}{\\fs%d\\u1}",
|
||||
o.font_mono, kspaces, o.font, 1.3*o.font_size)
|
||||
local spost = term and "" or format("{\\u0\\fs%d}", o.font_size)
|
||||
o.font_mono, kspaces, o.font, 1.3*font_size)
|
||||
local spost = term and "" or format("{\\u0\\fs%d}", font_size)
|
||||
|
||||
-- create the display lines
|
||||
local info_lines = {}
|
||||
|
@ -1340,6 +1347,24 @@ local function print_page(page, after_scroll)
|
|||
end
|
||||
end
|
||||
|
||||
local function update_scale(name, value)
|
||||
-- Calculate scaled metrics.
|
||||
local scale = 1
|
||||
if not o.vidscale then
|
||||
if value <= 1 then
|
||||
value = 1
|
||||
end
|
||||
scale = 720 / value
|
||||
end
|
||||
font_size = o.font_size * scale
|
||||
border_size = o.border_size * scale
|
||||
shadow_x_offset = o.shadow_x_offset * scale
|
||||
shadow_y_offset = o.shadow_y_offset * scale
|
||||
plot_bg_border_width = o.plot_bg_border_width * scale
|
||||
if display_timer:is_enabled() then
|
||||
print_page(curr_page)
|
||||
end
|
||||
end
|
||||
|
||||
local function clear_screen()
|
||||
if o.persistent_overlay then mp.set_osd_ass(0, 0, "") else mp.osd_message("", 0) end
|
||||
|
@ -1566,3 +1591,5 @@ if o.bindlist ~= "no" then
|
|||
mp.command("quit")
|
||||
end)
|
||||
end
|
||||
|
||||
mp.observe_property('osd-height', 'native', update_scale)
|
||||
|
|
Loading…
Reference in New Issue