home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / snip0693.zip / SCROLBAR.PRG < prev    next >
Text File  |  1993-05-21  |  3KB  |  75 lines

  1. /*
  2.  This is SuccessWare's raw functions with some minor changes I made.
  3.  It is not perfect but it will work with the Six stuff. I made it
  4.  return the current scroll so I could implement nested browses.
  5.  Lots of ways to do this but this should give you some basics.
  6.  I make the first call with the coordinates and a .f. so it
  7.  doesn't display ahead of the rest of my window.
  8.  
  9.    ShowScrollBar() - This function displays a simple vertical "scroll bar"
  10.                      for a TBrowse on the current table and index.  Call
  11.                      ShowScrollBar() with scroll bar screen coordinates to
  12.                      initialize it, then with no parameters to update it.
  13.                      Static variables are used to keep track of screen
  14.                      coordinates and step value.  Called from Main().
  15. */
  16.  
  17. FUNC ShowScrollBar( pArray , lDisplay )
  18. // parameter is an array of nTop, nLeft, nBottom, nRight
  19.  
  20.     static nBarTop, nBarLeft, nBarBottom, nBarRight, nBarWidth
  21.     static nKeyStep, nKeys
  22.  
  23.     LOCAL  nPos
  24.     LOCAL i
  25.     LOCAL keyno
  26.     LOCAL aReturn := { nBarTop , nBarLeft , nBarBottom , nBarRight }
  27.  
  28.     // Did we get coordinates?
  29.     IF pArray # NIL
  30.         // Yes, initialize...
  31.  
  32.         // Set the bar coordinates
  33.         nBarTop    := pArray[1] //nTop
  34.         nBarLeft   := pArray[2] //nLeft
  35.         nBarBottom := pArray[3] //nBottom
  36.         nBarRight  := pArray[4] //nRight
  37.         nBarWidth  := (nBarRight - nBarLeft) + 1
  38.  
  39.     ENDIF
  40.  
  41.     // default is to display the scroll bar
  42.     If lDisplay = NIL .or. lDisplay
  43.  
  44.         // Get number of keys in current index
  45.         nKeys    := Sx_KeyCount()
  46.  
  47.         // Calculate the number of keys to skip before moving "elevator"
  48.         If nKeys < (nBarBottom - nBarTop )
  49.            nKeyStep := INT((nBarBottom - nBarTop) / nKeys )
  50.         Else
  51.            nKeyStep := INT(nKeys / (nBarBottom - nBarTop))
  52.         Endif
  53.         nKeyStep := If(nKeyStep = 0 , 1 , nKeyStep)
  54.  
  55.        // Clear the scroll bar
  56.        For i = nBarTop to nBarBottom
  57.           @ i,nBarLeft SAY REPLICATE(Chr(176),nBarWidth) color clr4
  58.        Next
  59.  
  60.        // Draw the "elevator"
  61.        keyno := Sx_Keyno()
  62.        If keyno = 1
  63.           nPos := nBartop
  64.        Elseif keyno = nKeys
  65.           nPos := nBarBottom
  66.        Elseif nKeys < (nBarBottom - nBarTop )
  67.           nPos := MIN(nBarTop + ( (keyno - 1) * nKeyStep), nBarBottom)
  68.        Else
  69.           nPos := MIN(nBarTop + (  keyno / nKeyStep), nBarBottom)
  70.        Endif
  71.        @ nPos,nBarLeft SAY REPLICATE(chr(254),nBarWidth) Color clr4
  72.  
  73.     Endif
  74. RETURN aReturn
  75.