-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
text.lua
72 lines (57 loc) · 1.36 KB
/
text.lua
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose: Text class
--
--==========================================================================--
class "gui.text" ( "gui.box" )
local text = gui.text
function text:text( parent, text )
gui.box.box( self, parent, nil )
self:set( text )
end
function text:createCanvas()
end
function text:draw()
assert( false )
love.graphics.setColor( self:getColor() )
love.graphics.draw( self._text )
end
function text:drawCanvas()
if ( not self:isVisible() ) then
return
end
love.graphics.push()
local a = self:getOpacity()
local c = self:getColor()
love.graphics.setColor(
a * c[ 1 ], a * c[ 2 ], a * c[ 3 ], a * c[ 4 ]
)
love.graphics.draw( self._text )
love.graphics.pop()
end
function text:getWidth()
local font = self:getFont()
return font:getWidth( self:get() )
end
function text:getHeight()
local font = self:getFont()
return font:getHeight()
end
function text:set( text )
self.text = text
if ( self._text ) then
self._text:set( text or "" )
else
self._text = love.graphics.newText( self:getFont(), text )
end
end
text.setText = text.set
function text:get()
return rawget( self, "text" ) or ""
end
function text:setFont( font )
self._text:setFont( font )
end
function text:getFont()
return self._text and self._text:getFont() or self:getScheme( "font" )
end