Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A scrolling SUB for text in SCREEN 0
#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


Messages In This Thread
RE: A scrolling SUB for text in SCREEN 0 - by TempodiBasic - 12-10-2024, 01:04 AM



Users browsing this thread: 1 Guest(s)