This function allows you to place a scrolling text box of any size at any position on the screen.
Passing the text you want to print to the function will print the text inside the box at the first free line and when the box is full, automatically scroll the text up to make room.
You can also specify if you want a border around the box and the box background colour.
The function works regardless of the font face or font size currently in use.
The function:
Function ScrollPrint(XPos,YPos,ScrollBoxWidth,ScrollBoxHeight,NewLine$,R,G,B,Border)
TextHeight = Text Height("A")
Numlines = ScrollBoxHeight/TextHeight+1: Rem Number of lines to print before scrolling takes place
If NewLine$ <> ""
If LineCount(0) < Numlines
LineCount(0) = LineCount(0)+1
If LineCount(0) > Numlines Then LineCount(0) = Numlines
Endif
ActLine = LineCount(0)
If ActLine < Numlines
Rem Free Array Slots Available...
Display$(ActLine) = NewLine$
Else
Rem Array Full...
For Q = 1 To Numlines-2
Display$(Q) = Display$(Q+1)
Next Q
Display$(Numlines-1) = NewLine$
Endif
If Border = 1
Ink RGB(255,255,255),0: Rem Border line colour
Box XPos,YPos,XPos+ScrollBoxWidth-1,YPos+ScrollBoxHeight-1
Endif
Ink RGB(R,G,B),0: Rem Set to text box background colour
Box XPos+1,YPos+1,XPos+ScrollBoxWidth-2,YPos+ScrollBoxHeight-2
Ink RGB(255,255,255),0: Rem Text colour
For Y = 0 To NumLines-1
Text XPos+2,Y*TextHeight+YPos,Display$(Y+1)
Next Y
Sync
Endif
EndFunction
Usage Notes:
XPos,YPos - Screen position of top left corner of text box
ScrollBoxWidth,ScrollBoxHeight - Width and Height of box
NewLine$ - Text to print
R,G,B - Background colour of text box
Border - 0 for no border and 1 for a border around text box
Important!
You MUST include the two following DIM statements at the top of your program:
Dim Display$(100): Rem Array required for function
Dim LineCount(0): Rem Array required for function
Example Usage Demo Program:
Dim Display$(100): Rem Array required for function
Dim LineCount(0): Rem Array required for function
Set Display Mode 640,480,16
Sync On: Sync Rate 0: CLS 0
Rem ******************************************************************
Rem If you need a different font/font size, unrem and alter lines here
Rem Set Text Font "Courier New"
Rem Set Text Size 12
Rem ******************************************************************
XPos=100: Rem X position of scroll box on screen
YPos=100: Rem Y position of scroll box on screen
ScrollBoxWidth = 320: Rem Width of scroll (Set to screen width for full screen)
ScrollBoxHeight = 200: Rem Height of scroll (Set to screen height for full screen)
Border = 1: Rem Set this to 0 for no border and 1 for a white border
R = 50: G = 50: B = 50: Rem Text box background colour RGB values
For A=1 To 100
NewLine$="Example Line Of Text "+Str$(A)
ScrollPrint(XPos,YPos,ScrollBoxWidth,ScrollBoxHeight,NewLine$,R,G,B,Border): Rem <<<< Call this instead of Print
Sleep 40
Next A
End
Function ScrollPrint(XPos,YPos,ScrollBoxWidth,ScrollBoxHeight,NewLine$,R,G,B,Border)
TextHeight = Text Height("A")
Numlines = ScrollBoxHeight/TextHeight+1: Rem Number of lines to print before scrolling takes place
If NewLine$ <> ""
If LineCount(0) < Numlines
LineCount(0) = LineCount(0)+1
If LineCount(0) > Numlines Then LineCount(0) = Numlines
Endif
ActLine = LineCount(0)
If ActLine < Numlines
Rem Free Array Slots Available...
Display$(ActLine) = NewLine$
Else
Rem Array Full...
For Q = 1 To Numlines-2
Display$(Q) = Display$(Q+1)
Next Q
Display$(Numlines-1) = NewLine$
Endif
If Border = 1
Ink RGB(255,255,255),0: Rem Border line colour
Box XPos,YPos,XPos+ScrollBoxWidth-1,YPos+ScrollBoxHeight-1
Endif
Ink RGB(R,G,B),0: Rem Set to text box background colour
Box XPos+1,YPos+1,XPos+ScrollBoxWidth-2,YPos+ScrollBoxHeight-2
Ink RGB(255,255,255),0: Rem Text colour
For Y = 0 To NumLines-1
Text XPos+2,Y*TextHeight+YPos,Display$(Y+1)
Next Y
Sync
Endif
EndFunction
TDK_Man