OSC: implemented user configurable colors

This commit is contained in:
omar 2024-04-20 14:57:08 +02:00 committed by Kacper Michajłow
parent 861908c70f
commit a26bbbd78d
2 changed files with 99 additions and 19 deletions

View File

@ -431,6 +431,57 @@ Configurable Options
Use a Unicode minus sign instead of an ASCII hyphen when displaying
the remaining playback time.
``background_color``
Default: #000000
Sets the background color of the OSC.
``timecode_color``
Default: #FFFFFF
Sets the color of the timecode and seekbar, of the OSC.
``title_color``
Default: #FFFFFF
Sets the color of the video title. Formatted as #RRGGBB.
``time_pos_color``
Default: #FFFFFF
Sets the color of the timecode at hover position in the seekbar.
``time_pos_outline_color``
Default: #FFFFFF
Sets the color of the timecode's outline at hover position in the seekbar.
Also affects the timecode in the slimbox layout.
``buttons_color``
Default: #FFFFFF
Sets the colors of the big buttons.
``top_buttons_color``
Default: #FFFFFF
Sets the colors of the top buttons.
``small_buttonsL_color``
Default: #FFFFFF
Sets the colors of the small buttons on the left in the box layout.
``small_buttonsR_color``
Default: #FFFFFF
Sets the colors of the small buttons on the right in the box layout.
``held_element_color``
Default: #999999
Sets the colors of the elements that are being pressed or held down.
Script Commands
~~~~~~~~~~~~~~~

View File

@ -60,6 +60,18 @@ local user_opts = {
playlist_media_title = true, -- whether to use media titles as playlist entry names
chapter_fmt = "Chapter: %s", -- chapter print format for seekbar-hover. "no" to disable
unicodeminus = false, -- whether to use the Unicode minus sign character
background_color = "#000000", -- background color of the osc
timecode_color = "#FFFFFF", -- color of the progress bar and time color
title_color = "#FFFFFF", -- color of the title
time_pos_color = "#FFFFFF", -- color of the timecode at hovered position
buttons_color = "#FFFFFF", -- color of big buttons, wc buttons, and bar small buttons
small_buttonsL_color = "#FFFFFF", -- color of left small buttons
small_buttonsR_color = "#FFFFFF", -- color of right small buttons
top_buttons_color = "#FFFFFF", -- color of top buttons
held_element_color = "#999999", -- color of an element while held down
time_pos_outline_color = "#000000" -- color of the border timecodes in slimbox and TimePosBar
}
-- read options from config and command-line
@ -76,27 +88,31 @@ local osc_param = { -- calculated by osc_init()
},
}
function osc_color_convert(color)
return color:sub(6,7) .. color:sub(4,5) .. color:sub(2,3)
end
local osc_styles = {
bigButtons = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs50\\fnmpv-osd-symbols}",
smallButtonsL = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs19\\fnmpv-osd-symbols}",
bigButtons = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\3c&HFFFFFF\\fs50\\fnmpv-osd-symbols}",
smallButtonsL = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.small_buttonsL_color) .. "\\3c&HFFFFFF\\fs19\\fnmpv-osd-symbols}",
smallButtonsLlabel = "{\\fscx105\\fscy105\\fn" .. mp.get_property("options/osd-font") .. "}",
smallButtonsR = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs30\\fnmpv-osd-symbols}",
topButtons = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs12\\fnmpv-osd-symbols}",
smallButtonsR = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.small_buttonsR_color) .. "\\3c&HFFFFFF\\fs30\\fnmpv-osd-symbols}",
topButtons = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.top_buttons_color) .. "\\3c&HFFFFFF\\fs12\\fnmpv-osd-symbols}",
elementDown = "{\\1c&H999999}",
timecodes = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs20}",
vidtitle = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs12\\q2}",
box = "{\\rDefault\\blur0\\bord1\\1c&H000000\\3c&HFFFFFF}",
elementDown = "{\\1c&H" .. osc_color_convert(user_opts.held_element_color) .."}",
timecodes = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.timecode_color) .. "\\3c&HFFFFFF\\fs20}",
vidtitle = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\3c&HFFFFFF\\fs12\\q2}",
box = "{\\rDefault\\blur0\\bord1\\1c&H" .. osc_color_convert(user_opts.background_color) .. "\\3c&HFFFFFF}",
topButtonsBar = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs18\\fnmpv-osd-symbols}",
smallButtonsBar = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs28\\fnmpv-osd-symbols}",
timecodesBar = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs27}",
timePosBar = "{\\blur0\\bord".. user_opts.tooltipborder .."\\1c&HFFFFFF\\3c&H000000\\fs30}",
vidtitleBar = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs18\\q2}",
topButtonsBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.top_buttons_color) .. "\\3c&HFFFFFF\\fs18\\fnmpv-osd-symbols}",
smallButtonsBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\3c&HFFFFFF\\fs28\\fnmpv-osd-symbols}",
timecodesBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.timecode_color) .."\\3c&HFFFFFF\\fs27}",
timePosBar = "{\\blur0\\bord".. user_opts.tooltipborder .."\\1c&H" .. osc_color_convert(user_opts.time_pos_color) .. "\\3c&H" .. osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs30}",
vidtitleBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\3c&HFFFFFF\\fs18\\q2}",
wcButtons = "{\\1c&HFFFFFF\\fs24\\fnmpv-osd-symbols}",
wcTitle = "{\\1c&HFFFFFF\\fs24\\q2}",
wcBar = "{\\1c&H000000}",
wcButtons = "{\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\fs24\\fnmpv-osd-symbols}",
wcTitle = "{\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\fs24\\q2}",
wcBar = "{\\1c&H" .. osc_color_convert(user_opts.background_color) .. "}",
}
-- internal states, do not touch
@ -1408,9 +1424,9 @@ layouts["slimbox"] = function ()
-- styles
local styles = {
box = "{\\rDefault\\blur0\\bord1\\1c&H000000\\3c&HFFFFFF}",
timecodes = "{\\1c&HFFFFFF\\3c&H000000\\fs20\\bord2\\blur1}",
tooltip = "{\\1c&HFFFFFF\\3c&H000000\\fs12\\bord1\\blur0.5}",
box = "{\\rDefault\\blur0\\bord1\\1c&H" .. osc_color_convert(user_opts.background_color) .. "\\3c&HFFFFFF}",
timecodes = "{\\1c&H" .. osc_color_convert(user_opts.timecode_color) .. "\\3c&H" .. osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs20\\bord2\\blur1}",
tooltip = "{\\1c&H" .. osc_color_convert(user_opts.time_pos_color).. "\\3c&H" .. osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs12\\bord1\\blur0.5}",
}
@ -1727,6 +1743,19 @@ function validate_user_opts()
user_opts.windowcontrols_alignment .. "\". Ignoring.")
user_opts.windowcontrols_alignment = "right"
end
local colors = {
user_opts.background_color, user_opts.top_buttons_color,
user_opts.small_buttonsL_color, user_opts.small_buttonsR_color,
user_opts.buttons_color, user_opts.title_color,
user_opts.timecode_color, user_opts.time_pos_color,
user_opts.held_element_color, user_opts.time_pos_outline_color,
}
for _, color in pairs(colors) do
if color:find("^#%x%x%x%x%x%x$") == nil then
msg.warn("'" .. color .. "' is not a valid color")
end
end
end
function update_options(list)