home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_progr.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  119 lines

  1. /*
  2.     File......: GT_Progress.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 15/03/93
  8.     Revision..: 1.0
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 15/03/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *       GT_PROGRESS()
  23.  *  $CATEGORY$
  24.  *       General
  25.  *  $ONELINER$
  26.  *       Display a progress bar and allow Esc option.
  27.  *  $SYNTAX$
  28.  *       GT_Progress(<nCounter>,<lSetup>, ;
  29.  *           <lAllowEsc>,<nMax>) -> lContinue
  30.  *  $ARGUMENTS$
  31.  *       <nCounter> is the value to base the bar on.
  32.  *       <lSetup> Initialise !
  33.  *       <lAllowEsc> Can User Press Esc ?
  34.  *       <nMax> Max value to close on.
  35.  *  $RETURNS$
  36.  *       lContinue
  37.  *  $DESCRIPTION$
  38.  *       Display a progress bar and allow Esc option.
  39.  *  $EXAMPLES$
  40.  *       // Setup allowing Esc
  41.  *       GT_Progress(NIL,.T.,.T.,LASTREC())
  42.  *
  43.  *       // Use it
  44.  *       DO WHILE GT_Progress(RECNO())
  45.  *           Update()
  46.  *       ENDDO
  47.  *  $END$
  48.  */
  49.  
  50. #include "GtClippe.ch"
  51.  
  52. FUNCTION GT_Progress(nCounter,lSetup,lAllowEsc,nMax)
  53.  
  54. STATIC cScreen := ''
  55. STATIC lStop := .F.
  56. STATIC nLeft := 02
  57. STATIC nMid := 0
  58. STATIC nWidth := 0
  59. STATIC nTotal := 0
  60.  
  61. LOCAL lContinue := .T.
  62.  
  63. Default nCounter to -1
  64. Default lSetup to .F.
  65. Default lAllowEsc to .F.
  66. Default nMax to 1
  67.  
  68. DO CASE
  69.     CASE nCounter == nTotal
  70.         // Complete
  71.         IF .NOT. EMPTY(cScreen)
  72.             RESTSCREEN(00,00,MAXROW(),MAXCOL(),cScreen)
  73.             cScreen := ''
  74.         ENDIF
  75.  
  76.     CASE nCounter >= 0
  77.         // Active
  78.         @ nMid,nLeft SAY REPLICATE('█', ;
  79.             INT(nCounter*nWidth))
  80.         IF lStop
  81.             IF INKEY() = K_ESC
  82.                 IF .NOT. EMPTY(cScreen)
  83.                     RESTSCREEN(00,00,MAXROW(),MAXCOL(),cScreen)
  84.                     cScreen := ''
  85.                 ENDIF
  86.                 lContinue := .F.
  87.             ENDIF
  88.         ENDIF
  89.  
  90.     CASE lSetup
  91.         // Setup
  92.         nMid := INT(MAXROW()/2) - 01
  93.         lStop := lAllowEsc
  94.         nTotal := nMax
  95.         cScreen := SAVESCREEN(00,00,MAXROW(),MAXCOL())
  96.  
  97.         GT_Window(nMid-01,nLeft-01,nMid+02,MAXCOL()-02, ;
  98.             BOX_SS,SETCOLOR(),IF(lAllowEsc,'Esc∙Stop', ;
  99.             'Working:'))
  100.  
  101.         // Use middle row
  102.         nWidth := MAXCOL() - 05
  103.         @ nMid+01, nLeft SAY REPLICATE('.',nWidth)
  104.         @ nMid+01, nLeft SAY '0'
  105.         @ nMid+01, MAXCOL() - 05 SAY '100'
  106.         @ nMid+01, nLeft + (nWidth/2) - 01 SAY '50'
  107.         nWidth /= nMax
  108.  
  109.     OTHERWISE
  110.  
  111. ENDCASE
  112.  
  113. /*
  114.     End of GT_Progress()
  115. */
  116. RETURN(lContinue)
  117.  
  118.  
  119.