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

@@ -1,67 +1,5 @@
local ROOT = (...):gsub('[^.]*$', '')
local Base = require(ROOT .. 'base')
local Backend = require(ROOT .. 'backend')
local Font = Base:extend()
local cache = {}
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 cache[key] then
if path then
cache[key] = love.graphics.newFont(path, size)
else
cache[key] = love.graphics.newFont(size)
end
end
self.layout = {}
self.font = cache[key]
self.color = color
end
function Font:setAlignment (align)
self.layout.align = align
end
function Font:setWidth (width)
self.layout.width = width
end
function Font:getLineHeight ()
return self.font:getHeight()
end
function Font:getAscender ()
return self.font:getAscent()
end
function Font:getDescender ()
return self.font:getDescent()
end
function Font:getAdvance (text)
return (self.font:getWidth(text))
end
if love._version_minor < 10 then
function Font:getWrappedHeight (text)
local _, lines = self.font:getWrap(text, self.layout.width)
return lines * self.font:getHeight()
end
else
function Font:getWrappedHeight (text)
local _, lines = self.font:getWrap(text, self.layout.width)
return #lines * self.font:getHeight()
end
end
return Font
return Backend.Font