-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
executable file
·62 lines (56 loc) · 1.31 KB
/
init.lua
File metadata and controls
executable file
·62 lines (56 loc) · 1.31 KB
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
local trim5 = function(s)
return s:match'^%s*(.*%S)' or ''
end
local reflow = function(progress,printf,text,x,y,w,a,sx,sy)
assert(progress)
assert(printf)
assert(text)
assert(x)
assert(y)
assert(sx)
assert(sy)
local font = love.graphics.getFont()
local width,wrappedtext = font:getWrap(text,w)
local target = math.floor( math.min(1,math.max(0,progress or 1)) * #text)
local c_start = 0
for i,line in pairs(wrappedtext) do
local c_end = c_start + #line
local linewidth = font:getWidth(trim5(line))
local offset = 0 -- a == nil or a == "left"
if a == "center" then
offset = (w-linewidth)/2 * sx
elseif a == "right" then
offset = (w-linewidth) * sx
end
-- Determine how much of the line is to be drawn
local subline
if c_end < target then -- all
subline = line
elseif c_start <= target and target <= c_end then -- partial
subline = line:sub(1,target-c_start)
else -- not at all
break
end
printf(
subline,
x+offset,
y+font:getHeight()*(i-1)*sy,
0, sx, sy
)
c_start = c_end
end
end
function reflowprint(i,text,x,y,w,a,sx,sy)
sx = sx or 1
sy = sy or 1
if type(i) == "table" then
reflow(
i.progress,
i.print or love.graphics.print,
i.text,i.x,i.y,i.w,i.a,i.sx,i.sy
)
else
reflow(i,love.graphics.print,text,x,y,w,a,sx,sy)
end
end
return reflowprint