From 51bd00c33a905c3e5de149870b897bc99843e0be Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Mon, 13 Nov 2023 08:46:29 +0100 Subject: stats.lua: inherit OSD styles Avoid having to configure both the OSD and the stats script opts when you change the OSD options, in particular avoid having to convert colors to BGR. Also document the shadow options. font_size, border_size and shadow offset defaults are kept because the same values look much bigger in the stats than in the corresponding OSD options. osd-back-color is now respected without extra checks until you explicitly set a shadow_color. --- player/lua/stats.lua | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'player/lua') diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 3d093c7e2e..d07e4dc123 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -47,15 +47,15 @@ local o = { plot_color = "FFFFFF", -- Text style - font = "sans-serif", + font = "", font_mono = "monospace", -- monospaced digits are sufficient font_size = 8, - font_color = "FFFFFF", + font_color = "", border_size = 0.8, - border_color = "262626", + border_color = "", shadow_x_offset = 0.0, shadow_y_offset = 0.0, - shadow_color = "000000", + shadow_color = "", alpha = "11", -- Custom header for ASS tags to style the text output. @@ -158,13 +158,26 @@ local function text_style() if o.custom_header and o.custom_header ~= "" then return o.custom_header else - local has_shadow = mp.get_property('osd-back-color'):sub(2, 3) == '00' - return format("{\\r\\an7\\fs%d\\fn%s\\bord%f\\3c&H%s&" .. - "\\1c&H%s&\\1a&H%s&\\3a&H%s&" .. - (has_shadow and "\\4a&H%s&\\xshad%f\\yshad%f\\4c&H%s&}" or "}"), - o.font_size, o.font, o.border_size, - o.border_color, o.font_color, o.alpha, o.alpha, o.alpha, - o.shadow_x_offset, o.shadow_y_offset, o.shadow_color) + local style = "{\\r\\an7\\fs" .. o.font_size .. "\\bord" .. o.border_size + + if o.font ~= "" then + style = style .. "\\fn" .. o.font + end + + if o.font_color ~= "" then + style = style .. "\\1c&H" .. o.font_color .. "&\\1a&H" .. o.alpha .. "&" + end + + if o.border_color ~= "" then + style = style .. "\\3c&H" .. o.border_color .. "&\\3a&H" .. o.alpha .. "&" + end + + if o.shadow_color ~= "" then + style = style .. "\\4c&H" .. o.shadow_color .. "&\\4a&H" .. o.alpha .. "&" + end + + return style .. "\\xshad" .. o.shadow_x_offset .. + "\\yshad" .. o.shadow_y_offset .. "}" end end -- cgit v1.2.3