home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / clrchart.aml < prev    next >
Text File  |  1995-08-10  |  7KB  |  269 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        CLRCHART.AML                                         */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro displays a color chart with color         */
  6. /*               attribute codes in decimal and hexidecimal. It is    */
  7. /*               used by CFGCOLOR.X, but also be used independently.  */
  8. /*                                                                    */
  9. /* Usage:        To enter a color string (e.g. 'red on blue') at      */
  10. /*               the cursor position in your text:                    */
  11. /*                 1. run this macro                                  */
  12. /*                 2. position the cursor to the desired color        */
  13. /*                 3. press <enter>                                   */
  14. /* ------------------------------------------------------------------ */
  15.  
  16.   include bootpath "define.aml"
  17.  
  18.   define
  19.     set display_str    '  '
  20.   end
  21.  
  22.   var basecolor
  23.   var foreground
  24.   var background
  25.   var lforeground
  26.   var lbackground
  27.   var xbackground
  28.   var retvalue
  29.   var colorstring
  30.  
  31.   xposition    = arg 2
  32.   yposition    = arg 3
  33.   initialattr  = arg 4
  34.   notifyobject = arg 5
  35.  
  36.   if initialattr then
  37.     foreground = initialattr & 0fh
  38.     background = (initialattr & 0f0h) shr 4
  39.     if background > 7 then
  40.       background = background - 8
  41.       basecolor  = 128
  42.     end
  43.   end
  44.  
  45.  
  46.   // keep this code resident
  47.   stayresident
  48.   inheritfrom "win"
  49.  
  50.   // create the color chart window
  51.   createwindow
  52.   setframe ">b"
  53.   setcolor  border_color         color gray  on black
  54.   setcolor  text_color           color black on black
  55.   setcolor  border_flash_color   color brightgreen on black
  56.   settitle "Color Chart"
  57.   setwinctrl (if? basecolor "≡" "≡") 2
  58.  
  59.   if xposition then
  60.     sizewindow xposition yposition xposition + 23 yposition + 17
  61.                "a1" '' (getprevwin)
  62.   else
  63.     // center the window
  64.     width = 24
  65.     height = 18
  66.     ox = (getvidcols - width) / 2
  67.     oy = (getvidrows - height) / 2
  68.     sizewindow ox oy ox + width - 1 oy + height - 1 "ad"
  69.   end
  70.   setborder "1f"
  71.  
  72.   // draw the color chart
  73.   function drawchart
  74.     var b
  75.     var f
  76.     gotoxy 1 1
  77.     while f < 16 do
  78.       while b < 8 do
  79.         writestr display_str  (b * 16 + f) + basecolor
  80.         b = b + 1
  81.       end
  82.       writeline
  83.       b = 0
  84.       f = f + 1
  85.     end
  86.     gotoxy 19 17
  87.     writestr "  O" (color black on green)
  88.     writestr "k  " (color red   on green)
  89.   end
  90.  
  91.   drawchart
  92.  
  93.   // return the color name for a color attribute
  94.   function attrname (attr)
  95.     case attr
  96.       when  0 "black"       when  8 "darkgray"
  97.       when  1 "blue"        when  9 "brightblue"
  98.       when  2 "green"       when 10 "brightgreen"
  99.       when  3 "cyan"        when 11 "brightcyan"
  100.       when  4 "red"         when 12 "brightred"
  101.       when  5 "magenta"     when 13 "pink"
  102.       when  6 "brown"       when 14 "yellow"
  103.       when  7 "gray"        when 15 "white"
  104.     end
  105.   end
  106.  
  107.   function draw
  108.  
  109.     // clear the old bracket cursor
  110.     if xbackground then
  111.       writestr display_str lforeground + (lbackground * 16) + basecolor   xbackground - 1
  112.     end
  113.  
  114.     attr = foreground + (background * 16) + basecolor
  115.     //attr = getattr
  116.     colorstring = (attrname foreground) + ' on ' + (attrname background + (if? basecolor 8))
  117.  
  118.     // write color info at the bottom of the chart
  119.     writestr (pad '[dec=' + attr + ',hex=' + (base attr 16) + ']' 16 'l')
  120.              (color gray on black) 1 17
  121.     writestr  (pad colorstring 24 'l') (color gray on black) 1 18
  122.  
  123.     // move the cursor to the appropriate color cell
  124.     xbackground = background * 3 + 2
  125.     gotoxy xbackground foreground + 1
  126.  
  127.     // write the bracket [ ] cursor
  128.     attr = (if? background + (if? basecolor 8) > brightblue black white) + (background * 16) + basecolor
  129.     writestr '[' attr  xbackground - 1
  130.     writestr ']' attr  xbackground + 1
  131.     gotoxy xbackground foreground + 1
  132.  
  133.     lforeground = foreground
  134.     lbackground = background
  135.  
  136.     sendobject notifyobject "oncolor" (getattr)
  137.   end
  138.  
  139.   draw
  140.   showcursor 50 99
  141.  
  142.   // local close function for this window
  143.   function close (value)
  144.     // call 'close' in object 'win'
  145.     pass
  146.     destroyobject
  147.     endprocess
  148.     retvalue = if? (arg) value -1
  149.   end
  150.  
  151.   // toggle background base color
  152.   function togglebase
  153.     if basecolor then
  154.       basecolor = 0
  155.       setwinctrl '≡' 2
  156.     else
  157.       basecolor = 128
  158.       setwinctrl '≡' 2
  159.     end
  160.     xbackground = 0
  161.     drawchart
  162.     draw
  163.   end
  164.  
  165.   function "≡"
  166.     close
  167.   end
  168.  
  169.   // exit the chart
  170.   key <esc>
  171.     close
  172.   end
  173.  
  174.   // exit the chart when switching windows
  175.   function  onkillfocus
  176.     close
  177.   end
  178.  
  179.   // enter the color description in an edit window and exit
  180.   key <enter>
  181.     queue "write" colorstring
  182.     close (getattr)
  183.   end
  184.  
  185.   function <lbutton> (m)
  186.     pass
  187.     case getregion
  188.       // client area
  189.       when 1
  190.         if virtorow <= 16 then
  191.           foreground = (virtorow - 1) mod 16
  192.         else
  193.           // Ok button
  194.           if not m and virtorow == 17 and virtocol >= 19 then
  195.             call <enter>
  196.           end
  197.           return
  198.         end
  199.         background = (virtocol - 1) / 3
  200.         draw
  201.       when 52
  202.         togglebase
  203.     end
  204.   end
  205.  
  206.   function <move>
  207.     pass
  208.     if (button? 1) and getregion == 1 then
  209.       send <lbutton> 1
  210.     end
  211.   end
  212.  
  213.   function <ldouble>
  214.     call <enter>
  215.   end
  216.  
  217.   // check for 'Ok' hotkey
  218.   function <char> (c)
  219.     if icompare c 'k' then
  220.       call <enter>
  221.     else
  222.       pass
  223.     end
  224.   end
  225.  
  226.   // move the cursor around in the chart
  227.   key <left>
  228.     if not background then
  229.       togglebase
  230.     end
  231.     background = if? background (background - 1) 7
  232.     draw
  233.   end
  234.  
  235.   key <right>
  236.     if background == 7 then
  237.       togglebase
  238.     end
  239.     background = (background + 1) mod 8
  240.     draw
  241.   end
  242.  
  243.   key <up>
  244.     foreground = if? foreground (foreground - 1) 15
  245.     draw
  246.   end
  247.  
  248.   key <down>
  249.     foreground = (foreground + 1) mod 16
  250.     draw
  251.   end
  252.  
  253.   // toggle background base color
  254.   key <tab>
  255.     togglebase
  256.   end
  257.  
  258.   // toggle background base color
  259.   key <shift tab>
  260.     togglebase
  261.   end
  262.  
  263.   // invoke the editor recursively
  264.   // wait for endprocess to return here
  265.   process
  266.  
  267.   // return the ascii value
  268.   return retvalue
  269.