summaryrefslogtreecommitdiff
path: root/osd.lua
diff options
context:
space:
mode:
Diffstat (limited to 'osd.lua')
-rw-r--r--osd.lua53
1 files changed, 42 insertions, 11 deletions
diff --git a/osd.lua b/osd.lua
index 93f9f3f..eb7feda 100644
--- a/osd.lua
+++ b/osd.lua
@@ -73,12 +73,14 @@ function mt:destroy()
end
function mt:dirty()
- self.is_dirty = true
+ self.needs_redraw = true
end
function mt:flush(state)
- if self.is_dirty then
+ if self.needs_redraw then
self:redraw(state)
+ elseif self.needs_render_bg then
+ self:render_bg()
end
end
@@ -447,9 +449,22 @@ function mt:render_bg()
'{\\pos(0,0)\\alpha&H' .. config.bg_alpha .. '&\\c&H&}' ..
draw_rect(0, 0, 7680, 720)
+ if self.mactive and self.mstate and self.mstate.target == 'menu' then
+ local line = self.mstate.line
+ self.bg.data = self.bg.data .. '\n' ..
+ '{\\bord0\\pos(0,0)\\alpha&H' ..
+ config.bg_hover_alpha .. '&}' .. colour.bg_hover ..
+ draw_rect(
+ self.padding,
+ self.padding + ((line - 1) * config.font_size),
+ (self.width / self.scale) - self.padding,
+ self.padding + (line * config.font_size))
+ end
+
local sb = self.out.scrollbar
if sb then
- local hover = self.mstate and self.mstate.target == 'scrollbar'
+ local hover = self.mactive and self.mstate and
+ self.mstate.target == 'scrollbar'
local fg = hover and colour.scrollbar_fg_hover or
colour.scrollbar_fg
local bg = hover and colour.scrollbar_bg_hover or
@@ -467,6 +482,7 @@ function mt:render_bg()
end
self.bg:update()
+ self.needs_render_bg = false
end
-- this takes the data generated by redraw() and related functions, prepares it
@@ -604,10 +620,10 @@ function mt:redraw(state)
end
-- menu changes could result in hover changes
- self:update_mstate()
+ self:update_mstate(self.mactive)
self:render()
- self.is_dirty = false
+ self.needs_redraw = false
end
function mt:toggle_hidden()
@@ -672,7 +688,7 @@ function mt:mouse_over_menu_btn(mpos)
y > coords.y1 and y < coords.y2
end
-function mt:update_mstate()
+function mt:update_mstate(mactive)
local t = {}
local val
@@ -708,12 +724,19 @@ function mt:update_mstate()
::update::
local ms = self.mstate or {}
- self.mstate = t
-
- if (t.target == 'scrollbar') ~= (ms.target == 'scrollbar') then
- self:render_bg()
+ local t_hov = (t.target == 'menu' or t.target == 'scrollbar')
+ local ms_hov = (ms.target == 'menu' or ms.target == 'scrollbar')
+ if (t_hov or ms_hov) and
+ (t.target ~= ms.target or
+ not mactive ~= not self.mactive or
+ (t.target == 'menu' and
+ t.line ~= ms.line)) then
+ self.needs_render_bg = true
end
+ self.mstate = t
+ self.mactive = mactive
+
return t
end
@@ -727,7 +750,15 @@ function mt:set_mpos(mpos)
self.mpos = mpos
self.mpos_time = mp.get_time()
- return self:update_mstate()
+ return self:update_mstate(mpos and mpos.hover)
+end
+
+function mt:set_mactive(bool)
+ if not self.mactive == not bool then
+ return
+ end
+
+ self:update_mstate(bool)
end
function mt:show_menu_btn(bool)