Qbasicnews.com

Full Version: Text scrolling routine, with psudeocursor
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is my text scrolling routine, complete with psudeo-cursor. I plan to use it in my QB-IDE clone (link in my signature). BTW, if anyone knows how I can make something other than a block cursor, please let me know.

Use:
arrow keys move the cursor
escape quits

Code:
'base code from DJ Peters (Joshy)
'Dr_D corrected mistakes in UDT usage
'Cha0s corrected some screen bugs
'I modded it to use a cursor and color text, and fixed a few bugs

#Include "fbgfx.bi"

#if __FB_VERSION__ >= "0.17"
  Using FB
#endif

ScreenRes 640,480,8
#define max_x 100
#define max_y 100

Type text Field=1
  char As ubyte
  fgc As Ubyte
  bgc As Ubyte
End Type

Dim As text Ptr    lpRow,lpTextBuffer=callocate(max_x*max_y*sizeof(text))
Dim As uInteger     xPos,yPos,xLast,yLast,i,j,doit=0

ScreenInfo xLast,yLast
xLast Shr=3:yLast Shr=3

For i = 0 To max_x*max_y-1
  lpTextBuffer[i].char=32+Int(Rnd*32)
  lpTextBuffer[i].fgc=Int(Rnd*5)+2
  lpTextBuffer[i].bgc=Int(Rnd*5)+2
Next

lpTextBuffer[0              ].char = 65 ' left top
lpTextBuffer[max_x-1        ].char = 65 ' right top
lpTextBuffer[(max_y-1)*max_x].char = 65 ' left bottom
lpTextBuffer[max_y*max_x-1  ].char = 65 ' right bottom

lpTextBuffer[0              ].fgc  = 1
lpTextBuffer[max_x-1        ].fgc  = 1 ' right top
lpTextBuffer[(max_y-1)*max_x].fgc  = 1 ' left bottom
lpTextBuffer[max_y*max_x-1  ].fgc  = 1 ' right bottom

lpTextBuffer[0              ].bgc  = 2 ' left top
lpTextBuffer[max_x-1        ].bgc  = 2 ' right top
lpTextBuffer[(max_y-1)*max_x].bgc  = 2 ' left bottom
lpTextBuffer[max_y*max_x-1  ].bgc =  2 ' right bottom


Dim As Ubyte CurPosY=0, CurPosX=0
Dim As ubyte n
Do
    If MultiKey(SC_UP) Then
        If CurPosY > 0 Then
            CurPosY -= 1
        Elseif CurPosY = 0 Then
            If yPos > 0 Then yPos-=1
        Endif
        doit=1
    Endif
                  
    If MultiKey(SC_DOWN) Then
        If CurPosY+1 = Ylast Then
                If yPos < max_y-yLast Then yPos+=1
        Elseif CurPosY < ylast Then
                curposy += 1
        Endif
        doit=1
    End If
  
    If MultiKey(SC_LEFT ) Then
        If CurPosX > 0 Then
            CurPosX -= 1
        Elseif CurPosX = 0 Then
            If xPos > 0 Then xPos-=1
        Endif
        doit=1
    Endif
  
    If MultiKey(SC_RIGHT) Then
        If CurPosx+1 = xlast Then
                If xPos < max_x-xLast Then xPos+=1
        Elseif CurPosx < xlast Then
                curposx += 1
        Endif
        doit=1
    Endif
      
    If doit=1 Then
        lpRow=lpTextBuffer+xPos+yPos*max_x
      
        windowtitle xPos & "," & yPos & " " & CurPosX & "," & CurPosY
      
        screenlock
        Locate 1, 1, 0
        For i=1 To yLast
            For j=0 To xLast-1
                Color lpRow[j].fgc,lpRow[j].bgc
                Print chr(lpRow[j].char);
            Next
        lpRow+=max_x
        Next
      
        Locate CurPosY+1,CurPosX+1,0:Color 8,8:Print Chr(219);
      
        DoIt=0
        screenunlock
    End If

    If multikey(SC_ESCAPE) Then n=1
  
    Do:Loop Until Inkey=""

Loop Until n=1
deallocate(lpTextBuffer)
End
The pipe symbol is similar to the Windows cursor. On my keyboard, it's directly above Enter. The DOS "insert" cursor was the underscore character.
Well, in DOS, the overtype cursor character was #219. That's no problem to emulate with color calls. The insert one is a tad harder, I have to show an underscore without compromising the character above.
Oh... yes... I forgot about that... hmm.