add dedicated backend (WIP)

This commit is contained in:
airstruck
2015-11-22 12:36:44 -05:00
parent 97b2332d47
commit bbba7e1b3d
23 changed files with 6073 additions and 235 deletions

View File

@@ -0,0 +1,65 @@
local Font = setmetatable({}, { __call = function (self, ...)
local object = setmetatable({}, { __index = self })
return object, self.constructor(object, ...)
end })
local fontCache = {}
function Font:constructor (path, size, color)
if not size then
size = 12
end
if not color then
color = { 0, 0, 0 }
end
local key = (path or '') .. '_' .. size
if not fontCache[key] then
if path then
fontCache[key] = love.graphics.newFont(path, size)
else
fontCache[key] = love.graphics.newFont(size)
end
end
self.loveFont = fontCache[key]
self.color = color
end
function Font:setAlignment (align)
self.align = align
end
function Font:setWidth (width)
self.width = width
end
function Font:getLineHeight ()
return self.loveFont:getHeight()
end
function Font:getAscender ()
return self.loveFont:getAscent()
end
function Font:getDescender ()
return self.loveFont:getDescent()
end
function Font:getAdvance (text)
return (self.loveFont:getWidth(text))
end
if love._version_minor < 10 then
function Font:getWrappedHeight (text)
local _, lines = self.loveFont:getWrap(text, self.width)
return lines * self.loveFont:getHeight()
end
else
function Font:getWrappedHeight (text)
local _, lines = self.loveFont:getWrap(text, self.width)
return #lines * self.loveFont:getHeight()
end
end
return Font