This commit is contained in:
2026-04-03 11:33:51 +02:00
parent 64922e1ae3
commit 0ed904319d
57 changed files with 2935 additions and 1377 deletions
+44
View File
@@ -266,3 +266,47 @@ function ass_mt:spinner(x, y, size, opts)
self:icon(x, y, size, 'autorenew', opts)
request_render()
end
-- Renders a smooth curve from Bezier segments.
---@param ax number
---@param ay number
---@param bx number
---@param by number
---@param points number[] Flat table of normalized points (01): start point followed by segment entries cp1x, cp1y, cp2x, cp2y, px, py, ...
---@param opts? {color?: string; border?: number; border_color?: string; opacity?: number|{primary?: number; border?: number, shadow?: number, main?: number}; clip?: string}
function ass_mt:smooth_curve(ax, ay, bx, by, points, opts)
if not points or #points < 8 then return end
opts = opts or {}
local border_size = opts.border or 0
local tags = '\\pos(0,0)\\rDefault\\an7\\blur0'
-- border
tags = tags .. '\\bord' .. border_size
-- colors
tags = tags .. '\\1c&H' .. (opts.color or fg)
if border_size > 0 then tags = tags .. '\\3c&H' .. (opts.border_color or bg) end
-- opacity
if opts.opacity then tags = tags .. self.opacity(nil, opts.opacity) end
-- clip
if opts.clip then tags = tags .. opts.clip end
-- draw
self:new_event()
self.text = self.text .. '{' .. tags .. '}'
self:draw_start()
-- Scale normalized (01) coordinates to rectangle bounds
local width, height = bx - ax, by - ay
local function scale(x, y)
return ax + x * width, ay + y * height
end
local x0, y0 = scale(points[1], points[2])
self:move_to(x0, y0)
local max = math.floor((#points - 2) / 6) * 6 + 2
for i = 3, max, 6 do
local x1, y1 = scale(points[i], points[i+1])
local x2, y2 = scale(points[i+2], points[i+3])
local x3, y3 = scale(points[i+4], points[i+5])
self:bezier_curve(x1, y1, x2, y2, x3, y3)
end
self:draw_stop()
end