After doing a word wrap function, I got to thinking. Would it really be that hard to have words wrapped without breaking them up? Not at all.
There is a bug. Seems to hault with a box width less than 80. That number is probably different depending on the words in the strings.
So take your longest word "n" and make sure your width can accomodate a width of n+1.
So instead of:
The puppy
is a ver
y large p
et to hav
e at home
.
You'd have:
The puppy
is a very
large pet
to have
at home.
sync on
thing$ = "Hello, my name is Ozark. We are the elephant people that live in the mountains. If you wish to find the magic key, you must first do something for us. Go to the nearest cave, and there you will find a magical and mystical potatoe head. Bring this back to us and we will tell you where you can find the super duper magic key of Rasberry!"
width = 100
repeat
cls
if mouseclick() = 1 then inc width
if mouseclick() = 2 then dec width
if width < 80 then width = 80
talkBox(mousex(),mousey(),thing$,width,rgb(200,255,0),rgb(0,0,255))
sync
until spacekey() = 1
`============================================
`Displays a box and text wrapped to the box.
`The height of the box depends on how many
`lines the text is broken down to.
`(X,Y) Top-left corner of box position
`"S" text to display
`"Width" width of the box
`"tColor" is text color
`"bColor" is box color
`============================================
function talkBox(x as integer, y as integer, s as string, width as integer, tColor as dword, bColor as dword)
sTemp as string
sTemp = s
lines = 1
while text width(sTemp) > width
length = len(sTemp)
for i = 1 to length
if mid$(sTemp, i) = " "
wIndex = i
endif
if text width(left$(sTemp,i)) > width
inc lines
exit
endif
next i
sTemp = right$(sTemp,length-wIndex)
endwhile
height = text height(s) * lines
ink bColor,0
box x,y,x+width,y+height
ink tColor,0
wrapText(x,y,s,width)
endfunction
`============================================
`Wraps and displays text using the specified
`width as the boundary. Words are not broken
`up when wrapped.
`============================================
function wrapText(x as integer, y as integer, s as string, width as integer)
repeat
length = len(s)
wIndex = 0
for i = 1 to length
if mid$(s,i) = " "
wIndex = i
endif
if text width(left$(s,i)) > width
exit
endif
next i
text x,y,left$(s,wIndex-1)
y = y + text height(s)
s = right$(s,length-wIndex)
until text width(s) < width
text x,y,s
endfunction
Your signature has been erased by a mod because it's larger than 600x120...