
Function Text_Box_String ( ByRef Buffer As String = EMPTY, W As Long = 40, H As Long = 30) As String

	If Len ( Buffer ) = 0 Then
		Return EMPTY
	End If

	Dim As String Subject_Buffer = EMPTY, Queue_Buffer = EMPTY, Output_Buffer = EMPTY
	
	Queue_Buffer = Buffer

	Do While StrPos ( SP & SP, Queue_Buffer ) > 0
		
		Queue_Buffer = Prefix ( SP & SP, Queue_Buffer ) & SP & Suffix ( SP & SP, Queue_Buffer )
		
	Loop

	Do While StrPos ( CRLF & CRLF, Queue_Buffer ) > 0
		
		Queue_Buffer = Prefix ( CRLF & CRLF, Queue_Buffer ) & CRLF & Suffix ( CRLF & CRLF, Queue_Buffer )
		
	Loop
	
	Do
		If Len ( Queue_Buffer ) = 0 Then
			Return Subject_Buffer
		End If
		
		Do While Len ( Prefix ( CRLF, Queue_Buffer ) ) < Len ( Prefix ( SP, Queue_Buffer ) )
			
			If Len ( Queue_Buffer ) = 0 Then
				Return Subject_Buffer
			End If

			Do While Len ( Prefix ( CRLF, Queue_Buffer ) ) > W
				If Len ( Queue_Buffer ) = 0 Then
					Return Subject_Buffer
				End If

				Output_Buffer &= Left( Queue_Buffer, W - Len ( Subject_Buffer ) - 1 ) & "-" & CRLF
			
				Queue_Buffer = Mid( Queue_Buffer, W - Len ( Subject_Buffer ) + 1 )
			
				Subject_Buffer = EMPTY
				
			Loop
			
		Loop

		Do While Len ( Prefix ( SP, Queue_Buffer ) ) > W
			
			If Len ( Queue_Buffer ) = 0 Then
				Return Subject_Buffer
			End If
			
			Output_Buffer &= Left( Queue_Buffer, W - Len ( Subject_Buffer ) - 1 ) & "-" & CRLF
			
			Queue_Buffer = Mid( Queue_Buffer, W - Len ( Subject_Buffer ) + 1 )
			
			Subject_Buffer = EMPTY
			
		Loop
		
		Select Case Len ( Subject_Buffer & Prefix ( SP, Queue_Buffer ) )
		
		Case IS <= W
		
			Subject_Buffer &= Prefix ( SP, Queue_Buffer )
			
		Case Else
		
			Output_Buffer &= Subject_Buffer & CRLF
			
			Subject_Buffer = EMPTY
			
		End Select

		If Len ( Queue_Buffer ) = 0 Then
		
			Exit Do
			
		End If

	Loop
	
	Return Output_Buffer
	
End Function

Function Text_Box_Render ( ByRef Buffer As String = EMPTY, W As Long = 40, H As Long = 30, Y_Scroll As Long = 0 ) As FB.Image Ptr

	'Color RGBA ( 255, 255, 0, 255 )
	'Print "Function Text_Box_Render ( Buffer As String = " & QUOT & Buffer & QUOT & ", W As Long = "& QUOT & W & QUOT & ", H As Long = "& QUOT & H & QUOT & ", Y_Scroll As Long = "& QUOT & Y_Scroll & QUOT & " ) As FB.Image Ptr"

	Color RGBA ( 255, 255, 255, 255 )
	
	SimpleSleep ( VGA_Table ( ), ESC )
	
	Dim As String Buff, Subject : Buff = Buffer : Subject = EMPTY
	
	Dim As FB.Image Ptr Image = ImageCreate ( W * 8, H * 8, RGBA ( 0, 0, 0, 0 ), 32 )
	
	'Buff = Text_Box_String ( Buffer, W, H ) : Subject = EMPTY
	
	Dim As Long X = 1, Y = 0

	Do While Len ( Buff ) > 0
		
		Y += 1
		
		Subject = Prefix( CRLF, Buff ) : Buff = Suffix( CRLF, Buff )
		
		If Y - Y_Scroll >= 1 AndAlso Y - Y_Scroll <= H Then
			
			Draw String Image, ( ( X - 1 ) * 8, ( Y - 1 - Y_Scroll ) * 8 ), Subject, RGBA ( 0, 255, 0, 255 )
		
		ElseIf Y - Y_Scroll > H Then
			
			Exit Do
		
		End If
		
		If Len ( Buff ) = 0 Then
		
			Exit Do
			
		End If
		
	Loop

	Line Image, ( 0, 0 ) - ( Image -> Width - 1, Image -> Height - 1 ), RGBA ( 255, 0, 0, 128 )
	
	Line Image, ( Image -> Width - 1, 0 ) - ( 0, Image -> Height - 1 ), RGBA ( 255, 0, 0, 128 )
	
	Return Image

End Function

Function SEQ_Echo_Direct ( ByVal SEQ_Text_Buffer As String = EMPTY ) As String
	
	Dim As FB.Image Ptr SEQ_Text_Image
	
	'SEQ_Text_Buffer = Text_Box_String ( SEQ_Text_Buffer, 40, 30 ) 
	SEQ_Text_Image = Text_Box_Render ( SEQ_Text_Buffer, 40, 30, 0 )
	
	Line SEQ_Text_Image, ( 0, 0 ) - ( SEQ_Text_Image -> Width - 1, SEQ_Text_Image -> Height - 1 ), RGBA ( 0, 255, 0, 196 )
	
	Line SEQ_Text_Image, ( SEQ_Text_Image -> Width - 1, 0 ) - ( 0, SEQ_Text_Image -> Height - 1 ), RGBA ( 0, 255, 0, 196 )
	
	Put ( 0, 0 ), SEQ_Text_Image, Alpha : SimpleSleep ( VGA_Table ( ), ESC )
	SEQ_Text_Image = ImageDestroy2 ( SEQ_Text_Image )
	
	Return SEQ_Text_Buffer
	
End Function

Function Property_Echo_Direct ( ByVal Property_Text_Buffer As String = EMPTY ) As String
	
	Dim As FB.Image Ptr Property_Text_Image
	
	'Property_Text_Buffer = Text_Box_String ( Property_Text_Buffer, 40, 30 ) 
	Property_Text_Image = Text_Box_Render ( Property_Text_Buffer, 40, 30, 0 )
	
	Line Property_Text_Image, ( 0, 0 ) - ( Property_Text_Image -> Width - 1, Property_Text_Image -> Height - 1 ), RGBA ( 0, 255, 0, 196 )
	
	Line Property_Text_Image, ( Property_Text_Image -> Width - 1, 0 ) - ( 0, Property_Text_Image -> Height - 1 ), RGBA ( 0, 255, 0, 196 )
	
	Put ( 0, 0 ), Property_Text_Image, Alpha : SimpleSleep ( VGA_Table ( ) )

	Property_Text_Image = ImageDestroy2 ( Property_Text_Image )
	
	Return Property_Text_Buffer
	
End Function
