home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / SCREGION.PRG < prev    next >
Text File  |  1991-08-16  |  9KB  |  226 lines

  1. /*
  2.  * File......: SCREGION.PRG
  3.  * Author....: David A. Richardson
  4.  * Date......: $Date:   15 Aug 1991 23:05:46  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/scregion.prv  $
  7.  * 
  8.  * This is an original work by David A. Richardson and is hereby placed
  9.  * in the public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/scregion.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:05:46   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:52:56   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:02:14   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_SAVRGN()
  31.  *  $CATEGORY$
  32.  *     Video
  33.  *  $ONELINER$
  34.  *     Save a screen region for later display
  35.  *  $SYNTAX$
  36.  *     FT_SAVRGN( <nTop>, <nLeft>, <nBottom>, <nRight> ) -> cScreen
  37.  *  $ARGUMENTS$
  38.  *     <nTop>, <nLeft>, <nBottom>, and <nRight> define the portion of the
  39.  *     screen to save.  Allowable values are 0 through 255.
  40.  *  $RETURNS$
  41.  *     FT_SAVRGN() returns the saved screen region and its coordinates
  42.  *     as a character string. 
  43.  *  $DESCRIPTION$
  44.  *     FT_SAVRGN() is similar to Clipper's SAVESCREEN(), but it saves the
  45.  *     screen coordinates as well as the display information.  The saved
  46.  *     area can be restored by passing the returned string to FT_RSTRGN().
  47.  *
  48.  *     Note that the strings returned from FT_SAVRGN() and Clipper's
  49.  *     SAVESCREEN() are not interchangeable.  A screen region saved with 
  50.  *     with FT_SAVRGN() must be restored using FT_RSTRGN().
  51.  *
  52.  *     FT_SAVRGN() calls Clipper's SAVESCREEN().  Refer to the Clipper
  53.  *     documentation for more information regarding this function.
  54.  *  $EXAMPLES$
  55.  *     The following example uses FT_SAVRGN() and FT_RSTRGN() to save
  56.  *     and restore a portion of the screen.
  57.  *
  58.  *     @ 00, 00, 24, 79 BOX "111111111"       // fill the screen with 1's
  59.  *     cScreen = FT_SAVRGN(10, 10, 20, 30)    // save a region
  60.  *     @ 00, 00, 24, 79 BOX "222222222"       // fill the screen with 2's
  61.  *     FT_RSTRGN(cScreen)                     // restore the 1's region
  62.  *  $SEEALSO$
  63.  *     FT_RSTRGN() FT_RGNSTACK()
  64.  *  $END$
  65.  */
  66.  
  67. FUNCTION FT_SAVRGN(nTop, nLeft, nBottom, nRight)
  68.  
  69.    RETURN (CHR(nTop) + CHR(nLeft) + CHR(nBottom) + CHR(nRight) + ;
  70.       SAVESCREEN(nTop, nLeft, nBottom, nRight))
  71.  
  72.  
  73. /*  $DOC$
  74.  *  $FUNCNAME$
  75.  *     FT_RSTRGN()
  76.  *  $CATEGORY$
  77.  *     Video
  78.  *  $ONELINER$
  79.  *     Restore region of the screen saved with FT_SAVRGN()
  80.  *  $SYNTAX$
  81.  *     FT_RSTRGN( <cScreen>, [ <nTop> ], [ <nLeft> ] ) -> NIL
  82.  *  $ARGUMENTS$
  83.  *     <cScreen> is a screen region previously returned from FT_SAVRGN().
  84.  *
  85.  *     <nTop> and <nLeft> are optional parameters that define a new location 
  86.  *     for the upper left corner of the screen area contained in <cScreen>.
  87.  *     Allowable values are 0 through 255.
  88.  *  $RETURNS$
  89.  *     FT_RSTRGN() returns NIL.
  90.  *  $DESCRIPTION$
  91.  *     FT_RSTRGN() restores a screen region previously saved with
  92.  *     FT_SAVRGN().  Calling FT_RSTRGN() with <cScreen> as the only
  93.  *     parameter will restore the saved region to its original location. 
  94.  *     <nTop> and <nLeft> may be used to define a new location for the 
  95.  *     upper left corner of the saved region.  
  96.  *
  97.  *     <nTop> and <nLeft> are dependent upon each other. You may not
  98.  *     specify one without the other. 
  99.  *
  100.  *     FT_RSTRGN() calls Clipper's RESTSCREEN().  Refer to the Clipper
  101.  *     documentation for more information regarding this function. 
  102.  *  $EXAMPLES$
  103.  *     The following example uses FT_RSTRGN() to restore a saved portion
  104.  *     of the screen to different locations.
  105.  *
  106.  *     @ 00, 00, 24, 79 BOX "111111111"      // fill the screen with 1's
  107.  *     cScreen = FT_SAVRGN(10, 10, 20, 30)   // save a region
  108.  *     @ 00, 00, 24, 79 BOX "222222222"      // fill the screen with 2's
  109.  *     FT_RSTRGN(cScreen)                    // restore the 1's region
  110.  *     @ 00, 00, 24, 79 BOX "222222222"      // fill the screen with 2's
  111.  *     FT_RSTRGN(cScreen, 15, 15)            // restore to a different location
  112.  *     @ 00, 00, 24, 79 BOX "222222222"      // fill the screen with 2's
  113.  *     FT_RSTRGN(cScreen, 20, 60)            // restore to a different location
  114.  *  $SEEALSO$
  115.  *     FT_SAVRGN() FT_RGNSTACK()
  116.  *  $END$
  117.  */
  118.  
  119. FUNCTION FT_RSTRGN(cScreen, nTop, nLeft)
  120.  
  121.    IF PCOUNT() == 3
  122.       RESTSCREEN(nTop, nLeft, (nTop - ASC(cScreen)) + ASC(SUBSTR(cScreen, 3)), ;
  123.          (nLeft - ASC(SUBSTR(cScreen, 2))) + ASC(SUBSTR(cScreen, 4)), ;
  124.          SUBSTR(cScreen, 5))
  125.    ELSE
  126.       RESTSCREEN(ASC(cScreen), ASC(SUBSTR(cScreen, 2)), ASC(SUBSTR(cScreen, 3)), ;
  127.          ASC(SUBSTR(cScreen, 4)), SUBSTR(cScreen, 5))
  128.    ENDIF
  129.  
  130.    RETURN NIL
  131.  
  132.  
  133. /*  $DOC$
  134.  *  $FUNCNAME$
  135.  *     FT_RGNSTACK()
  136.  *  $CATEGORY$
  137.  *     Video
  138.  *  $ONELINER$
  139.  *     Push or pop a saved screen region on or off the stack
  140.  *  $SYNTAX$
  141.  *     FT_RGNSTACK( <cAction>, [ <nTop> ], [ <nLeft> ], [ <nBottom> ],
  142.  *        [ <nRight> ] ) -> NIL
  143.  *  $ARGUMENTS$
  144.  *     <cAction> determines what action FT_RGNSTACK() will take.  The
  145.  *     allowable values for this parameter are "push", "pop", and "pop all".
  146.  *     If the function is called with any other string as the first parameter
  147.  *     no action is performed. 
  148.  *
  149.  *     <cAction> with a value of "push" will push a saved screen region onto
  150.  *     the stack.  A value of "pop" will restore the most recently pushed
  151.  *     screen region.  "pop all" tells the function to restore all screen 
  152.  *     images which are currently on the stack. 
  153.  *  
  154.  *     The use of <nTop>, <nLeft>, <nBottom>, and <nRight> depends on the
  155.  *     <cAction> parameter.  If <cAction> is "push", the next four parameters
  156.  *     define the screen region to save.  If <cAction> is "pop" or "pop all" 
  157.  *     the following four parameters are ignored.
  158.  *  $RETURNS$
  159.  *     FT_RGNSTACK() returns NIL.
  160.  *  $DESCRIPTION$
  161.  *     FT_RGNSTACK() allows multiple screens to be saved and restored from
  162.  *     a stack.  The stack is implemented with Clipper static array that is
  163.  *     visible only to FT_RGNSTACK().
  164.  *
  165.  *     The purpose of FT_RGNSTACK() is to allow multiple screen regions to be
  166.  *     managed without the need to remember the original coordinates or to 
  167.  *     create variables for each one. 
  168.  *
  169.  *     When called with "push", FT_RGNSTACK() places the saved screen area
  170.  *     at the end of the static array.  The array size is incremented by one
  171.  *     to accommodate the new screen area.
  172.  *
  173.  *     When called with "pop", the function restores the screen image stored
  174.  *     in the last element of the array, and the array size is decremented by
  175.  *     one.  If "pop all" is specified, all the saved screens are restored
  176.  *     until the array is empty.
  177.  *
  178.  *     FT_RGNSTACK() calls FT_SAVRGN() and FT_RSTRGN().  Refer to the
  179.  *     documentation for these two functions for more information. 
  180.  *  $EXAMPLES$
  181.  *     The following example uses FT_RGNSTACK() to save and restore various
  182.  *     sections of the screen. 
  183.  *
  184.  *     @ 00, 00, 24, 79 BOX "111111111"         // fill the screen with 1's
  185.  *     FT_RGNSTACK("push", 10, 05, 15, 15)      // push a region
  186.  *     @ 00, 00, 24, 79 BOX "222222222"         // fill the screen with 2's
  187.  *     FT_RGNSTACK("push", 10, 20, 15, 30)      // push a region
  188.  *     @ 00, 00, 24, 79 BOX "333333333"         // fill the screen with 3's
  189.  *     FT_RGNSTACK("push", 10, 35, 15, 45)      // push a region
  190.  *     @ 00, 00, 24, 79 BOX "444444444"         // fill the screen with 4's
  191.  *     FT_RGNSTACK("push", 10, 50, 15, 60)      // push a region
  192.  *     @ 00, 00, 24, 79 BOX "555555555"         // fill the screen with 5's
  193.  *     FT_RGNSTACK("push", 10, 65, 15, 75)      // push a region
  194.  *     CLEAR
  195.  *     FT_RGNSTACK("pop")        // restore the 5's region
  196.  *     FT_RGNSTACK("pop")        // restore the 4's region
  197.  *     FT_RGNSTACK("pop all")    // restore the 3's, 2's and 1's regions
  198.  *  $SEEALSO$
  199.  *     FT_SAVRGN() FT_RSTRGN()
  200.  *  $END$
  201.  */
  202.  
  203. FUNCTION FT_RGNSTACK(cAction, nTop, nLeft, nBottom, nRight)
  204.  
  205.    STATIC aRgnStack_[0], nStackPtr := 0
  206.    LOCAL nPopTop
  207.  
  208.    IF cAction == "push"
  209.  
  210.       ASIZE(aRgnStack_, ++nStackPtr)[nStackPtr] = ;
  211.          FT_SAVRGN(nTop, nLeft, nBottom, nRight)
  212.  
  213.    ELSEIF cAction == "pop" .OR. cAction = "pop all"
  214.  
  215.       nPopTop = IIF("all" $ cAction, 0, nStackPtr-1)
  216.  
  217.       DO WHILE nStackPtr > nPopTop
  218.          FT_RSTRGN(aRgnStack_[nStackPtr--])
  219.       ENDDO
  220.  
  221.       ASIZE(aRgnStack_, nStackPtr)
  222.  
  223.    ENDIF
  224.  
  225.    RETURN NIL
  226.