summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.lua2
-rw-r--r--main.lua27
-rw-r--r--osd.lua53
3 files changed, 66 insertions, 16 deletions
diff --git a/config.lua b/config.lua
index 0d56271..e5a3515 100644
--- a/config.lua
+++ b/config.lua
@@ -16,6 +16,7 @@ config.click_max_drift = 2
config.btn_timeout = 1
config.bg_alpha = '44'
+config.bg_hover_alpha = '66'
config.colour = {
title = '999999',
option = 'ffffff',
@@ -41,6 +42,7 @@ config.colour = {
status_error = 'ff3333',
menu_btn_fg = '000000',
menu_btn_bg = '00cc00',
+ bg_hover = '003300',
}
config.icon = {
diff --git a/main.lua b/main.lua
index 0ee88c7..f3a1915 100644
--- a/main.lua
+++ b/main.lua
@@ -1005,9 +1005,13 @@ local function handle_mouse_click(ev, id)
return
end
+ local mpos = osd.mpos
+ if not mpos then
+ return
+ end
+
local time = mp.get_time()
local clk = click_state
- local mpos = osd.mpos
if ev.event == 'down' then
clk.ct, clk.ck = time, ev.key_name
@@ -1240,19 +1244,30 @@ local function handle_key(ev)
t = binding_state.active['ANY_UNICODE']
end
+ -- ev.is_mouse is false for some mouse events
+ local k = ev.key_name
+ if k:find('MOUSE_') or k:find('MBTN_') or k:find('WHEEL_') then
+ if not osd.mactive then
+ osd:set_mactive(true)
+ end
+ elseif osd.mactive then
+ osd:set_mactive(false)
+ click_state = {}
+ end
+
local f = t and t[1]
if not f then
- return
+ goto flush
end
- local flag = t[2]
- if flag == 'complex' then
+ if t[2] == 'complex' then
f(ev)
elseif ev.event == 'down' or
- (ev.event == 'repeat' and flag == 'repeat') then
+ (ev.event == 'repeat' and t[2] == 'repeat') then
f()
end
+ ::flush::
osd:flush(state)
end
@@ -1365,6 +1380,8 @@ mp.observe_property('mouse-pos', 'native', function(_, mpos)
else
btn_timer:kill()
end
+
+ osd:flush(state)
end)
mp.observe_property('user-data/osc/visibility', 'native', function(_, val)
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)