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.
This commit is contained in:
Guido Cella 2023-11-13 08:46:29 +01:00 committed by Kacper Michajłow
parent 75d899bcaf
commit 51bd00c33a
2 changed files with 47 additions and 17 deletions

View File

@ -120,7 +120,7 @@ Configurable Options
Clear data buffers used for drawing graphs when toggling. Clear data buffers used for drawing graphs when toggling.
``font`` ``font``
Default: sans-serif Default: same as ``osd-font``
Font name. Should support as many font weights as possible for optimal Font name. Should support as many font weights as possible for optimal
visual experience. visual experience.
@ -137,9 +137,9 @@ Configurable Options
Font size used to render text. Font size used to render text.
``font_color`` ``font_color``
Default: FFFFFF Default: same as ``osd-color``
Font color. Color of the text.
``border_size`` ``border_size``
Default: 0.8 Default: 0.8
@ -147,14 +147,31 @@ Configurable Options
Size of border drawn around the font. Size of border drawn around the font.
``border_color`` ``border_color``
Default: 262626 Default: same as ``osd-border-color``
Color of drawn border. Color of the text border.
``shadow_x_offset``
Default: 0
The horizontal distance from the text to position the shadow at.
``shadow_y_offset``
Default: 0
The vertical distance from the text to position the shadow at.
``shadow_color``
Default: same as ``osd-shadow-color``
Color of the text shadow.
``alpha`` ``alpha``
Default: 11 Default: 11
Transparency for drawn text. Transparency of text when ``font_color`` is specified, of text borders when
``border_color`` is specified, and of text shadows when ``shadow_color`` is
specified.
``plot_bg_border_color`` ``plot_bg_border_color``
Default: 0000FF Default: 0000FF

View File

@ -47,15 +47,15 @@ local o = {
plot_color = "FFFFFF", plot_color = "FFFFFF",
-- Text style -- Text style
font = "sans-serif", font = "",
font_mono = "monospace", -- monospaced digits are sufficient font_mono = "monospace", -- monospaced digits are sufficient
font_size = 8, font_size = 8,
font_color = "FFFFFF", font_color = "",
border_size = 0.8, border_size = 0.8,
border_color = "262626", border_color = "",
shadow_x_offset = 0.0, shadow_x_offset = 0.0,
shadow_y_offset = 0.0, shadow_y_offset = 0.0,
shadow_color = "000000", shadow_color = "",
alpha = "11", alpha = "11",
-- Custom header for ASS tags to style the text output. -- 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 if o.custom_header and o.custom_header ~= "" then
return o.custom_header return o.custom_header
else else
local has_shadow = mp.get_property('osd-back-color'):sub(2, 3) == '00' local style = "{\\r\\an7\\fs" .. o.font_size .. "\\bord" .. o.border_size
return format("{\\r\\an7\\fs%d\\fn%s\\bord%f\\3c&H%s&" ..
"\\1c&H%s&\\1a&H%s&\\3a&H%s&" .. if o.font ~= "" then
(has_shadow and "\\4a&H%s&\\xshad%f\\yshad%f\\4c&H%s&}" or "}"), style = style .. "\\fn" .. o.font
o.font_size, o.font, o.border_size, end
o.border_color, o.font_color, o.alpha, o.alpha, o.alpha,
o.shadow_x_offset, o.shadow_y_offset, o.shadow_color) 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
end end