summaryrefslogtreecommitdiff
path: root/text.lua
diff options
context:
space:
mode:
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/text.lua b/text.lua
new file mode 100644
index 0000000..a885b39
--- /dev/null
+++ b/text.lua
@@ -0,0 +1,37 @@
+local font = require "font"
+local utf8 = require "utf8"
+
+local text = {}
+
+local function draw_char(c, center)
+ love.graphics.push()
+ local c = font[c] or font["□"]
+ if not center then
+ love.graphics.translate(c.width / 2, 0)
+ end
+ for _, l in ipairs(c) do
+ line(unpack(l))
+ end
+ love.graphics.pop()
+ return c.width
+end
+
+function text.draw(str, x, y, opt)
+ opt = opt or {}
+ opt.scale = opt.scale or 1
+ opt.spacing = opt.spacing or 3
+
+ local lw = love.graphics.getLineWidth(lw)
+ love.graphics.push()
+ love.graphics.translate(x or 0, y or 0)
+ love.graphics.scale(opt.scale)
+ love.graphics.setLineWidth(lw / opt.scale)
+ for _, c in utf8.codes(str) do
+ love.graphics.translate(draw_char(utf8.char(c)), 0)
+ love.graphics.translate(opt.spacing, 0)
+ end
+ love.graphics.pop()
+ love.graphics.setLineWidth(lw)
+end
+
+return text