summaryrefslogtreecommitdiff
path: root/osd.lua
diff options
context:
space:
mode:
Diffstat (limited to 'osd.lua')
-rw-r--r--osd.lua80
1 files changed, 79 insertions, 1 deletions
diff --git a/osd.lua b/osd.lua
index bf5dfec..796c3b3 100644
--- a/osd.lua
+++ b/osd.lua
@@ -39,6 +39,7 @@ function osd.new(init)
local t = setmetatable({
fg = mp.create_osd_overlay('ass-events'),
bg = mp.create_osd_overlay('ass-events'),
+ toggle_button = mp.create_osd_overlay('ass-events'),
width = 0,
height = 0,
scale = 1,
@@ -46,6 +47,8 @@ function osd.new(init)
padding = math.floor((720 - (lines * config.font_size)) / 2),
}, mt)
t.bg.z = -1
+ t.toggle_button.z = 1
+ t.toggle_button.hidden = true
for k, v in pairs(init or {}) do
t[k] = v
@@ -67,7 +70,24 @@ end
function mt:resize(w, h)
self.width = w
self.height = h
- self.scale = h / 720
+ self.scale = h > 0 and h/720 or 1
+
+ local sz = self.padding + self:measure_width('»') - 2
+ local coords = {
+ x1 = 2,
+ y1 = self.padding + ((config.font_size - sz) / 2),
+ }
+ coords.x2 = coords.x1 + sz
+ coords.y2 = coords.y1 + sz
+ self.toggle_button_coords = coords
+
+ self.toggle_button.data =
+ '{\\pos(' .. coords.x1 .. ',' .. coords.y1 .. ')}' ..
+ colours.toggle_button_bg .. draw_rect(0, 0, sz, sz) .. '\n' ..
+ '{\\q2\\fs' .. sz .. '\\bord0\\an5\\pos(' ..
+ coords.x1 + sz/2 .. ',' .. coords.y1 + sz/2 ..')}' ..
+ colours.toggle_button_fg .. '≡'
+ self.toggle_button:update()
end
function mt:set_status(msg, level, no_dirty)
@@ -570,6 +590,12 @@ function mt:is_hidden()
end
function mt:get_mouse_line(mpos)
+ local x = mpos.x / self.scale
+ local w = self.width / self.scale
+ if x < self.padding or x > w - self.padding then
+ return
+ end
+
local y = mpos.y / self.scale
local line = math.floor((y - self.padding) / config.font_size) + 1
if line < 1 or line > self.lines then
@@ -578,4 +604,56 @@ function mt:get_mouse_line(mpos)
return line
end
+function mt:mouse_over_button_area(mpos)
+ if not mpos.hover then
+ return false
+ end
+
+ local y = mpos.y / self.scale
+ return y < self.padding + (2 * config.font_size)
+end
+
+function mt:mouse_over_toggle_button(mpos)
+ if not mpos.hover then
+ return false
+ end
+
+ local x = mpos.x / self.scale
+ local y = mpos.y / self.scale
+ local coords = self.toggle_button_coords
+ return coords and
+ x > coords.x1 and x < coords.x2 and
+ y > coords.y1 and y < coords.y2
+end
+
+function mt:show_toggle_button(bool)
+ if self.toggle_button.hidden ~= bool then
+ return
+ end
+
+ self.toggle_button.hidden = not bool
+ self.toggle_button:update()
+end
+
+function mt:measure_width(str)
+ local e = self.toggle_button
+ local data = e.data
+ local hidden = e.hidden
+ e.hidden = true
+ e.compute_bounds = true
+
+ local block = '\xe2\x96\x88'
+ local pre = '{\\q2\\fs' .. config.font_size .. '\\pos(0,0)}' .. block
+ e.data = pre .. block
+ local size = e:update().x1
+ e.data = pre .. str .. block
+ size = e:update().x1 - size
+
+ e.data = data
+ e.hidden = hidden
+ e.compute_bounds = false
+
+ return size
+end
+
return osd