-
Notifications
You must be signed in to change notification settings - Fork 9
/
draw_modifier.lua
47 lines (40 loc) · 1.05 KB
/
draw_modifier.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local draw_modifier = {}
local mgl = require "MGL"
function draw_modifier.color(color, f)
return function (...)
local old_color = {love.graphics.getColor()}
love.graphics.setColor(unpack(color))
local ret = f(...)
love.graphics.setColor(unpack(old_color))
return ret
end
end
function draw_modifier.line_width(width, f)
return function (...)
local old_width = love.graphics.getLineWidth()
love.graphics.setLineWidth(width)
local ret = f(...)
love.graphics.setLineWidth(old_width)
return ret
end
end
function draw_modifier.transform(transform, f)
return function (...)
love.graphics.push()
love.graphics.applyTransform(transform)
local ret = f(...)
love.graphics.pop()
return ret
end
end
function draw_modifier.combine(...)
local ff = {...}
return function (...)
local rets = {}
for i, f in ipairs(ff) do
rets[i] = f(...)
end
return rets
end
end
return draw_modifier