Heres som old code i had lying around (modified slightly to support newlines) if anyone wants.
This draws text inside a frame and wraps on words/cr.
Hope it helps =)
Graphics 640,480, 0
Repeat
SetColor 128,128,128
DrawRect 32,32, 128,128
SetColor 256,256,256
DrawTextRect( 32+1,32+1, 128-2,128-2, "A quick brown fox jumped over the fence...~n1~n2~n3")
Flip
Cls
Until KeyHit( KEY_ESCAPE)
End
Function GetNextEx:String( value:String Var, seps:String[])
Local index:Int, s:String
If (value.Length <= 0) Or (seps.Length <= 0) Then Return Null
For s = EachIn seps
index = value.Find( s)
If index = 0 Then
value = value[s.Length..]
Return Null
ElseIf index >= 1 Then
Local res:String = value[..index]
value = value[index + s.Length..]
Return res
EndIf
Next
If value.Length > 0 Then
s = value
value = Null
Return s
EndIf
Return Null
EndFunction
Function DrawTextRect( x:Int,y:Int,w:Int,h:Int, text:String)
' seperate text into words with spaces,tabs & crlf
Local words:String[], ss:String, idx:Int
Repeat
ss = GetNextEx( text, [" ","~t"])
idx = ss.Find( "~n")
If idx <> -1 Then
Repeat
Local tmp:String = GetNextEx( ss, ["~r~n","~n"])
If tmp.Length > 0 Then
words = words[..words.Length + 2]
words[words.length - 2] = tmp
EndIf
Until ss.Length = 0
Else
words = words[..words.Length + 1]
words[words.Length - 1] = ss
EndIf
Until text.Length = 0
' draw it within the suplied frame
Local xx:Int,yy:Int, ww:Int,hh:Int
For Local s:String = EachIn words
If s.length <= 0 Then
xx = 0
yy :+ TextHeight("jX")
Else
ww = TextWidth(s)
hh = TextHeight(s)
If xx + ww > w Then
xx = 0
yy :+ hh
EndIf
DrawText s, x+xx,y+yy
xx :+ ww + TextWidth( " ")
EndIf
Next
EndFunction