diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-28 19:57:42 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-28 19:57:42 -0800 |
| commit | 5c23089356402017a396f6efbd6a0d547a6a26ac (patch) | |
| tree | 8c34a64799af7be6ab91161ce0119fb87ba32fb9 | |
| parent | b29af502c800131a34c38a74d6e7be8da259deb2 (diff) | |
| download | mpv-iptv-menu-5c23089356402017a396f6efbd6a0d547a6a26ac.tar.gz mpv-iptv-menu-5c23089356402017a396f6efbd6a0d547a6a26ac.tar.xz | |
add progress bar for active programmes
| -rw-r--r-- | config.lua | 4 | ||||
| -rw-r--r-- | osd.lua | 36 | ||||
| -rw-r--r-- | rt.lua | 2 |
3 files changed, 41 insertions, 1 deletions
@@ -34,6 +34,10 @@ config.colour = { icon_favourite = 'ff00ff', icon_active = 'ff9900', icon_missing = 'ff0000', + progress_bar_fg = '444444', + progress_bar_bg = '222222', + progress_bar_epg_fg = 'ff9900', + progress_bar_epg_bg = '444444', scrollbar_fg = '666666', scrollbar_bg = '333333', scrollbar_fg_hover = '00cc00', @@ -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) @@ -410,6 +410,7 @@ local menu_option_mt = { v.epg_channel_id, time) local ret = prog and prog.title or '' local exp = prog and prog.stop + rawset(t, 'programme', prog) if not prog then prog = ctx.epg:next_programme( @@ -667,6 +668,7 @@ local function open_option_epg(opt) local prog = { name = os.date('%a %d %b %H:%M', v.start) .. ' ' .. os.date('%H:%M', v.stop) .. ' ' .. v.title, + type = 'programme', info = v.desc, programme = v, } |
