home *** CD-ROM | disk | FTP | other *** search
- `Here's a function to display text within specified margins.
- dim imageflag(1)
-
- a$="Insert some funky old test string. "
- for j=1 to 82
- wrap(a$)
- next j
-
- if imageflag(1)=1 then delete image 99
- undim imageflag(1)
- end
-
- FUNCTION wrap(a$)
- `Change these 6 values as needed, all values in pixels.
- `Make left & right margins > 0, make top & bottom margins
- `multiples of text height, which by default is 16.
- screenwidth=640 : screenheight=480
- leftmargin=25 : rightmargin=25
- topmargin=16 : bottommargin=16*9
-
- aheight=text height(a$)
- if xover<leftmargin then xover=leftmargin
- if ydown<topmargin then ydown=topmargin
- nextline$=""
-
- do
- alen=len(a$)
- `get rid of any spaces at beginning of a$...
- while left$(a$,1)=" "
- dec alen
- a$=right$(a$,alen)
- endwhile
-
- awidth=text width(a$)
- room=screenwidth-rightmargin-xover
- `if there's room on the line, display a$, exit do-loop...
- if awidth<room
- text xover,ydown,a$
- xover=xover+awidth
- exit
- endif
-
- `...otherwise go backwards along a$,
- `moving the last character into nextline$
- `until a$ is short enough to fit...
- while awidth>room
- nextline$=right$(a$,1)+nextline$
- dec alen
- a$=left$(a$,alen)
- awidth=text width(a$)
- endwhile
-
- `then count back until it hits a space,
- `so you don't break mid-word...
- righ$=right$(a$,1)
- while righ$<>" " and alen>0
- nextline$=righ$+nextline$
- dec alen
- a$=left$(a$,alen)
- righ$=right$(a$,1)
- endwhile
-
- `print a$ to screen...
- text xover,ydown,a$
- `and make nextline$ the new a$...
- a$=nextline$ : nextline$=""
- xover=leftmargin : ydown=ydown+aheight
-
- `scroll it off the top if necessary...
- if ydown=>screenheight-bottommargin
- x2=screenwidth-rightmargin : y2=screenheight-bottommargin
- if y2>screenheight then y2=screenheight
- get image 99,leftmargin,topmargin+aheight,x2,y2
- paste image 99,leftmargin,topmargin
- ink 0,0
- box leftmargin,screenheight-bottommargin-aheight,x2,y2
- ink rgb(255,255,255),0
- ydown=screenheight-bottommargin-aheight
- imageflag(1)=1
- endif
- loop
- ENDFUNCTION
-