home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / CLIPPER / SYSWIN / SYSWIN.PRG < prev    next >
Text File  |  1992-05-16  |  9KB  |  188 lines

  1. /**************************************************************************
  2. **  SYSWIN.PRG          CLIPPER VERSION 5.0   Save & Restore Screen funcs**
  3. **            Functions which save and restore screen & color attributes **
  4. **     based upon a static array stack.  These are replacement functions **
  5. **     for those located in FUNCS.CH header file.                        **
  6. **     Copyright notice:                                                 **
  7. **     Copyright (c) 1992, Roderick Jay Cushman.  All rights reserved.   **
  8. **     ----------------------------------------------------------------- **
  9. **              You may use these functions freely so long as this and   **
  10. **      the function headers remain intact.  You may use these functions **
  11. **      as part of your applications so long as the functions in this    **
  12. **      file are not sold for profit.                                    **
  13. **                              Author        : Rod Cushman              **
  14. **                              Revision Date : 05/16/92 00:02am         **
  15. **************************************************************************/
  16.  
  17. #include "BOX.CH"                     && Includes constants, functions, ...
  18.  
  19.  
  20. #xcommand DEFAULT <foo> to <bar> => ;
  21.                   If( <foo> == NIL, <foo> := <bar>, NIL )
  22.  
  23.       /* Array is necessary for operation of Sav_SWIN2() and Rst_Swin2() */
  24. static Scr_Stack := {}
  25.  
  26.  
  27. #define SCR_TOP         1      /** Scr_Stack{} Top Row      index **/
  28. #define SCR_LFT         2      /** Scr_Stack{} Left Column  index **/
  29. #define SCR_BOT         3      /** Scr_Stack{} Bottom Row   index **/
  30. #define SCR_RIT         4      /** Scr_Stack{} Right Column index **/
  31. #define SCR_COLOR       5      /** Scr_Stack{} Color        index **/
  32. #define SCR_SCREEN      6      /** Scr_Stack{} Screen Str   index **/
  33. #define SCR_LSHADE      7      /** Scr_Stack{} Shaded Scr?  index **/
  34.  
  35.  
  36. /**************************************************************************
  37. **     Creates a shaded window, save the color and screen onto the screen**
  38. **     stack prior to creating box.  The color is set to cColor value.   **
  39. **     Call with the following parameters:                               **
  40. **           nTop       :  Top Row of the box.                           **
  41. **           nLft       :  Left column of the box.                       **
  42. **           nBot       :  Bottom Row of the box.                        **
  43. **           nRit       :  Right column of the box.                      **
  44. **           cColor     :  Color which to display box in.                **
  45. **           lShade     :  Logical: Shaded box ? Defaults to Yes.        **
  46. **                                                                       **
  47. **     copyright (c) 1992, Roderick Jay Cushman.  All Rights reserved.   **
  48. **                              Author        : Rod Cushman              **
  49. **                              Revision Date : 05/15/92 07:58pm         **
  50. **************************************************************************/
  51. Function SAV_SWIN2( nTop, nLft, nBot, nRit, cColor, lShade )
  52.   Local sWin, oColor
  53.  
  54.   DEFAULT cColor to SetColor()
  55.   DEFAULT lShade to .t.
  56.   oColor := SetColor( cColor )
  57.   If lShade
  58.     sWin   := Savescreen(nTop, nLft, nBot+1, nRit+2)
  59.     RestScreen( nTop+1,nLft+2,nBot+1,nRit+2,                              ;
  60.       Transform( SaveScreen( nTop+1,nLft+2,nBot+1,nRit+2 ),               ;
  61.            Replicate( 'X'    , ( nBot-nTop+1 )*( nRit-nLft+1 ) ) ) )
  62. *          Replicate( Chr(177), ( nBot-nTop+1 )*( nRit-nLft+1) ) ) )
  63.   Else
  64.     sWin   := Savescreen(nTop, nLft, nBot, nRit)
  65.   EndIf
  66.   __BoxD( nTop, nLft, nBot, nRit )
  67.   __ATClear( nTop+1, nLft+1, nBot-1, nRit-1 )
  68.  
  69.   Aadd( Scr_Stack, { nTop, nLft, nBot, nRit, oColor, sWin, lShade } )
  70. Return( Len(Scr_Stack) )
  71.  
  72.  
  73. /**************************************************************************
  74. **     Restores screen & color information saved onto the Screen Stack   **
  75. **     via the SAV_SWIN2() function.  Functions restores the last window **
  76. **     saved via a call to SAV_SWIN2().  Color is also restored from the **
  77. **     last call to SAV_SWIN2().                                         ** 
  78. **     copyright (c) 1992, Roderick Jay Cushman.  All Rights reserved.   **
  79. **                              Author        : Rod Cushman              **
  80. **                              Revision Date : 05/08/92 01:00pm         **
  81. **************************************************************************/
  82. Function RST_SWIN2( )
  83.   Local cColor := "", anXY := {}
  84.  
  85.  
  86.   Local ele := Len( Scr_Stack )
  87.   If ele > 0               /* Ensure elements exist in Environment Stack */
  88.                                                           /* Reset Color */
  89.     DispBegin()
  90.     cColor       := SetColor( Scr_Stack[ ele, SCR_COLOR] )
  91.  
  92.  
  93.                       /* Restore Screen if one was stored in SAV_SWIN2() */
  94.     If Scr_Stack[ele, SCR_LSHADE]              // Was Shaded region saved ?
  95.       RestScreen(Scr_Stack[ele, SCR_TOP]  , Scr_Stack[ele, SCR_LFT]  ,      ;
  96.                  Scr_Stack[ele, SCR_BOT]+1, Scr_Stack[ele, SCR_RIT]+2,      ;
  97.                                             Scr_Stack[ele, SCR_SCREEN] )
  98.     Else
  99.       RestScreen(Scr_Stack[ele, SCR_TOP], Scr_Stack[ele, SCR_LFT],        ;
  100.                  Scr_Stack[ele, SCR_BOT], Scr_Stack[ele, SCR_RIT],        ;
  101.                                           Scr_Stack[ele, SCR_SCREEN] )
  102.     EndIf
  103.     DispEnd()
  104.  
  105.     anXY := ASize( Aclone(Scr_Stack[ele]), 4)      /* Screen coordinates */
  106.  
  107.     Asize( Scr_Stack, ele - 1)          /* Decrease stack by one element */
  108.  
  109.                                      /* Return lSuccess := .t., settings */ 
  110.     Return({ .t., cColor, anXY } )
  111.   Endif
  112. Return({ .f., cColor, anXY } )
  113.  
  114.  
  115. /****================ MISCELLANEOUS FUNCTIONS ========================****/
  116.  
  117.  
  118.  
  119. /**************************************************************************
  120. ** Clears the area of the screen: ntop,nleft -> nbot,nright Color cColor **
  121. **************************************************************************/
  122. Function CLR_WIN
  123.   Parameters nTop, nLeft, nBot, nRight, cColor, cBorder
  124.   Local cOColor
  125.  
  126.   DEFAULT cColor  TO SetColor()
  127.   DEFAULT cBorder TO B_DOUBLE + Space(1)                && Relies on box.ch
  128.  
  129.   DispBegin()
  130.   tColor := SetColor()
  131.   Set Color to                                    && Reset color to default
  132.   SetColor( cColor )
  133.   @ nTop,nLeft,nBot,nRight Box cBorder
  134.   DispEnd()
  135. Return(cOColor)
  136.  
  137.  
  138. /**************************************************************************
  139. ** Function DispWin                                                      **
  140. **      clear window area and draw box for window                        **
  141. **************************************************************************/
  142. Function DispWin
  143.   Parameters nT,nL,nB,nR, cColor               /* top row, bot. row, etc */
  144.  
  145.   DEFAULT cColor TO SetColor()
  146.  
  147.   SetColor( cColor )
  148.   DispBegin()
  149. * @ nT,nL CLEAR TO nB,nR
  150.   @ nT,nL,nB,nR BOX B_DOUBLE_SINGLE+Space(1) Color cColor  && Relies on box.ch
  151.   DispEnd()
  152. Return  NIL
  153.  
  154.  
  155. /**************************************************************************
  156. **      The following function is part of Steve Straley's TooLkiT (tm)   **
  157. **      - Release 2, published by Four Seasons Publishing Co., Inc.  All **
  158. **      Rights Reserved.  Information: 212-599-2141 / 800-662-2278.  All **
  159. **      Rights Reserved.                                                 **
  160. **              This function takes a screen string and returns it with  **
  161. **      the attribute byte dulled.                                       **
  162. **************************************************************************/
  163. Function SCR_DULLING( cStr )
  164.   Local tStr := "", i := 1
  165.   
  166.   For i := 1 to Len( cStr ) Step 2
  167.     tStr += SubStr( cStr, i, 1) + Chr(8)
  168.   Next i
  169. Return( t_str )
  170.  
  171.  
  172. /**************************************************************************
  173. **      Function returns the screen display as a string, including line- **
  174. **      feeds, minus the attribute byte.  Parameters specify coordinates **
  175. **      to be parsed.                                                    **
  176. **************************************************************************/
  177. Function SCR_TO_TXT( nTop, nLft, nBot, nRit )
  178.   Local RetStr := "", tStr := "", i := 1, tRow := 0, tCol :=0
  179.   
  180.   tStr := SaveScreen( nTop, nLft, nBot, nRit )
  181.   For tRow := 1 to nBot - nTop + 1
  182.     For tCol := 1 to nRit - nLft + 1 Step 2
  183.       RetStr += SubStr( cStr, i, 1)
  184.     Next tCol
  185.     RetStr += Chr(13)                && Place Carriage Return at end of row
  186.   Next tRow
  187. Return( RetStr )
  188.