summaryrefslogtreecommitdiff
path: root/osd.lua
diff options
context:
space:
mode:
Diffstat (limited to 'osd.lua')
-rw-r--r--osd.lua33
1 files changed, 18 insertions, 15 deletions
diff --git a/osd.lua b/osd.lua
index 72d9cea..12ae826 100644
--- a/osd.lua
+++ b/osd.lua
@@ -57,10 +57,10 @@ function mt:resize(w, h)
self.scale = h / 720
end
-function mt:menu_lines(depth)
- if depth > 1 then
+function mt:menu_lines(state)
+ if state.depth > 1 then
-- leaves an extra line for padding between titles and options
- return self.lines - depth
+ return self.lines - state.depth
else
return self.lines
end
@@ -252,9 +252,10 @@ function mt:remove_image()
self.img = nil
end
-function mt:draw_scrollbar(menu, depth)
+function mt:draw_scrollbar(state)
+ local menu = state:menu()
local opts = #menu.options
- local lines = self:menu_lines(depth)
+ local lines = self:menu_lines(state)
if opts <= lines then
return
end
@@ -274,17 +275,17 @@ function mt:draw_scrollbar(menu, depth)
'{\\pos(2,' .. top + pos .. ')}' .. draw_rect(0, 0, w, hh))
end
-function mt:redraw(menus, depth, favourites, playing_id)
+function mt:redraw(state)
local out = {}
- if depth > 1 then
- for i = 2, depth do
- out[#out+1] = self:menu_title(menus[i])
+ if state.depth > 1 then
+ for i = 2, state.depth do
+ out[#out+1] = self:menu_title(state.menus[i])
end
out[#out+1] = ' ' -- space character for correct line height
end
- local menu = menus[depth]
+ local menu = state:menu()
local img
if menu.img_url then
@@ -292,13 +293,13 @@ function mt:redraw(menus, depth, favourites, playing_id)
end
for i = menu.view_top, math.min(
- menu.view_top + self:menu_lines(depth) - 1,
+ menu.view_top + self:menu_lines(state) - 1,
#menu.options) do
local opt = menu.options[i]
-- use real-time count for favourites
if opt.id == 'favourites' then
- opt.info = tostring(#favourites)
+ opt.info = tostring(#state.favourites)
end
local selected = i == menu.cursor and not menu.search_active
@@ -306,8 +307,10 @@ function mt:redraw(menus, depth, favourites, playing_id)
selected = selected,
empty = (opt.type == 'group' and not opt.lazy and
#opt.children == 0),
- playing = not not (opt.id and opt.id == playing_id),
- favourited = not not (opt.id and favourited(opt.id)),
+ playing = not not (
+ opt.id and opt.id == state.playing_id),
+ favourited = not not (
+ opt.id and state:favourited(opt.id)),
}
out[#out+1] = self:option_icons(opt, info) ..
self:option_text(opt, info) ..
@@ -325,7 +328,7 @@ function mt:redraw(menus, depth, favourites, playing_id)
self.bg.data =
'{\\pos(0,0)\\alpha&H' .. config.bg_alpha .. '&\\c&H&}' ..
draw_rect(0, 0, 7680, 720)
- local sb = self:draw_scrollbar(menu, depth)
+ local sb = self:draw_scrollbar(state)
if sb then
self.bg.data = self.bg.data .. '\n' .. sb
end