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

  1. /*
  2.      Program: COLORSET()
  3.      System: GRUMPFISH LIBRARY
  4.      Author: Greg Lief
  5.      Copyright (c) 1988-90, Greg Lief
  6.      Clipper 5.x Version
  7.      Compile instructions: clipper colorset /n/w/a
  8.      Complete color management for the Grumpfish Library.
  9. */
  10.  
  11. //───── begin preprocessor directives
  12.  
  13. #include "grump.ch"
  14. #include "inkey.ch"
  15. #define COLOR_CNT   34         /* total number of colors in array */
  16.  
  17. //───── end preprocessor directives
  18.  
  19. //───── begin global declarations
  20.  
  21. static gfcolors := { { "+W/N",   "N/W",   "Current Entry Fields" }     , ;
  22.                      { "+W/BR",  "N/W",   "Message Boxes" }            , ;
  23.                      { "+W*/BR", "*N/W",  "Blinking Messages" }        , ;
  24.                      { "+GR/N",  "+W/N",  "Wait Messages" }            , ;
  25.                      { "+GR*/N", "+W*/N", "Blinking Wait Messages" }   , ;
  26.                      { "+W/BR",  "+W/N",  "Yes/No Messages" }          , ;
  27.                      { "W/R",    "N/W",   "Error Box Outline" }        , ;
  28.                      { "+W/R",   "N/W",   "Error Messages" }           , ;
  29.                      { "+W/R",   "W/N",   "Memoedit Window Outline " } , ;
  30.                      { "+W/N",   "+W/N",  "Memoedit Window Interior" } , ;
  31.                      { "W/B",    "W/N",   "Stopwatch Box" }            , ;
  32.                      { "+W/N",   "N/W",   "Stopwatch Window " }        , ;
  33.                      { "W/BR",   "W/N",   "Calculator Box" }           , ;
  34.                      { "+W/N",   "N/W",   "Calculator Window " }       , ;
  35.                      { "+W/B",   "W/N",   "Notepad Box" }              , ;
  36.                      { "+W/N",   "W/N",   "Notepad Window " }          , ;
  37.                      { "+W/R",   "W/N",   "Phonebook Main Window" }    , ;
  38.                      { "+W/B",   "W/N",   "Phonebook Edit Window" }    , ;
  39.                      { "W/B",    "W/N",   "Calendar Window" }          , ;
  40.                      { "+W/BG",  "+W/N",  "Appointment Window" }       , ;
  41.                      { "+W/B",   "+W/N",  "Picklist Box Outline" }     , ;
  42.                      { "W/N",    "W/N",   "Picklist Status Bar" }      , ;
  43.                      { "+GR/N",  "N/W",   "Picklist Indicator " }      , ;
  44.                      { "W/B",    "W/N",   "Picklist Unselected Items" }, ;
  45.                      { "N/W",    "N/W",   "Picklist Highlighted Item" }, ;
  46.                      { "+GR/B",  "+W/N",  "Picklist Tagged Items" }    , ;
  47.                      { "+W/R",   "N/W",   "Picklist Tagged/Current" }  , ;
  48.                      { "R/B",    "+W/N",  "Picklist Unavailable Items" }   , ;
  49.                      { "N/B",    "N/W",   "Picklist Unavailable/Current" } , ;
  50.                      { "W/B",    "W/N",   "Unselected Menu Options " } , ;
  51.                      { "+GR/R",  "N/W",   "Selected Menu Options" }    , ;
  52.                      { "W/B",    "W/N",   "DataBrowse Box" }           , ;
  53.                      { "+W/B",   "+W/N",  "DataBrowse Text" }          , ;
  54.                      { "+W/N",   "N/W",   "DataBrowse Highlight" } }
  55.  
  56. static iscolor := .T.      // global flag to indicate color vs. mono
  57. static colorfile := "COLORS.GF" // default filename for color configuration
  58.  
  59. //───── end global declarations
  60.  
  61. function ColorSet(mcolor, newcolor)
  62. local ret_val
  63. //───── if parameter was a character string, that means they are processing
  64. //───── an "on-the-fly" color rather than one out of the static array
  65. if valtype(mcolor) == "C"
  66.    ret_val := setcolor(mcolor)
  67. else
  68.    do case
  69.       //───── set color to the default
  70.       //───── return the current setting
  71.       case newcolor == NIL
  72.          ret_val := setcolor(gfcolors[mcolor][IF(iscolor, 1, 2)])
  73.       //───── change this color setting to the color string you just passed
  74.       //───── return the current setting
  75.       case valtype(newcolor) == "C"
  76.          ret_val := setcolor(gfcolors[mcolor][IF(iscolor, 1, 2)] := newcolor)
  77.       //───── do not change color at this time
  78.       //───── simply return default setting
  79.       otherwise
  80.          ret_val := gfcolors[mcolor][IF(iscolor, 1, 2)]
  81.    endcase
  82. endif
  83. return ret_val
  84.  
  85. * end function ColorSet()
  86. *--------------------------------------------------------------------*
  87.  
  88.  
  89. /*
  90.  
  91.     Function: ColorInit()
  92.     Purpose:  Determine whether to use color or monochrome settings
  93.     Syntax:   ColorInit(<mono/file>)
  94.               Three possibilities here:
  95.  
  96.               1) If you do not pass a parameter, ColorInit() will
  97.               go with whatever ISCOLOR() returns.
  98.  
  99.               2) Pass a logical, and ColorInit() will use COLOR
  100.               if True, or MONO if False.
  101.  
  102.               3) Pass a filename and ColorInit() will load
  103.               previously saved color settings from that file and
  104.               use those instead of anything else.
  105.  
  106.               If you want something more flexible than this, go
  107.               hire yourself a contortionist!
  108.  
  109. */
  110. function colorinit(mvar)
  111. local nhandle, xx, ele, buffer, bytes
  112. do case
  113.    case mvar == NIL
  114.       iscolor := iscolor()
  115.    case valtype(mvar) == 'L'
  116.       iscolor := mvar
  117.    otherwise
  118.       //───── save the name of this file to use as default
  119.       //───── if you later change the colors via COLORMOD()
  120.       colorfile := mvar
  121.       if ( nhandle := fopen(mvar) ) != -1
  122.          buffer := space(COLOR_CNT * 2 + 1)
  123.          bytes := fread(nhandle, @buffer, COLOR_CNT * 2 + 1)
  124.          fclose(nhandle)
  125.          /*
  126.             The first FOR..NEXT loop below is provided strictly for
  127.             downward compatibility with GrumpLib 3.0.  This is necessary
  128.             because color configuration files created with ColorMod()
  129.             3.0 will contain color *or* monochrome settings, but not both.
  130.             On the other hand, Color.cfg files created with 3.1 will
  131.             contain both color and mono settings, along with an additional
  132.             start byte signifying whether to use color or mono.
  133.  
  134.             If you are reasonably certain that you will only be using
  135.             3.1 files, then by all means feel free to delete the first
  136.             FOR..NEXT loop.
  137.          */
  138.          if bytes == COLOR_CNT
  139.             for xx = 1 to bytes
  140.                gfcolors[xx, 1] := Color_N2S(bin2i(substr(buffer, xx, 1)))
  141.             next
  142.          else
  143.             iscolor := (substr(buffer, 1, 1) == "C")
  144.             ele := 1
  145.             for xx = 2 to bytes step 2
  146.                gfcolors[ele, 1] := Color_N2S(bin2i(substr(buffer, xx, 1)))
  147.                gfcolors[ele++, 2] := Color_N2S(bin2i(substr(buffer, xx + 1, 1)))
  148.             next
  149.          endif
  150.       endif
  151. endcase
  152. return nil
  153.  
  154. * end function ColorInit()
  155. *--------------------------------------------------------------------*
  156.  
  157.  
  158. /*
  159.  
  160.    Function: ColorMod()
  161.    Purpose:  View/Modify all Grumpfish global color settings
  162.    Syntax:   ColorMod( <file> )
  163.    Parameter: <file> is the filename & path to save colors to
  164.               If not passed, the user will be allowed to enter
  165.               a filename
  166. */
  167. function ColorMod( savefile )
  168. local key := 0, keepgoing, ntop := 4, nhandle, arrow := chr(196) + chr(16)
  169. local mrow := ntop, mcol := 31, buffer, newcolor, changed := .f., nbottom := 20
  170. local curr_color := 1, oldscore, maincolor := colorset(C_MESSAGE, .T.)
  171. local oldf10 := setkey(K_F10, NIL)       // save F10 setting
  172. memvar getlist
  173. GFSaveEnv(.t., 0)                        // shut off cursor
  174. ShowColors(ntop, nbottom, maincolor)
  175. mrow := ntop
  176. do while key != K_ESC
  177.    @ mrow, mcol ssay chr(16)
  178.    @ mrow, mcol+7 ssay chr(17)
  179.    key := ginkey(0)
  180.    do case
  181.  
  182.       case key == K_F10                  // toggle color/mono
  183.          iscolor := ! iscolor
  184.          changed := .t.
  185.          maincolor := colorset(C_MESSAGE, .T.)
  186.          ShowColors(ntop, nbottom, maincolor)
  187.  
  188.       case key == K_ENTER                // change this color
  189.          newcolor := colorpal(ColorSet(curr_color, .T.))
  190.          if lastkey() != K_ESC
  191.             changed := .t.
  192.             colorset(curr_color, newcolor)
  193.             @ mrow, mcol + 1 ssay "SAMPLE"
  194.             setcolor(maincolor)
  195.          endif
  196.  
  197.       case key == K_UP
  198.          @ mrow, mcol ssay chr(32)
  199.          @ mrow, mcol+7 ssay chr(32)
  200.          if mrow == ntop
  201.             mrow := nbottom
  202.             curr_color += COLOR_CNT - 2
  203.          else
  204.             mrow--
  205.             curr_color -= 2
  206.          endif
  207.  
  208.       case key == K_DOWN
  209.          @ mrow, mcol ssay chr(32)
  210.          @ mrow, mcol+7 ssay chr(32)
  211.          if mrow == nbottom
  212.             mrow := ntop
  213.             curr_color -= (COLOR_CNT - 2)
  214.          else
  215.             mrow++
  216.             curr_color += 2
  217.          endif
  218.  
  219.       case key == K_PGUP
  220.          @ mrow, mcol ssay chr(32)
  221.          @ mrow, mcol+7 ssay chr(32)
  222.          mrow := ntop
  223.          curr_color := if(mcol == 31, 1, 2)
  224.  
  225.       case key == K_PGDN
  226.          @ mrow, mcol ssay chr(32)
  227.          @ mrow, mcol+7 ssay chr(32)
  228.          mrow := nbottom
  229.          curr_color := if(mcol == 70, COLOR_CNT, COLOR_CNT - 1)
  230.  
  231.       case key == K_HOME
  232.          @ mrow, mcol ssay chr(32)
  233.          @ mrow, mcol+7 ssay chr(32)
  234.          mrow := ntop
  235.          mcol := 31
  236.          curr_color := 1
  237.  
  238.       case key == K_END
  239.          @ mrow, mcol ssay chr(32)
  240.          @ mrow, mcol+7 ssay chr(32)
  241.          mrow := nbottom
  242.          mcol := 70
  243.          curr_color := COLOR_CNT
  244.  
  245.       case key == K_LEFT .or. key == K_RIGHT
  246.          @ mrow, mcol ssay chr(32)
  247.          @ mrow, mcol+7 ssay chr(32)
  248.          if mcol == 31
  249.             mcol := 70
  250.             curr_color++
  251.          else
  252.             mcol := 31
  253.             curr_color--
  254.          endif
  255.  
  256.    endcase
  257. enddo
  258.  
  259. //───── if they changed one or more settings, ask if they want to save 'em
  260. if changed
  261.    if yes_no("Would you like to save your settings")
  262.       //───── if filename was passed as parameter to ColorMod(), do
  263.       //───── not allow user to pick a file
  264.       if savefile == NIL
  265.          oldscore := set(_SET_SCOREBOARD, .f.)
  266.          GFSaveGets()
  267.          colorfile := padr(colorfile, 12)
  268.          ColorSet(C_MESSAGE)
  269.          buffer := ShadowBox(11, 18, 13, 61, 2)
  270.          @ 12, 20 ssay "Enter file name to save to:"
  271.          @ 12, 48 get colorfile picture '@!'
  272.          setcursor(1)
  273.          read
  274.          setcursor(0)
  275.          ByeByeBox(buffer)
  276.          GFRestGets()
  277.          set(_SET_SCOREBOARD, oldscore)
  278.       else
  279.          colorfile := savefile
  280.       endif
  281.       if lastkey() != K_ESC .and. ! empty(colorfile)
  282.          colorfile := ltrim(trim(colorfile))
  283.          //───── note: we don't need confirmation to overwrite the file
  284.          //───── if you passed it as a parameter to ColorMod()
  285.          keepgoing := .t.
  286.          if file(colorfile) .and. savefile == NIL
  287.             keepgoing := yes_no(colorfile + ' exists', ;
  288.                                'Do you wish to overwrite it')
  289.          endif
  290.          if keepgoing
  291.             if ( nhandle := fcreate(colorfile) ) != -1
  292.                buffer := space(COLOR_CNT)
  293.                //───── write color/mono setting as first byte
  294.                fwrite(nhandle, if(iscolor, "C", "M"))
  295.                //───── now loop through colors array, write color and
  296.                //───── monochrome settings to the file
  297.                aeval(gfcolors, { | a | fwrite(nhandle, chr(Color_S2N(a[1])) + ;
  298.                                        chr(Color_S2N(a[2]))) } )
  299.                fclose(nhandle)
  300.             endif
  301.          endif
  302.       endif
  303.    endif
  304. endif
  305. GFRestEnv()
  306. setkey(K_F10, oldf10)         // restore F10 setting
  307. return NIL
  308.  
  309. * end function ColorMod()
  310. *--------------------------------------------------------------------*
  311.  
  312.  
  313. /*
  314.    Function: ShowColors()
  315.    Purpose:  Show samples for entire colors array
  316. */
  317. static function showcolors(ntop, nbottom, maincolor)
  318. local xx
  319. dispbegin()
  320. setcolor(maincolor)
  321. SINGLEBOX(ntop - 1, 0, nbottom + 2, 79)
  322. SCRNCENTER(nbottom + 1, chr(24) + chr(25) + chr(27) + chr(26) + "PgUp "   + ;
  323.            "PgDn to move" + space(4) + "Enter to change color" + space(4) + ;
  324.            "F10 switches to " + if(iscolor, "monochrome", "color"))
  325. setpos(ntop, 0)
  326. for xx = 1 to COLOR_CNT
  327.    @ row(), if(xx % 2 == 1, 2, 42) ssay gfcolors[xx][3]
  328.    colorset(xx)
  329.    @ row(), if(xx % 2 == 1, 32, 71) ssay "SAMPLE"
  330.    setcolor(maincolor)
  331.    if xx % 2 == 0
  332.       setpos(row()+1, 0)
  333.    endif
  334. next
  335. dispend()
  336. return nil
  337.  
  338. * end static function ShowColors()
  339. *--------------------------------------------------------------------*
  340.  
  341. * eof colorset.prg
  342.