Code archives/Miscellaneous/Multiline DrawText
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Text | |||||
Function DrawMultilineText:Int( text:String, x:Int, y:Int, lineWidth:Int = 0, cWidth:Int = 0, cHeigth:Int = 0, autowrap:Byte = 0 ) Local linePos:Int = 0 Local textPos:Int = 0 Local width:Int = 0 Local height:Int = TextHeight( "A" ) For Local pos:Int = 1 To text.length Local character:Byte = Asc( Mid( text, pos, 1 ) ) width = TextWidth( Chr( character ) ) If ( textPos / ( cWidth + 1 ) ) >= lineWidth And autowrap = 1 linePos:+ 1 textPos = 0 EndIf If character = 10 'break linePos:+1 textPos = 0 Else DrawText Chr( character ), x + textPos, y + linePos * ( height + cHeigth) textPos:+ ( width + cWidth ) EndIf Next Return linePos EndFunction |
Comments
| ||
Ew! No! Use this:Function DrawTextMultiLine(t:String,x:Float,y:Float) Local parts:String[]=t.split("~n") Local lineheight:Int=TextHeight(" ") Local dy:Float=y For Local i:Int=0 To parts.length-1 DrawText(parts[i],x,dy) dy:+lineheight Next EndFunction |
| ||
no -> no autobreak in your code! |
| ||
? Why in the world would you need "autobreak" functionality? |
| ||
Autowrap? Seems like a good thing to me. |
| ||
Ooohh! I didn't link the two, autobreak and autowrap, and the code wasn't helping anything. :) My apologies. I haven't programmed in a while. :P |
Code Archives Forum