home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / SAVEENV.PRG < prev    next >
Encoding:
Text File  |  1991-05-07  |  3.8 KB  |  117 lines

  1. /*
  2.  
  3.    Program: SAVEENV.PRG
  4.    System: GRUMPFISH LIBRARY
  5.    Author: Greg Lief
  6.    Copyright (c) 1988-90, Greg Lief
  7.    Clipper 5.x version
  8.    Compile instructions: clipper saveenv /n/w/a
  9.  
  10.    Functions: GFSaveEnv(), GFRestEnv()
  11.    Save and restore basic environment items (cursor size & position,
  12.    color, screen contents)
  13.  
  14. */
  15.  
  16. //───── begin global declarations
  17.  
  18. #include "grump.ch"
  19.  
  20. #define TOP      coords[1]
  21. #define LEFT     coords[2]
  22. #define BOTTOM   coords[3]
  23. #define RIGHT    coords[4]
  24.  
  25. #define NTOP     envstack_[ele, SCREEN][1]
  26. #define NLEFT    envstack_[ele, SCREEN][2]
  27. #define NBOTTOM  envstack_[ele, SCREEN][3]
  28. #define NRIGHT   envstack_[ele, SCREEN][4]
  29. #define NSCREEN  envstack_[ele, SCREEN][5]
  30.  
  31. #define ROW     1
  32. #define COLUMN  2
  33. #define CURSOR  3
  34. #define COLOR   4
  35. #define SCREEN  5
  36.  
  37. static envstack_ := {}       // environmental stack
  38.  
  39. //───── end global declarations
  40.  
  41. /*
  42.     Function:   GFSaveEnv()
  43.     Purpose:    Save current cursor row/column/size, color, and screen
  44.     Syntax:     GFSaveEnv( <coords>, <cursorsize>, <color> )
  45.                 All parameters are optional
  46.     Parameters: <coords> can be one of three things:
  47.                          NIL -- do not save the screen
  48.                          Array -- four numeric expressions representing
  49.                                   the screen coordinates to be saved
  50.                          Other -- save the entire screen
  51.  
  52.                 <cursorsize> is a numeric representing the new cursor
  53.                 size to use.  If not passed, the cursor size will be
  54.                 left unchanged. Please refer to SETCURS.CH for the
  55.                 appropriate definitions. Use a comma if you want to
  56.                 skip this parameter.
  57.  
  58.                 <color> is a character string representing the new color
  59.                 setting to use. If not passed, the color will be left
  60.                 unchanged.
  61.  
  62.     Examples:   #include "setcurs.ch"
  63.                 gfsaveenv(, SC_NONE, 'w/b')
  64.  
  65.              Do not save screen, turn off cursor, change color to W/B
  66.  
  67.                 gfsaveenv(.t., , 'r/w')
  68.  
  69.              Save full screen, don't change cursor, change color to R/W
  70.  
  71.                 gfsaveenv( { 10, 10, 14, 69 }, SC_NONE)
  72.  
  73.              Save screen buffer between @ 10, 10 and @ 14, 69, turn off
  74.              cursor, leave color unchanged.
  75. */
  76. function GFSaveEnv(scrn_save, curs_size, newcolor)
  77. local coords := if(scrn_save == NIL .or. valtype(scrn_save) == "A", ;
  78.                 scrn_save, { 0, 0, maxrow(), maxcol() } )
  79. aadd(envstack_, { row(), col(), setcursor(curs_size), setcolor(newcolor), ;
  80.      if(valtype(coords) == "A", { TOP, LEFT, BOTTOM, RIGHT, ;
  81.         savescreen(TOP, LEFT, BOTTOM, RIGHT) }, NIL) } )
  82. return len(envstack_)
  83.  
  84. * end function GFSaveEnv()
  85. *--------------------------------------------------------------------*
  86.  
  87.  
  88. /*
  89.        GFRestEnv(): restore previous environmental settings
  90. */
  91. function GFRestEnv(ele)
  92. //───── use LIFO (last item in array) if no parameter was passed
  93. default ele to len(envstack_)
  94. //───── preclude empty array!
  95. if len(envstack_) > 0 .and. ele <= len(envstack_)
  96.    //───── reset row/column position
  97.    setpos(envstack_[ele, ROW], envstack_[ele, COLUMN])
  98.    //───── reset cursor state
  99.    setcursor(envstack_[ele, CURSOR])
  100.    //───── reset color
  101.    setcolor(envstack_[ele, COLOR])
  102.    //───── restore screen if it was saved
  103.    if envstack_[ele, SCREEN] != NIL
  104.       restscreen(NTOP, NLEFT, NBOTTOM, NRIGHT, NSCREEN)
  105.    endif
  106.    //───── truncate length of array only if using LIFO, i.e., no param passed
  107.    if ele == len(envstack_) .and. pcount() == 0
  108.       truncate(envstack_)
  109.    endif
  110. endif
  111. return NIL
  112.  
  113. * end function GFRestEnv()
  114. *--------------------------------------------------------------------*
  115.  
  116. * eof saveenv.prg
  117.