-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtext.lua
More file actions
50 lines (41 loc) · 1.46 KB
/
text.lua
File metadata and controls
50 lines (41 loc) · 1.46 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
-- Text drawing utilities
text = {}
-- Draw some text that's centered within the specified rectangle
function text.drawCentered(x, y, w, h, text)
-- Get the current font, calculate the width and height of its
-- glyphs to be able to center the text properly.
local font = love.graphics.getFont()
local textW = font:getWidth(text)
local textH = font:getHeight()
love.graphics.print(text, x+w/2, y+h/2, 0, 1, 1, textW/2, textH/2)
end
-- Draw right aligned text
function text.drawRight(x, y, w, text)
local font = love.graphics.getFont()
local textW = font:getWidth(text)
love.graphics.print(text, x+w-textW, y)
end
-- Draw some text that's centered within the specified rectangle, ROTATED!
function text.drawCenteredRot(x, y, w, h, text, angle)
-- Get the current font, calculate the width and height of its
-- glyphs to be able to center the text properly.
local font = love.graphics.getFont()
local textW = font:getWidth(text)
local textH = font:getHeight()
love.graphics.push()
love.graphics.translate(x, y)
love.graphics.rotate(angle)
love.graphics.print(text, x+w/2, y+h/2, 0, 1, 1, textW/2, textH/2)
love.graphics.pop()
end
-- Print text with an outline that extends to the outside of the text glyphs.
function text.drawOutlined(text, x, y, rds)
love.graphics.setColor(0,0,0)
for oux = -rds, rds, 1 do
for ouy = -rds, rds, 1 do
love.graphics.print(text, x+oux, y+ouy)
end
end
love.graphics.setColor(1,1,1)
love.graphics.print(text, x, y)
end