Implement timeline_elements option

This commit is contained in:
tomasklaen
2022-08-20 21:28:30 +02:00
parent f85d7cfcdc
commit cb542459bd
2 changed files with 175 additions and 158 deletions

View File

@@ -27,9 +27,12 @@ timeline_step=5
timeline_cached_ranges=345433:0.8
# floating number font scale adjustment
timeline_font_scale=1
# timeline chapters style: none, dots, lines, lines-top, lines-bottom
# timeline chapters style: dots, lines, lines-top, lines-bottom
timeline_chapters=dots
timeline_chapters_opacity=0.2
# which timeline elements to render, and in what order
# available: ranges,chapters,progress,cache,time
timeline_elements=ranges,chapters,progress,cache,time
# where to display volume controls: none, left, right
volume=right

View File

@@ -34,6 +34,7 @@ local options = {
timeline_font_scale = 1,
timeline_chapters = 'dots',
timeline_chapters_opacity = 0.2,
timeline_elements = 'ranges,chapters,progress,cache,time',
volume = 'right',
volume_size = 40,
@@ -1404,16 +1405,6 @@ end
-- ELEMENT RENDERERS
function render_foreground_bar(ass, fax, fay, fbx, fby)
ass:new_event()
ass:append('{\\blur0\\bord0\\1c&H'..options.color_foreground..'}')
ass:append(ass_opacity(options.timeline_opacity))
ass:pos(0, 0)
ass:draw_start()
ass:rect_cw(fax, fay, fbx, fby)
ass:draw_stop()
end
function render_timeline(this)
if this.size_max == 0 or state.duration == nil or state.duration == 0 or state.position == nil then return end
@@ -1471,12 +1462,19 @@ function render_timeline(this)
ass:rect_cw(bax, bay, bbx, bby)
ass:draw_stop()
-- Foreground bar - renders below custom ranges
if not is_line then
render_foreground_bar(ass, fax, fay, fbx, fby)
-- Progress
local function render_progress()
ass:new_event()
ass:append('{\\blur0\\bord0\\1c&H'..options.color_foreground..'}')
ass:append(ass_opacity(options.timeline_opacity))
ass:pos(0, 0)
ass:draw_start()
ass:rect_cw(fax, fay, fbx, fby)
ass:draw_stop()
end
-- Custom ranges
local function render_ranges()
if state.chapter_ranges ~= nil then
for i, chapter_range in ipairs(state.chapter_ranges) do
for i, range in ipairs(chapter_range.ranges) do
@@ -1497,15 +1495,14 @@ function render_timeline(this)
end
end
end
end
-- Chapters
local function render_chapters()
if (
options.timeline_chapters ~= 'none'
and (
state.chapters ~= nil and #state.chapters > 0
or state.ab_loop_a and state.ab_loop_a > 0
or state.ab_loop_b and state.ab_loop_b > 0
)
) then
local dots = false
local chapter_size, chapter_y
@@ -1575,8 +1572,10 @@ function render_timeline(this)
end
end
end
end
-- Seekable ranges
local function render_cache()
if options.timeline_cached_ranges and state.cached_ranges then
local range_height = math.max(math.min(this.size_max / 8, foreground_size / 3), 1)
local range_ay = fby - range_height
@@ -1595,12 +1594,10 @@ function render_timeline(this)
ass:draw_stop()
end
end
-- Foreground line - renders above most other indicators
if is_line then
render_foreground_bar(ass, fax, fay, fbx, fby)
end
-- Time values
local function render_time()
if text_opacity > 0 then
-- Elapsed time
if state.elapsed_seconds then
@@ -1644,13 +1641,29 @@ function render_timeline(this)
ass:append(end_time)
end
end
end
-- Render requested elements
local element_renderers = {
ranges = render_ranges,
chapters = render_chapters,
progress = render_progress,
cache = render_cache,
time = render_time,
}
local rendered_chapters = false
for _, name in ipairs(options.timeline_elements) do
if name == 'chapters' then rendered_chapters = true end
if element_renderers[name] ~= nil then element_renderers[name]() end
end
if (this.proximity_raw == 0 or this.pressed) and not (elements.speed and elements.speed.dragging) then
-- Hovered time and chapter
if (this.proximity_raw == 0 or this.pressed) and not (elements.speed and elements.speed.dragging) then
local hovered_seconds = state.duration * (cursor.x / display.width)
local chapter_title = ''
local chapter_title_width = 0
if (state.chapters and options.timeline_chapters ~= 'none') then
if (rendered_chapters and state.chapters) then
for i = #state.chapters, 1, -1 do
local chapter = state.chapters[i]
if hovered_seconds >= chapter.time then
@@ -3177,10 +3190,11 @@ end
-- VALUE SERIALIZATION/NORMALIZATION
options.proximity_out = math.max(options.proximity_out, options.proximity_in + 1)
options.timeline_chapters = itable_find({'dots', 'lines', 'lines-top', 'lines-bottom'}, options.timeline_chapters) and options.timeline_chapters or 'none'
options.timeline_chapters = itable_find({'dots', 'lines', 'lines-top', 'lines-bottom'}, options.timeline_chapters) and options.timeline_chapters or 'dots'
options.media_types = split(options.media_types, ' *, *')
options.subtitle_types = split(options.subtitle_types, ' *, *')
options.stream_quality_options = split(options.stream_quality_options, ' *, *')
options.timeline_elements = split(options.timeline_elements, ' *, *')
options.timeline_cached_ranges = (function()
if options.timeline_cached_ranges == '' or options.timeline_cached_ranges == 'no' then return nil end
local parts = split(options.timeline_cached_ranges, ':')