home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP13.EXE / CHP1313.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  5.3 KB  |  180 lines

  1. /*
  2.    Listing 13.13  Clipper 5 Color Management System
  3.    NOTE: This program makes external calls to:
  4.           RESTARRAY()   contained in CHP0917.PRG
  5.           SAVEARRAY()   contained in CHP0919.PRG
  6.           SAVEENV()     contained in CHP1201.PRG
  7.           RESTENV()     contained in CHP1202.PRG
  8.    Author: Greg Lief
  9.    Excerpted from "Clipper 5: A Developer's Guide"
  10.    Copyright (c) 1991 M&T Books
  11.                       501 Galveston Drive
  12.                       Redwood City, CA 94063-4728
  13.                       (415) 366-3600
  14. */
  15.  
  16. //───── NOTE: must compile with the /N option!
  17.  
  18. #include "box.ch"
  19. #include "inkey.ch"
  20. #include "colors.ch"
  21.  
  22. /* default name for color configuration file - change if you want */
  23. #define  CFG_FILE     "colors.cfg"
  24.  
  25. /* convert logical to numeric: 1 if by land (.T.), 2 if by sea (.F.) */
  26. #translate Logic2Num( <a> ) => ( if( <a>, 1, 2) )
  27.  
  28. static iscolor          /* global flag for color (1) or mono (2)  */
  29.  
  30. /* the following array contains color and monochrome settings for each
  31.    type of color.  The third array describes the color it applies to,
  32.    which makes it completely self-documenting.  This third element is
  33.    also used during the ColorMod() routine to identify each color.
  34. */
  35. static colors := {  { "W/B",   "W/N" , "Normal"   }, ;
  36.                     { "+W/B",  "+W/N", "Bold"     }, ;
  37.                     { "+GR/B", "+W/N", "Enhanced" }, ;
  38.                     { "*W/B",  "*W/N", "Blinking" }, ;
  39.                     { "+W/RB", "N/W" , "Messages" }, ;
  40.                     { "+W/R",  "N/W" , "Warnings" }  }
  41.  
  42.  
  43.  
  44. #define TESTING
  45.  
  46. #ifdef TESTING            // stub program begins here
  47.  
  48. function main
  49. local oldcolor
  50. do case
  51.    case file(CFG_FILE)
  52.       ColorInit(CFG_FILE)
  53.    /* verify that this is REALLY a color system */
  54.    case iscolor()
  55.       qout("Press C for color monitor, any other key for monochrome")
  56.       /* this looks nuts, but works perfectly -- can you see why? */
  57.       ColorInit( chr(inkey(0)) $ "cC" )
  58.    otherwise
  59.       ColorInit()
  60. endcase
  61. oldcolor := ColorSet(C_NORMAL)
  62. cls
  63. ColorSet(C_BOLD)
  64. @ 11, 24, 13, 55 box "┌─┐│┘─└│ "
  65. ColorSet(C_ENHANCED)
  66. @ 12, 26 say "Welcome to the Brownout Zone"
  67. inkey(3)
  68. ColorMod()
  69. ColorSet(C_BLINK)
  70. @ 12, 26 say "Hope you enjoyed your visit!"
  71. inkey(3)
  72. setcolor(oldcolor)
  73. cls
  74. return nil
  75.  
  76. #endif // stub program ends here... main functions begin
  77.  
  78.  
  79. /*
  80.     ColorInit(): initializes color management system
  81.                  to either color or monochrome, or
  82.                  load previously saved color settings
  83. */
  84. function colorinit(override)
  85. local temparray
  86. do case
  87.    case override == NIL
  88.       iscolor := logic2num(iscolor())
  89.    case valtype(override) == 'L'
  90.       iscolor := logic2num(override)
  91.    otherwise
  92.       if file(override)
  93.          if len( temparray := restarray(override) ) = 0
  94.             qout("Could not load colors from " + override)
  95.             inkey(0)
  96.          else
  97.             colors := temparray
  98.          endif
  99.          iscolor := logic2num( iscolor() )
  100.       endif
  101. endcase
  102. return NIL
  103.  
  104. * end function ColorInit()
  105. *---------------------------------------------------------------*
  106.  
  107. /*
  108.     ColorSet(): changes color in accordance with
  109.                 internal settings stored in array
  110. */
  111. function ColorSet(colornum, newcolor)
  112. /* modify color setting if second parameter was passed */
  113. if newcolor != NIL
  114.    colors[colornum, iscolor] := newcolor
  115. endif
  116. return setcolor(colors[colornum, iscolor])
  117.  
  118. * end function ColorSet()
  119. *---------------------------------------------------------------*
  120.  
  121. /*
  122.    ColorMod() - View/Modify all global color settings
  123. */
  124. function ColorMod()
  125. local key := 0, newcolor, ntop, xx, getlist := {}, colorfile, ;
  126.       oldscore := set(_SET_SCOREBOARD, .f.)  // shut off scoreboard
  127. SaveEnv(.t.)         // save entire screen for later restoration
  128. ColorSet(C_NORMAL)
  129. ntop = ( maxrow() - COLOR_CNT ) / 2
  130. @ ntop, 22, ntop + COLOR_CNT + 1, 57 box B_SINGLE + ' '
  131. setpos(ntop, 0)
  132. /* pad each color setting to 8 characters for data entry */
  133. aeval(colors,{ |a,b| colors[b, iscolor] := padr(colors[b, iscolor], 8) } )
  134. for xx = 1 to COLOR_CNT
  135.    @ row() + 1, 24 say colors[xx, 3] + " Color"
  136.    ColorSet(xx)
  137.    @ row(), 42 say "SAMPLE" get colors[xx, iscolor] valid redraw(ntop)
  138.    ColorSet(C_NORMAL)
  139. next
  140. read
  141.  
  142. /* trim each color setting */
  143. aeval(colors,{ |a,b| colors[b, iscolor] := trim(colors[b, iscolor]) } )
  144. setpos(ntop + COLOR_CNT + 1, 24)
  145. dispout("Press F10 to save these settings")
  146. if inkey(0) == K_F10
  147.    colorfile := padr(CFG_FILE, 12)
  148.    ColorSet(C_MESSAGE)
  149.    @ 11, 18, 13, 61 box B_DOUBLE + ' '
  150.    @ 12, 20 say "Enter file name to save to:"
  151.    @ 12, 48 get colorfile picture '@!'
  152.    setcursor(1)
  153.    read
  154.    setcursor(0)
  155.    if lastkey() != K_ESC .and. ! empty(colorfile)
  156.       savearray(colors, ltrim(trim(colorfile)))
  157.    endif
  158. endif
  159. RestEnv()
  160. set(_SET_SCOREBOARD, oldscore)
  161. return NIL
  162.  
  163. * end function ColorMod()
  164. *---------------------------------------------------------------*
  165.  
  166.  
  167. /*
  168.    Redraw() - redraw color samples after each GET
  169. */
  170. static function redraw(ntop)
  171. local oldcolor := ColorSet(row() - ntop)
  172. @ row(), 42 say "SAMPLE"
  173. setcolor(oldcolor)
  174. return .t.
  175.  
  176. * end static function Redraw()
  177. *--------------------------------------------------------------------*
  178.  
  179. // end of file CHP1313.PRG
  180.