Multiline text in a box

BlitzMax Forums/BlitzMax Beginners Area/Multiline text in a box

Czar Flavius(Posted 2008) [#1]
Is there an easy way to output multiline text in a box/designated area? Any modules?


slenkar(Posted 2008) [#2]
blitzmax has awesome string functions which makes it easier to do wordwrap:


this to put the text in lines in a list:

local the_text$=YOURTEXT
local width=YOURBOXWIDTH

If TextWidth(the_text) > width - 9
Local word_array$[] = the_text.split(" ")
Local new_string$
Local long_string$
Local iter = 0

While iter<word_array.length
Local a$ = word_array[iter]

long_string$ = new_string + A$

If TextWidth(long_string)>width-9
line_list.addlast(new_string)

new_string = a+" "
long_string=""

If iter = word_array.length-1
line_list.addlast(New_String)
EndIf

Else
new_string = new_string + a + " "

If iter=word_array.length-1
line_list.addlast(new_string)
EndIf

EndIf

iter = iter + 1

Wend
Else
line_list.addlast(the_text)
EndIf

current_line = (line_list.count() - (height /TextHeight("hi")))+2



this is to draw the text:

local height=YOURBOXHEIGHT
local
Local line_position=0
Local iter=0
For Local a$ = EachIn line_list

If line_position > current_line - 1
If line_position < (current_line + (height / TextHeight(a)) )-1
DrawText a,x+9,y+(iter*TextHeight(a))+5
iter=iter+1
EndIf
EndIf

line_position=line_position+1
Next




Czar Flavius(Posted 2008) [#3]
Thanks!! Quick question, does this work with all fonts and sizes or just the default? There are some "magic numbers" (numeric constants with no obvious meaning) what are they for?


plash(Posted 2008) [#4]
FonText has a lot of text formatability.


slenkar(Posted 2008) [#5]
I think it works with all because of the textheight command.
the capital letters are stuff that you have to fill in yourself.