gears.shape: Stop using _call on a matrix
Instead of using a special _call field on gears.matrix instances which has to be copied around suitably, this commit changes the code so that the magic is restricted to a single function in gears.shape.transform. With some metatable magic, suitable redirection to everything is added. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
19f146de5f
commit
96055fc86b
|
@ -455,15 +455,26 @@ function module.transform(shape)
|
|||
-- Apply the transformation matrix and apply the shape, then restore
|
||||
local function apply(self, cr, width, height, ...)
|
||||
cr:save()
|
||||
cr:transform(self:to_cairo_matrix())
|
||||
cr:transform(self.matrix:to_cairo_matrix())
|
||||
shape(cr, width, height, ...)
|
||||
cr:restore()
|
||||
end
|
||||
-- Redirect function calls like :rotate() to the underlying matrix
|
||||
local function index(_, key)
|
||||
return function(self, ...)
|
||||
self.matrix = self.matrix[key](self.matrix, ...)
|
||||
return self
|
||||
end
|
||||
end
|
||||
|
||||
local matrix = g_matrix.identity:copy()
|
||||
rawset(matrix, "_call", apply)
|
||||
local result = setmetatable({
|
||||
matrix = g_matrix.identity
|
||||
}, {
|
||||
__call = apply,
|
||||
__index = index
|
||||
})
|
||||
|
||||
return matrix
|
||||
return result
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
Loading…
Reference in New Issue