From e33b310682ddcb412377f4d968e51e03d2aa0199 Mon Sep 17 00:00:00 2001 From: Ren Tatsumoto Date: Fri, 23 Oct 2020 16:10:29 +0300 Subject: [PATCH] move common menu code in a separate class --- videoclip.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/videoclip.lua b/videoclip.lua index c520699..9e3d510 100644 --- a/videoclip.lua +++ b/videoclip.lua @@ -199,6 +199,53 @@ encoder.create_clip = function(clip_type) menu.timings:reset() end +------------------------------------------------------------ +-- Menu interface + +local Menu = {} +Menu.__index = Menu + +function Menu:new(parent) + local o = { + parent = parent, + overlay = parent and parent.overlay or mp.create_osd_overlay('ass-events'), + keybinds = { }, + } + return setmetatable(o, self) +end + +function Menu:overlay_draw(text) + self.overlay.data = text + self.overlay:update() +end + +function Menu:open() + if self.parent then + self.parent:close() + end + for _, val in pairs(self.keybinds) do + mp.add_key_binding(val.key, val.key, val.fn) + end + self:update() +end + +function Menu:close() + for _, val in pairs(self.keybinds) do + mp.remove_key_binding(val.key) + end + if self.parent then + self.parent:open() + else + self.overlay:remove() + end +end + +function Menu:update() + local osd = OSD:new():size(config.font_size):align(4) + osd:append('Dummy menu.'):newline() + self:overlay_draw(osd:get_text()) +end + ------------------------------------------------------------ -- main menu