History

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.

nanahi committed 2 years ago

Commit db6b1951 parent d2836882 files · +44 −11Browse files

Showing the changes to player/lua/stats.lua (1 of 2 files). Show all

Unified · Split

player/lua/stats.lua+38−11
@@ -60,6 +60,7 @@ local o = { · 59 unmodified lines
6060 shadow_y_offset = 0.0,
6161 shadow_color = "",
6262 alpha = "11",
63+ vidscale = true,
6364
6465 -- Custom header for ASS tags to style the text output.
6566 -- Specifying this will ignore the text style values above and just
@@ -101,6 +102,12 @@ local format = string.format · 35 unmodified lines
101102 local max = math.max
102103 local min = math.min
103104
105+-- Scaled metrics
106+local font_size = o.font_size
107+local border_size = o.border_size
108+local shadow_x_offset = o.shadow_x_offset
109+local shadow_y_offset = o.shadow_y_offset
110+local plot_bg_border_width = o.plot_bg_border_width
104111 -- Function used to record performance data
105112 local recorder = nil
106113 -- Timer used for redrawing (toggling) and clearing the screen (oneshot)
@@ -162,7 +169,7 @@ local function text_style() · 55 unmodified lines
162169 if o.custom_header and o.custom_header ~= "" then
163170 return o.custom_header
164171 else
165− local style = "{\\r\\an7\\fs" .. o.font_size .. "\\bord" .. o.border_size
172+ local style = "{\\r\\an7\\fs" .. font_size .. "\\bord" .. border_size
166173
167174 if o.font ~= "" then
168175 style = style .. "\\fn" .. o.font
@@ -180,8 +187,8 @@ local function text_style() · 11 unmodified lines
180187 style = style .. "\\4c&H" .. o.shadow_color .. "&\\4a&H" .. o.alpha .. "&"
181188 end
182189
183− return style .. "\\xshad" .. o.shadow_x_offset ..
184− "\\yshad" .. o.shadow_y_offset .. "}"
190+ return style .. "\\xshad" .. shadow_x_offset ..
191+ "\\yshad" .. shadow_y_offset .. "}"
185192 end
186193 end
187194
@@ -211,8 +218,8 @@ local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics) · 23 unmodified lines
211218 end
212219
213220 local x_max = (len - 1) * x_tics
214− local y_offset = o.border_size
215− local y_max = o.font_size * 0.66
221+ local y_offset = border_size
222+ local y_max = font_size * 0.66
216223 local x = 0
217224
218225 if v_max > 0 then
@@ -237,7 +244,7 @@ local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics) · 18 unmodified lines
237244 s[#s+1] = format("%f %f %f %f", x, y_max, 0, y_max)
238245
239246 local bg_box = format("{\\bord%f}{\\3c&H%s&}{\\1c&H%s&}m 0 %f l %f %f %f 0 0 0",
240− o.plot_bg_border_width, o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max)
247+ plot_bg_border_width, o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max)
241248 return format("%s{\\rDefault}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s",
242249 o.prefix_sep, y_offset, bg_box, o.plot_color, table.concat(s), text_style())
243250 end
@@ -300,7 +307,7 @@ local function scroll_hint(search) · 56 unmodified lines
300307 end
301308 hint = hint .. ")"
302309 if not o.use_ass then return " " .. hint end
303− return format(" {\\fs%s}%s{\\fs%s}", o.font_size * 0.66, hint, o.font_size)
310+ return format(" {\\fs%s}%s{\\fs%s}", font_size * 0.66, hint, font_size)
304311 end
305312
306313 local function append_perfdata(header, s, dedicated_page, print_passes)
@@ -347,8 +354,8 @@ local function append_perfdata(header, s, dedicated_page, print_passes) · 40 unmodified lines
347354 local h = dedicated_page and header or s
348355 h[#h+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}%s",
349356 dedicated_page and "" or o.nl, dedicated_page and "" or o.indent,
350− b("Frame Timings:"), o.prefix_sep, o.font_size * 0.66,
351− "(last/average/peak μs)", o.font_size,
357+ b("Frame Timings:"), o.prefix_sep, font_size * 0.66,
358+ "(last/average/peak μs)", font_size,
352359 dedicated_page and scroll_hint() or "")
353360
354361 for _,frame in ipairs(sorted_keys(vo_p)) do -- ensure fixed display order
@@ -507,8 +514,8 @@ local function get_kbinfo_lines() · 152 unmodified lines
507514 local kpost = term and " " or format(" {\\fn%s}", o.font)
508515 local spre = term and kspaces .. " "
509516 or format("{\\q2\\fn%s}%s {\\fn%s}{\\fs%d\\u1}",
510− o.font_mono, kspaces, o.font, 1.3*o.font_size)
511− local spost = term and "" or format("{\\u0\\fs%d}", o.font_size)
517+ o.font_mono, kspaces, o.font, 1.3*font_size)
518+ local spost = term and "" or format("{\\u0\\fs%d}", font_size)
512519
513520 -- create the display lines
514521 local info_lines = {}
@@ -1340,6 +1347,24 @@ local function print_page(page, after_scroll) · 825 unmodified lines
13401347 end
13411348 end
13421349
1350+local function update_scale(name, value)
1351+ -- Calculate scaled metrics.
1352+ local scale = 1
1353+ if not o.vidscale then
1354+ if value <= 1 then
1355+ value = 1
1356+ end
1357+ scale = 720 / value
1358+ end
1359+ font_size = o.font_size * scale
1360+ border_size = o.border_size * scale
1361+ shadow_x_offset = o.shadow_x_offset * scale
1362+ shadow_y_offset = o.shadow_y_offset * scale
1363+ plot_bg_border_width = o.plot_bg_border_width * scale
1364+ if display_timer:is_enabled() then
1365+ print_page(curr_page)
1366+ end
1367+end
13431368
13441369 local function clear_screen()
13451370 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 · 220 unmodified lines
15661591 mp.command("quit")
15671592 end)
15681593 end
1594+
1595+mp.observe_property('osd-height', 'native', update_scale)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t