dotfiles/multimedia/.config/mpv/scripts/uosc/elements/Curtain.lua

36 lines
1,016 B
Lua
Raw Permalink Normal View History

2024-04-20 07:27:09 +00:00
local Element = require('elements/Element')
2023-05-23 13:31:17 +00:00
---@class Curtain : Element
local Curtain = class(Element)
function Curtain:new() return Class.new(self) --[[@as Curtain]] end
function Curtain:init()
2024-04-20 07:27:09 +00:00
Element.init(self, 'curtain', {render_order = 999})
2023-05-23 13:31:17 +00:00
self.opacity = 0
---@type string[]
self.dependents = {}
end
---@param id string
function Curtain:register(id)
self.dependents[#self.dependents + 1] = id
if #self.dependents == 1 then self:tween_property('opacity', self.opacity, 1) end
end
---@param id string
function Curtain:unregister(id)
self.dependents = itable_filter(self.dependents, function(item) return item ~= id end)
if #self.dependents == 0 then self:tween_property('opacity', self.opacity, 0) end
end
function Curtain:render()
2024-04-20 07:27:09 +00:00
if self.opacity == 0 or config.opacity.curtain == 0 then return end
2023-05-23 13:31:17 +00:00
local ass = assdraw.ass_new()
ass:rect(0, 0, display.width, display.height, {
2024-04-20 07:27:09 +00:00
color = config.color.curtain, opacity = config.opacity.curtain * self.opacity,
2023-05-23 13:31:17 +00:00
})
return ass
end
return Curtain