scrolling text box

Blitz3D Forums/Blitz3D Beginners Area/scrolling text box

Hola.

Does anyone have an example of a scrolling text box with word wrap? No scroll bar - just the ability to arrow up and down to scroll through the text with a max of 5 lines or so visible.

Would one of the GUI libs work for this? Sorry, I'm a noob at text and strings, just needing a wee bit of a hand here. I'm using Blitzplay Pro, and it has a few functions that adds text under the next line when Enter is pressed. Once the max lines are reached, the top one is deleted. I'm sure I'll need to edit the HandleMessages() function once I figure this all out, but I'm stumped.

This is a scrolling example:
;-----------------------------------------------------------------------------------------------------
;												types
;-----------------------------------------------------------------------------------------------------

	Type TLine
		Field s$
	End Type
	
;-----------------------------------------------------------------------------------------------------
;											build stuff
;-----------------------------------------------------------------------------------------------------
	
	;setup graphics
	Graphics3D 800, 600, 0, 2
	SetBuffer BackBuffer()

	
	;create a few lines	
	For i = 0 To 20
		CreateLine(	"Line no." + i )
	Next
	
	;init
	TFirst.TLine = First TLine
	TLast.TLine = Last TLine
	
	sel = 1
	

;-----------------------------------------------------------------------------------------------------
;											main loop
;-----------------------------------------------------------------------------------------------------
	Repeat
		
		;check range	
		test1 = (TFirst <> First TLine) And (sel = 1)
		test2 = (TLast <> After After After After First TLine) And (sel = 5)
		
		;cursor up
		If KeyHit(200) Then 
			If test1 Then 
				Insert Last TLine Before First TLine
			Else
				If sel > 1 Then sel = sel - 1
			End If
		End If
		
		;cursor down
		If KeyHit(208) Then 
			If test2 Then 
				Insert First TLine After Last TLine
			Else
				If sel < 5 Then sel = sel + 1
			End If
		End If	
		
		;draw graphics	
		Cls
				
		l.TLine = First TLine
		Color 0, 255, 0
		;take 5 lines
		For c = 1 To 5
			;line "sel" is green
			If c = sel Then Color 0, 255, 0 Else Color 255, 255, 255
			If l <> Null Then
				;draw text to screen
				Text 400, 200 + c * 20, l\s$, 1, 1
				;jump to next line
				l = After l
			End If
		Next
		
		;show graphics		
		Flip
		
	;esc = exit
	Until KeyHit(1)
	
	End
	
;-----------------------------------------------------------------------------------------------------
;												CreateLine()
;-----------------------------------------------------------------------------------------------------
;create a line
Function CreateLine.TLine(s$)
	l.TLine = New TLine
	l\s$ = s$
	Return l
End Function 

For wordwrapping, look at gosse's wrapping functions. They are very nice: http://www.devcrunch.com/forum/viewtopic.php?t=19

Thanks bram32! I was thinking... if there's a possibility that a ton of text is going to be collected, would it be better for me to create a .txt file to hold the text and read it in real-time, then delete the .txt file upon program exit?

I don't know. How much text are you expecting? I think you need to balance disk and memory usage during the program. You could also consider reading/writing text file in blocks. I mean, read or write say 256 lines in one turn, dispose them and then read the next 256 lines. This way the memory will hold only 256 lines the entire time and the program doesn't read the file too often. I believe that, in general, disk usage is slower than using memory.