From 5c23089356402017a396f6efbd6a0d547a6a26ac Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 28 Jan 2026 19:57:42 -0800 Subject: add progress bar for active programmes --- osd.lua | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'osd.lua') diff --git a/osd.lua b/osd.lua index 542a8ad..77f98d0 100644 --- a/osd.lua +++ b/osd.lua @@ -202,6 +202,28 @@ function mt:option_icons(opt, info) return str end +function mt:draw_progress_bar(prog, fg, bg) + local pct = (self.redraw_time - prog.start) / (prog.stop - prog.start) + local offset = 0.15 * config.font_size + local h = 0.25 * config.font_size + local w = 2 * config.font_size + local filled = w * pct + + -- overlay fill over bg using negative coordinates, then backtrack + -- width of fill using \fsp on a zero-width space. this is needed + -- because ASS essentially advances a cursor by the width of any + -- rendered shape, as opposed to starting the next shape where the + -- previous one ended. we must rewind this cursor to avoid a gap the + -- width of fill before anything else that follows. + -- + -- the reason this is done in the first place is because simply placing + -- two rectangles next to one another results in a subpixel gap between + -- them, affecting both the rendered result and the computed bounds. + return bg .. draw_rect(0, -offset, w, h - offset) .. + fg .. draw_rect(-w, -offset, filled - w, h - offset) .. + '{\\fsp'..-filled..'}\xe2\x80\x8b{\\fsp0}' +end + function mt:option_text(opt, info) local str = opt.name local col = colour.option @@ -235,11 +257,23 @@ function mt:option_text(opt, info) str = col .. '[' .. str .. ']' end + if opt.programme and opt.type == 'programme' and opt.active then + str = str .. ' ' .. self:draw_progress_bar( + opt.programme, colour.progress_bar_epg_fg, + colour.progress_bar_epg_bg) + end + local opt_info = opt.info if opt_info and #opt_info > 0 then str = str .. colour.info .. ' (' .. asscape(opt_info) .. ')' end + if opt.programme and opt.type ~= 'programme' then + str = str .. ' ' .. self:draw_progress_bar( + opt.programme, colour.progress_bar_fg, + colour.progress_bar_bg) + end + return str end @@ -631,7 +665,7 @@ function mt:redraw(state) self.needs_redraw = false if next_redraw ~= math.huge then - local d = math.max(0.1, next_redraw - os.time()) + local d = math.min(10, math.max(0.1, next_redraw - os.time())) self.redraw_timer = mp.add_timeout(d, function() self:redraw(state) end) -- cgit v1.2.3-70-g09d2