diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-07 23:25:48 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-07 23:25:48 -0800 |
| commit | 44644dfb4e3e19438c6499a6b49458fc8b382ac1 (patch) | |
| tree | e3697a8d8cef0bfe7e72450346b15b75e4a34abd /osd.lua | |
| parent | 8fd7556551ee6eeb353ac8e6815cdc78b361682b (diff) | |
| download | mpv-iptv-menu-44644dfb4e3e19438c6499a6b49458fc8b382ac1.tar.gz mpv-iptv-menu-44644dfb4e3e19438c6499a6b49458fc8b382ac1.tar.xz | |
more images cleanup
Diffstat (limited to 'osd.lua')
| -rw-r--r-- | osd.lua | 76 |
1 files changed, 46 insertions, 30 deletions
@@ -34,9 +34,9 @@ local function asscape(str) return mp.command_native({'escape-ass', (str:gsub('\n', ' '))}) end -function osd.new() +function osd.new(init) local lines = math.floor((720 / config.font_size) + 0.5) - 1 - local t = { + local t = setmetatable({ fg = mp.create_osd_overlay('ass-events'), bg = mp.create_osd_overlay('ass-events'), width = 0, @@ -45,10 +45,14 @@ function osd.new() lines = lines, padding = math.floor((720 - (lines * config.font_size)) / 2), img = nil, - } + }, mt) t.bg.z = -1 - return setmetatable(t, mt) + for k, v in pairs(init or {}) do + t[k] = v + end + + return t end function mt:resize(w, h) @@ -167,26 +171,33 @@ function mt:option_path(opt, info) return str end -function mt:load_image() +function mt:load_img() local f = mp_utils.file_info(self.img.path) if not f then return false end - local cmd = 'magick \'' .. self.img.path .. '\'' .. - ' -background none' .. - ' -gravity northwest' .. - ' -depth 8' .. - ' -resize ' .. self.img.cmd.w .. 'x' .. self.img.cmd.h .. - ' -extent ' .. self.img.cmd.w .. 'x' .. self.img.cmd.h .. - ' tmp.bgra' - print('exec: ' .. cmd) - os.execute(cmd) - self.img.loaded = true - return true + local cmd = { + 'magick', self.img.path, + '-background', 'none', + '-gravity', 'northwest', + '-depth', '8', + '-resize', self.img.cmd.w .. 'x' .. self.img.cmd.h, + '-extent', self.img.cmd.w .. 'x' .. self.img.cmd.h, + 'tmp.bgra'} + print('exec: ' .. mp_utils.to_string(cmd)) + local res = mp.command_native({ + name = 'subprocess', + args = cmd, + playback_only = false, + }) + + local loaded = res and res.status == 0 + self.img.loaded = loaded + return loaded end -function mt:clear_image(purge) +function mt:clear_img(purge) if not self.img then return end @@ -197,13 +208,13 @@ function mt:clear_image(purge) end end -function mt:draw_image() +function mt:draw_img() if not self.img then return end - if not (self.img.loaded or self:load_image()) then - self:clear_image() + if not (self.img.loaded or self:load_img()) then + self:clear_img() return end @@ -212,7 +223,7 @@ function mt:draw_image() end end -function mt:update_image(path, menu_res) +function mt:set_img(path, menu_res) -- images require *real* dimensions and coordinates, unlike other OSD -- functions which scale the given values automatically local padding = self.scale * self.padding @@ -329,8 +340,8 @@ function mt:redraw(state) self:option_text(opt, info) .. self:option_path(opt, info) - if selected and opt.image then - img = opt.image + if selected and opt.img_url then + img = opt.img_url end end @@ -349,12 +360,17 @@ function mt:redraw(state) self.fg.compute_bounds = not not img local res = self.fg:update() self.bg:update() - if img then - local path = get_image_path(img, true) - self:update_image(path, res) - self:draw_image() + if img and self.img_path_func then + local path = self.img_path_func(img, function(path) + if self.img and path == self.img.path then + self:draw_img() + end + end) + + self:set_img(path, res) + self:draw_img() else - self:clear_image(true) + self:clear_img(true) end end @@ -367,9 +383,9 @@ function mt:toggle_hidden() self.bg:update() if hidden then - self:clear_image() + self:clear_img() else - self:draw_image() + self:draw_img() end end |
