-
Notifications
You must be signed in to change notification settings - Fork 2
/
utilfont.monkey
52 lines (47 loc) · 1.87 KB
/
utilfont.monkey
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
Import mojo
Import fontmachine
Import horizon.application
Class UtilFont
Const KEY_ENTER% = CHAR_ENTER
Function Draw(font:BitmapFont, txt:String, x:Int, y:Int, boxWidth:Int, lineHeight:Float = 1.0)
Local sy:Int = y
For Local f2line:String = EachIn txt.Split("~n")
For Local line:String = EachIn f2line.Split(KEY_ENTER)
If (font.GetTxtWidth(line) > boxWidth)
Local px:Int = x
For Local word:String = EachIn line.Split(" ")
If (font.GetTxtWidth(word) + px > x + boxWidth)
y += font.GetFontHeight() * lineHeight
px = x
End If
font.DrawText (word + " ", px, y)
px += font.GetTxtWidth(word + " ")
Next
Else
font.DrawText line, x, y
End If
y += font.GetFontHeight() * lineHeight
Next
Next
End Function
Function GetHeight:Int(font:BitmapFont, txt:String, boxWidth:Int, lineHeight:Float = 1.0)
Local x:Int = 0
Local y:Int = 0
For Local f2line:String = EachIn txt.Split("~n")
For Local line:String = EachIn f2line.Split(CHAR_ENTER)
If (font.GetTxtWidth(line) > boxWidth)
Local px:Int = x
For Local word:String = EachIn line.Split(" ")
If (font.GetTxtWidth(word) + px > x + boxWidth)
y += font.GetFontHeight() * lineHeight
px = x
End If
px += font.GetTxtWidth(word + " ")
Next
End If
y += font.GetFontHeight() * lineHeight
Next
Next
Return y
End Function
End