Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A scrolling SUB for text in SCREEN 0
#1
Hi friends
thanks to Pete (whose code I have used to go on with Text Scrolling in SCREEN 0) I have made a versatile version of the code to get a scrolling of text in a window in mode only text (SCREEN 0).
Don't scare yourself with the long list of parameters that the SUB need. It is better than using SHARED variables that made the code lesser portable towards this one that follows.

Code: (Select All)

_Title "Scrolling text in SCREEN 0 with arrow keys"
_ControlChr Off
Dim TRmin As Integer, TRmax As Integer, TCmin As Integer, TCmax As Integer ' it declares the limit of text's area
Dim CharMin As Integer, CharMax As Integer, RowMin As Integer, RowMax As Integer ' it declares the dimensions of text to be printed on the screen
TRmin = 1: TRmax = 25: TCmin = 1: TCmax = 80
CharMin = 1: CharMax = 255: RowMin = 1: RowMax = 40
Width TCmax, TRmax ' screen 0 only text 80 columns for 25 rows


Dim Row As String, Text(RowMin To RowMax) As String, cText(CharMin To CharMax, RowMin To RowMax) As Integer
Dim a As Integer, b As Integer, R As Integer, C As Integer

' initialization

' it builds a string of 255 characters
For a = CharMin To CharMax
    Row = Row + Chr$(a)
Next a
' it builds  40 rows of 255 characters for row
For a = RowMin To RowMax
    Text(a) = Right$(Row, a + 10) + Left$(Row, CharMax - a - 10)
    For b = CharMin To CharMax
        cText(b, a) = (b * a) Mod 7
    Next b
Next a
' here it sets row and column at the start
R = 1
C = 1
PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R, C, Text(), cText(), 0
While -1
    _Limit 30
    Row = UCase$(InKey$)
    If Len(Row) = 2 Then
        Select Case InStr("HPKM", Mid$(Row, 2, 1))
            Case 1: R = R - 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R, C, Text(), cText(), 0
            Case 2: R = R + 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R, C, Text(), cText(), 0
            Case 3: C = C - 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R, C, Text(), cText(), 0
            Case 4: C = C + 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R, C, Text(), cText(), 0
        End Select
    End If
    _Display
Wend
End

Sub PrintTxt (TRm As Integer, TRmx As Integer, TCm As Integer, TCmx As Integer, Cm As Integer, Cmx As Integer, Rm As Integer, Rmx As Integer, Ra As Integer, Ca As Integer, T() As String, cT() As Integer, Bc As Integer)
    ' TRm text row min, TRmx text row max, TCm text column min, TCmx text column max, Cm char min, Cmx char max
    ' Rm row min, Rmx row max, Ra row actual, Ca column actual, T() text,cT() color text, Bc background color
    Cls , Bc
    For a = TRm - 1 To TRmx - 1
        Locate a + 1, TCm
        If (a + Ra) < Rmx + 1 And (a + Ra) > Rm - 1 Then
            For b = TCm To TCmx
                If (Ca + b - 1 < Cmx + 1) And (Ca + b - 1 > Cm - 1) Then
                    Color , cT(Ca + b - 1, a + Ra)
                    Print Mid$(T(a + Ra), Ca + b - 1, 1);
                Else
                    Color , Bc
                    Print " ";
                End If
            Next b
        End If
    Next
End Sub

the code is still that of Pete, but changing the parameters of rows of the window and/or of columns of the window you get the same behaviour of the text in the window...
here 2 screenschots after changing the rows or the columns of the window.


[Image: Different-rows-in-screen-0-Immagine-2024...014952.jpg]


[Image: different-columns-in-screen-0-Immagine-2...015646.jpg]

if do you find it interesting, it is possible to build a demonstration that manages different text area in the same window of text in Screen 0.
Thanks for feedbacks
Reply
#2
Hi friends
here a more complex evolution of the demonstration on the scrolling text into a text window in screen 0.

Code: (Select All)

' a little demonstration about making windows with text scrolling into them in Screen 0

' ---------------------  a bit of theory on windows in screen 0
'  ANATOMY of a Text Window
'
'  Upper Left corner      Title Bar      Title      Upper Right Corner
'    \                        |            |                  /
'    \                      |            |                  /
'      >ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ title on the bar ÍÍÍÍÍÍÍÍÍ»<
'        º                                                  º
'        º                                                  º
' lateralº              area of window                      º
'  bar ->º                                                  º
'        º                                                  º
'        º                                                  º
'      >ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ text on the status bar ÍÍÍÍÍÍÍÍͼ<
'      /                |              |                      \
'    /                |              |                      \
'Bottom Left corner  Status Bar      Status          Bottom Right corner

'the frame (cornice) of the window has its necessary elements: 4 corners (Upper Left, Upper Right, Bottom Left, Bottom Right)
' the title bar, the status bar and 2 lateral bars
'    the space within the frame is the area of the window: here text is scrolling by user input
'---------------

Screen 0
_FullScreen
_ControlChr Off

'global SHARED variables
Dim Shared As String UL, UR, BL, BR, HO, VE

'Global variables
Dim TRmin As Integer, TRmax As Integer, TCmin As Integer, TCmax As Integer ' it declares the limit of text's area
Dim CharMin As Integer, CharMax As Integer, RowMin As Integer, RowMax As Integer ' it declares the dimensions of text to be printed on the screen

CharMin = 1: CharMax = 255: RowMin = 1: RowMax = 40

