Created
February 18, 2013 13:10
-
-
Save tluyben/4977254 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method DrawWrap(t:String, x:Float, y:Float, width:Float, align:Int = AngelFont.ALIGN_CENTER) | |
' do some calculations and splitting | |
Local splits:StringList = New StringList | |
Local lw := Floor(width / font.TextWidth("W")) ' about how many letters fit in the width? | |
Local enters:String[] = t.Split("~n") | |
' check if any split string is too long to fit | |
For Local i:=0 Until enters.Length | |
Local s := enters[i] | |
Local s1 := s | |
Local lw1 = s.Length | |
While font.TextWidth(s) >= width | |
While font.TextWidth(s1) >= width | |
Local j | |
For j=lw1-1 To 0 Step -1 | |
If s[j] = 32 | |
lw1 = j | |
Exit | |
End | |
End | |
If j = 0 | |
s1 = s[..lw] | |
Else | |
s1 = s[..lw1] | |
End | |
End | |
s = s[s1.Length..] | |
splits.AddLast(s1.Trim()) | |
s1 = s | |
End | |
If s.Trim() > 0 | |
splits.AddLast(s.Trim()) | |
End | |
End | |
For Local i:=Eachin splits | |
Local x1 := x | |
If align = AngelFont.ALIGN_CENTER | |
x1 = x + (width/2 - font.TextWidth(i) / 2) | |
End | |
font.DrawHTML i, x1, y | |
y = y + font.height | |
End | |
End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment