-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathpixels.lua
73 lines (65 loc) · 1.23 KB
/
pixels.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require "sprites"
local pixels_mt = {
}
local font_mt = {
__gc = function(s)
stead.font_free(s.fnt)
end;
__tostring = function(s)
return s.fnt
end;
}
local pnew = function(p)
if stead.type(p) ~= 'userdata' then
return
end
local t = getmetatable(p).__index
setmetatable(t, pixels_mt)
return p
end
local fnew = function(f)
if stead.type(f) ~= 'string' then
return
end
local fn = {
fnt = f;
save = function() end;
}
setmetatable(fn, font_mt)
return fn
end
local font_m = {
text = function(s, text, col, style, ...)
return pnew(stead.sprite_pixels(stead.sprite_text(s.fnt, text, col, style, ...)))
end;
size = function(s, ...)
return stead.sprite_text_size(s.fnt, ...);
end;
}
local pixels_m = {
save = function() end;
dup = function(self)
local w, h, s = self:size()
local p = stead.sprite_pixels(w, h, s)
if p then
self:copy(p)
end
return pnew(p)
end;
}
font_mt.__index = font_m
pixels_mt.__index = pixels_m
pixels = {
nam = 'pixels';
object_type = true;
system_type = true;
fnt = function(name, sz, ...)
if not stead.tonum(sz) then
error("No font size specified.", 2)
end
return fnew(stead.font_load(name, -sz, ...))
end;
new = function(...)
return pnew(stead.sprite_pixels(...))
end;
}