Rectangular Text

BlitzPlus Forums/BlitzPlus Programming/Rectangular Text

Arem(Posted 2005) [#1]
This is a little function I wrote to make a string of text be displayed at a certain location at a certain width. I have already chopped 9 lines off the code and was wondering if anybody could shorten it more.

Graphics 800,600,32,2

SetBuffer BackBuffer()
textsquare("This is the test of the new textsquare function and I need to ramble to make sure it works, so that is what I am doing. I hope it works well. Yeah. This is getting old. Yup. It is. Ok. That ought to be long enough now.",100,20,400)
Flip
WaitKey
End

Function textsquare(incoming$,x,y,width)
word$=""
tempx=x
tempy=y

While incoming$<>""
word$=""
While Right$(word$,1)<>" " And incoming$<>""
word$=word$+Left$(incoming$,1)
incoming$=Right$(incoming$,Len(incoming$)-1)
Wend

If tempx+StringWidth(word$)<width+x
Text(tempx,tempy,word$)
tempx=tempx+StringWidth(word$)
Else
tempx=x
tempy=tempy+FontHeight()
Text(tempx,tempy,word$)
tempx=tempx+StringWidth(word$)
End If
Wend
End Function

Good luck!


WolRon(Posted 2005) [#2]
What are the forum codes?


Arem(Posted 2005) [#3]
You misunderstand me, fool. I don't want to put code in a box for the forums. I want to do it in a graphics mode. I am currently writing a function that does it fully justified.


DredPirateRoberts(Posted 2005) [#4]
not al that shorter line wise but its more efficient




Arem(Posted 2005) [#5]
This code will justify it too!



If you can shorten it, please do.


Arem(Posted 2005) [#6]
Ok. This is as good as I can get it.



22 lines of bliss. Shorten it. Please.