summaryrefslogtreecommitdiff
path: root/osd.lua
diff options
context:
space:
mode:
Diffstat (limited to 'osd.lua')
-rw-r--r--osd.lua46
1 files changed, 38 insertions, 8 deletions
diff --git a/osd.lua b/osd.lua
index 6bbc7b8..b780d9e 100644
--- a/osd.lua
+++ b/osd.lua
@@ -19,10 +19,14 @@ for k, v in pairs(config.colours) do
colours[k] = '{\\c&H' .. tag
end
-local cursor_glyph = '{\\p1\\pbo' .. math.floor(config.font_size / 5) .. '}' ..
- 'm 0 0 l ' .. math.ceil(config.font_size / 32) .. ' 0 ' ..
- math.ceil(config.font_size / 32) .. ' ' .. config.font_size ..
- ' 0 ' .. config.font_size .. '{\\p0}'
+local function draw_rect(x1, y1, x2, y2)
+ return string.format(
+ '{\\p1}m %f %f l %f %f %f %f %f %f{\\p0}',
+ x1, y1, x2, y1, x2, y2, x1, y2)
+end
+
+local cursor_glyph = '{\\pbo' .. math.floor(config.font_size / 5) .. '}' ..
+ draw_rect(0, 0, math.ceil(config.font_size / 32), config.font_size)
local function asscape(str)
-- remove newlines before escaping, since we don't want output to
@@ -42,10 +46,7 @@ function osd.new()
padding = math.floor((720 - (lines * config.font_size)) / 2),
img = nil,
}
-
t.bg.z = -1
- t.bg.data = '{\\pos(0,0)\\alpha&H' .. config.bg_alpha .. '&\\c&H&}' ..
- '{\\p1}m 0 0 l 7680 0 7680 720 0 720{\\p0}'
return setmetatable(t, mt)
end
@@ -251,6 +252,28 @@ function mt:remove_image()
self.img = nil
end
+function mt:draw_scrollbar(menu, depth)
+ local opts = #menu.options
+ local lines = self:menu_lines(depth)
+ if opts <= lines then
+ return
+ end
+
+ local top = self.padding + ((self.lines - lines) * config.font_size)
+ local h = 720 - self.padding - top
+ local w = self.padding - 4
+ local hh = math.max(config.font_size / 2, h * lines / opts)
+ local pos = (h - hh) * (menu.view_top - 1) / (opts - lines)
+
+ return (
+ -- bg
+ colours.scrollbar_bg ..
+ '{\\pos(2,' .. top .. ')}' .. draw_rect(0, 0, w, h) .. '\n' ..
+ -- fg
+ colours.scrollbar_fg .. '{\\bord0}' ..
+ '{\\pos(2,' .. top + pos .. ')}' .. draw_rect(0, 0, w, hh))
+end
+
function mt:redraw(menus, depth, favourites, playing_id)
local out = {}
@@ -294,15 +317,22 @@ function mt:redraw(menus, depth, favourites, playing_id)
self.fg.data = '{\\q2\\fs' .. config.font_size ..
'\\pos(' .. self.padding .. ',' .. self.padding .. ')}' ..
table.concat(out, '\\N')
+ 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)
+ if sb then
+ self.bg.data = self.bg.data .. '\n' .. sb
+ end
self.fg.compute_bounds = not not img
local res = self.fg:update()
+ self.bg:update()
if img then
self:update_image(img, res)
elseif self.img then
self:remove_image()
end
- self.bg:update()
end
function mt:toggle_hidden()