diff options
| author | the lemons <citrons@mondecitronne.com> | 2022-12-27 13:28:21 -0600 |
|---|---|---|
| committer | the lemons <citrons@mondecitronne.com> | 2022-12-27 13:28:21 -0600 |
| commit | defa88d271ae7375ec2773f839881474c3bd50ed (patch) | |
| tree | 3cefb8c3a57ff9cde833fb9f9f10ce19c91b1e99 /text.lua | |
| parent | db39f51f24406805ee50ad6fef89c32a71b179a7 (diff) | |
11¹¹¹ font (incomplete)
Diffstat (limited to 'text.lua')
| -rw-r--r-- | text.lua | 37 |
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 |
