summaryrefslogtreecommitdiffstats
path: root/player/lua/stats.lua
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2024-04-15 00:43:17 -0400
committerKacper Michajłow <kasper93@gmail.com>2024-04-18 18:44:53 +0200
commitdb6b195f3fc5b6e6989c3203eeccdb33dcc29b24 (patch)
tree7d26625a4d8f5373bd76844d5ff396f3bdbc7084 /player/lua/stats.lua
parentd28368893948239481387034db7ac9ee9f25a244 (diff)
downloadmpv-db6b195f3fc5b6e6989c3203eeccdb33dcc29b24.tar.bz2
mpv-db6b195f3fc5b6e6989c3203eeccdb33dcc29b24.tar.xz
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.
Diffstat (limited to 'player/lua/stats.lua')
-rw-r--r--player/lua/stats.lua49
1 files changed, 38 insertions, 11 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua
index 76d50e0eff..1cc3eb879a 100644
--- a/player/lua/stats.lua
+++ b/player/lua/stats.lua
@@ -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)