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
60 shadow_y_offset = 0.0,60 shadow_y_offset = 0.0,
61 shadow_color = "",61 shadow_color = "",
62 alpha = "11",62 alpha = "11",
63 vidscale = true,
63 64
64 -- Custom header for ASS tags to style the text output.65 -- Custom header for ASS tags to style the text output.
65 -- Specifying this will ignore the text style values above and just66 -- Specifying this will ignore the text style values above and just
@@ -101,6 +102,12 @@ local format = string.format · 35 unmodified lines
101local max = math.max102local max = math.max
102local min = math.min103local min = math.min
103 104
105-- Scaled metrics
106local font_size = o.font_size
107local border_size = o.border_size
108local shadow_x_offset = o.shadow_x_offset
109local shadow_y_offset = o.shadow_y_offset
110local plot_bg_border_width = o.plot_bg_border_width
104-- Function used to record performance data111-- Function used to record performance data
105local recorder = nil112local recorder = nil
106-- Timer used for redrawing (toggling) and clearing the screen (oneshot)113-- Timer used for redrawing (toggling) and clearing the screen (oneshot)
@@ -162,7 +169,7 @@ local function text_style() · 55 unmodified lines
162 if o.custom_header and o.custom_header ~= "" then169 if o.custom_header and o.custom_header ~= "" then
163 return o.custom_header170 return o.custom_header
164 else171 else
165 local style = "{\\r\\an7\\fs" .. o.font_size .. "\\bord" .. o.border_size172 local style = "{\\r\\an7\\fs" .. font_size .. "\\bord" .. border_size
166 173
167 if o.font ~= "" then174 if o.font ~= "" then
168 style = style .. "\\fn" .. o.font175 style = style .. "\\fn" .. o.font
@@ -180,8 +187,8 @@ local function text_style() · 11 unmodified lines
180 style = style .. "\\4c&H" .. o.shadow_color .. "&\\4a&H" .. o.alpha .. "&"187 style = style .. "\\4c&H" .. o.shadow_color .. "&\\4a&H" .. o.alpha .. "&"
181 end188 end
182 189
183 return style .. "\\xshad" .. o.shadow_x_offset ..190 return style .. "\\xshad" .. shadow_x_offset ..
184 "\\yshad" .. o.shadow_y_offset .. "}"191 "\\yshad" .. shadow_y_offset .. "}"
185 end192 end
186end193end
187 194
@@ -211,8 +218,8 @@ local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics) · 23 unmodified lines
211 end218 end
212 219
213 local x_max = (len - 1) * x_tics220 local x_max = (len - 1) * x_tics
214 local y_offset = o.border_size221 local y_offset = border_size
215 local y_max = o.font_size * 0.66222 local y_max = font_size * 0.66
216 local x = 0223 local x = 0
217 224
218 if v_max > 0 then225 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
237 s[#s+1] = format("%f %f %f %f", x, y_max, 0, y_max)244 s[#s+1] = format("%f %f %f %f", x, y_max, 0, y_max)
238 245
239 local bg_box = format("{\\bord%f}{\\3c&H%s&}{\\1c&H%s&}m 0 %f l %f %f %f 0 0 0",246 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)
241 return format("%s{\\rDefault}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s",248 return format("%s{\\rDefault}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s",
242 o.prefix_sep, y_offset, bg_box, o.plot_color, table.concat(s), text_style())249 o.prefix_sep, y_offset, bg_box, o.plot_color, table.concat(s), text_style())
243end250end
@@ -300,7 +307,7 @@ local function scroll_hint(search) · 56 unmodified lines
300 end307 end
301 hint = hint .. ")"308 hint = hint .. ")"
302 if not o.use_ass then return " " .. hint end309 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)
304end311end
305 312
306local function append_perfdata(header, s, dedicated_page, print_passes)313local 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
347 local h = dedicated_page and header or s354 local h = dedicated_page and header or s
348 h[#h+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}%s",355 h[#h+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}%s",
349 dedicated_page and "" or o.nl, dedicated_page and "" or o.indent,356 dedicated_page and "" or o.nl, dedicated_page and "" or o.indent,
350 b("Frame Timings:"), o.prefix_sep, o.font_size * 0.66,357 b("Frame Timings:"), o.prefix_sep, font_size * 0.66,
351 "(last/average/peak μs)", o.font_size,358 "(last/average/peak μs)", font_size,
352 dedicated_page and scroll_hint() or "")359 dedicated_page and scroll_hint() or "")
353 360
354 for _,frame in ipairs(sorted_keys(vo_p)) do -- ensure fixed display order361 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
507 local kpost = term and " " or format(" {\\fn%s}", o.font)514 local kpost = term and " " or format(" {\\fn%s}", o.font)
508 local spre = term and kspaces .. " "515 local spre = term and kspaces .. " "
509 or format("{\\q2\\fn%s}%s {\\fn%s}{\\fs%d\\u1}",516 or format("{\\q2\\fn%s}%s {\\fn%s}{\\fs%d\\u1}",
510 o.font_mono, kspaces, o.font, 1.3*o.font_size)517 o.font_mono, kspaces, o.font, 1.3*font_size)
511 local spost = term and "" or format("{\\u0\\fs%d}", o.font_size)518 local spost = term and "" or format("{\\u0\\fs%d}", font_size)
512 519
513 -- create the display lines520 -- create the display lines
514 local info_lines = {}521 local info_lines = {}
@@ -1340,6 +1347,24 @@ local function print_page(page, after_scroll) · 825 unmodified lines
1340 end1347 end
1341end1348end
1342 1349
1350local 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
1367end
1343 1368
1344local function clear_screen()1369local function clear_screen()
1345 if o.persistent_overlay then mp.set_osd_ass(0, 0, "") else mp.osd_message("", 0) end1370 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
1566 mp.command("quit")1591 mp.command("quit")
1567 end)1592 end)
1568end1593end
1594
1595mp.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