Dim Row As String, Text(RowMin To RowMax) As String, cText(CharMin To CharMax, RowMin To RowMax) As Integer ' it declares the text data and color array data
Dim a As Integer, b As Integer, R(1 To 3) As Integer, C(1 To 3) As Integer, FC(1 To 3) As Integer, BC(1 To 3) As Integer ' it declares index variables

' initialization
UL = "É": UR = "»": BL = "È": BR = "¼": HO = "Í": VE = "º"


' it builds a string of 255 characters
For a = CharMin To CharMax
    Row = Row + Chr$(a)
Next a
' it builds  40 rows of 255 characters for row
a = 1: b = 1
For a = RowMin To RowMax
    Text(a) = Right$(Row, a + 10) + Left$(Row, CharMax - a - 10)
    For b = CharMin To CharMax
        cText(b, a) = (b * a) Mod 7
    Next b
Next a
FC(1) = 15: BC(1) = 1
FC(2) = 11: BC(2) = 2
FC(3) = 12: BC(3) = 3

'here it makes windows' frames
Color FC(1), BC(1)
makeWindow 1, 1, 80, 15, " Editor "
Color FC(2), BC(2)
makeWindow 15, 1, 80, 6, " Output "
Color FC(3), BC(3)
makeWindow 20, 1, 80, 7, " Help "
Color 15, 0

' here it sets row and column at the start
' and it writes text into windows

'window Help
R(3) = 1
C(3) = 1
TRmin = 21: TRmax = 24: TCmin = 2: TCmax = 79
PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R(3), C(3), Text(), cText(), BC(3), FC(3)

' window Output
R(2) = 1
C(2) = 1
TRmin = 16: TRmax = 18: TCmin = 2: TCmax = 79
PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R(2), C(2), Text(), cText(), BC(2), FC(2)

' window Editor
R(1) = 1
C(1) = 1
TRmin = 2: TRmax = 13: TCmin = 2: TCmax = 79
PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R(1), C(1), Text(), cText(), BC(1), FC(1)

a = 1
While Row <> " "
    _Limit 30
    Row = UCase$(InKey$)
    If Len(Row) = 2 Then
        Select Case InStr("HPKM", Mid$(Row, 2, 1))
            Case 1: R(a) = R(a) - 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R(a), C(a), Text(), cText(), BC(a), FC(a)
            Case 2: R(a) = R(a) + 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R(a), C(a), Text(), cText(), BC(a), FC(a)
            Case 3: C(a) = C(a) - 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R(a), C(a), Text(), cText(), BC(a), FC(a)
            Case 4: C(a) = C(a) + 1
                PrintTxt TRmin, TRmax, TCmin, TCmax, CharMin, CharMax, RowMin, RowMax, R(a), C(a), Text(), cText(), BC(a), FC(a)
        End Select
    ElseIf Len(Row) = 1 And InStr("123", Mid$(Row, 1, 1)) Then
        a = InStr("123", Mid$(Row, 1, 1))
        Select Case a
            Case 1:
                TRmin = 2: TRmax = 13: TCmin = 2: TCmax = 79
            Case 2:
                TRmin = 16: TRmax = 18: TCmin = 2: TCmax = 79
            Case 3:
                TRmin = 21: TRmax = 24: TCmin = 2: TCmax = 79
        End Select
    End If
    _Display
Wend
Color 15, 0
End



Sub makeWindow (row As Integer, col As Integer, widthW As Integer, heightW As Integer, TitleW As String)
    If Len(TitleW) > widthW Then TitleW = Left$(_Trim$(TitleW), 3)
    Locate row, col
    Print UL + String$(widthW - 2, HO) + UR;
    For a% = row + 1 To row + heightW - 2
        Locate a%, col
        Print VE + Space$(widthW - 2) + VE;
    Next a%
    Locate , col
    Print BL + String$(widthW - 2, HO) + BR;
    Locate row, col + Fix((widthW - Len(TitleW)) / 2)
    Print TitleW;
End Sub

Sub PrintTxt (TRm As Integer, TRmx As Integer, TCm As Integer, TCmx As Integer, Cm As Integer, Cmx As Integer, Rm As Integer, Rmx As Integer, Ra As Integer, Ca As Integer, T() As String, cT() As Integer, Bc As Integer, Fc As Integer)
    ' TRm text row min, TRmx text row max, TCm text column min, TCmx text column max, Cm char min, Cmx char max
    ' Rm row min, Rmx row max, Ra row actual, Ca column actual, T() text,cT() color text, Bc background color, Fc foreground color
    Ccls Fc, Bc, TRm, TRmx, TCm, TCmx
    For a = TRm - 1 To TRmx - 1
        Locate a + 1, TCm
        If (a + Ra) < Rmx + 1 And (a + Ra) > Rm - 1 Then
            For b = TCm To TCmx
                If (Ca + b - 1 < Cmx + 1) And (Ca + b - 1 > Cm - 1) Then
                    Color , cT(Ca + b - 1, a + Ra)
                    Print Mid$(T(a + Ra), Ca + b - 1, 1);
                Else
                    Color Fc, Bc
                    Print " ";
                End If
            Next b
        End If
    Next
End Sub

Sub Ccls (Fc As Integer, Bc As Integer, TRm As Integer, TRmx As Integer, TCm As Integer, TCmx As Integer)
    Color Fc, Bc
    For a = TRm - 1 To TRmx - 1
        Locate a + 1, TCm
        Print Space$(TCmx - TCm + 1);
    Next a
End Sub

use arrows keys to scroll text being into the window
use 1 or 2 or 3 to navigate among the text windows
use space bar to quit

here a screenshot


[Image: Scrolling-demo-in-windows-in-screen-0-Im...004026.png]
Reply




Users browsing this thread: 2 Guest(s)