home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w055 / 4.ddi / SOURCES.LIF / COLORS.PEL < prev    next >
Encoding:
Text File  |  1990-09-27  |  6.8 KB  |  256 lines

  1. # $Header:   P:/source/ppee/macros/colors.pev   1.19   12 Jun 1990 15:15:04   skipr  $
  2.  
  3. ##############################################################################
  4. #
  5. #           Sage Software - POLYTRON Division
  6. #             1700 NW 167th Place
  7. #               Beaverton, OR 97006
  8. #
  9. #   Copyright 1990, Sage Software, Inc.
  10. #
  11. #   Permission is hereby granted for licensed users of Sage Professional
  12. #   Editor and PolyAwk to copy and modify this source code for their own
  13. #   personal use.  These derivative works may be distributed only to other
  14. #   licensed Sage Professional Editor and PolyAwk users.  All other usage
  15. #   is prohibited without express written permission from Sage Software.
  16. #
  17. ##############################################################################
  18.  
  19. #### $Workfile:   colors.pel  $: 
  20. #
  21. # colors for windows:
  22. #
  23. # These colors are accessed via select_color(), which returns color
  24. # codes compatible with color_text, color_messages, etc.
  25. #
  26. # For compatibility with mono displays, select_color() always returns
  27. # codes for black on white unless/until initColors() is called.
  28. #
  29.  
  30. local A_BLACK        = 0    # foreground or background
  31. local A_BLUE        = 1
  32. local A_GREEN        = 2
  33. #local A_CYAN        = 3
  34. local A_RED        = 4
  35. #local A_MAGENTA    = 5
  36. #local A_BROWN        = 6
  37. #local A_LIGHTGREY     = 7
  38. local A_WHITE        = 7
  39.  
  40. #local A_GREY        = 8    # high-intensity foreground 
  41. #local A_DARKGREY    = 8    # or blinking background
  42. #local A_LIGHTBLUE    = 9
  43. #local A_LIGHTGREEN    = 10
  44. #local A_LIGHTCYAN    = 11
  45. #local A_LIGHTRED    = 12
  46. #local A_LIGHTMAGENTA    = 13
  47. #local A_LIGHTBROWN    = 14
  48. #local A_YELLOW        = 14
  49. #local A_LIGHTWHITE     = 15
  50. #local A_BRIGHTWHITE     = 15
  51.  
  52. local nextNice = 0
  53. local maxNice = 0
  54. local niceColor
  55. local colorNames
  56.  
  57. function ATTR( fg, bg ){
  58.     return fg + bg*16 
  59. }
  60.  
  61. function foreground( c ){
  62.     return and( c, 15 )
  63. }
  64.  
  65. function background( c ){
  66.     return and( c/16, 7 )
  67. }
  68.  
  69. function reverseVideo( c ){
  70.     return ATTR( background( c ), and( foreground( c ), 7 ))
  71. }
  72.  
  73.  
  74. function color_current_window(){
  75.     local c = select_color()
  76.  
  77.     if( c ){
  78.         color_text = color_border = c
  79.         color_highlight = reverseVideo( c )
  80.     }
  81. }
  82.  
  83.  
  84. function select_color(){
  85.     local c 
  86.  
  87.     if( maxNice <= 0 )
  88.         return 0    # signal error with bad color combo
  89.     
  90.     c = niceColor[ nextNice ]
  91.     # message( " color[ %d ] = %s", nextNice, colorName( c ))
  92.     nextNice = ( nextNice + 1 ) % maxNice
  93.  
  94.     return c
  95.  
  96.  
  97. function init_colors( cancel ){
  98.  
  99.     if( cancel ){
  100.         maxNice = 0
  101.         return
  102.     }
  103.  
  104.     # pleasing (high contrast) color combinations:
  105.     
  106.     # brown and red are nearly indistinguishable on my VGA display
  107.     # they might look nice on someone else's
  108.  
  109.                            #         FG              BG
  110.  
  111.     niceColor[ maxNice++ ] = ATTR( A_BLACK,        A_GREEN    )
  112.     niceColor[ maxNice++ ] = ATTR( A_BLACK,        A_RED    )
  113. #    niceColor[ maxNice++ ] = ATTR( A_BLACK,        A_BLUE    )
  114.     niceColor[ maxNice++ ] = ATTR( A_BLACK,        A_WHITE    )
  115.  
  116.     niceColor[ maxNice++ ] = ATTR( A_BLUE,        A_WHITE    )
  117. #    niceColor[ maxNice++ ] = ATTR( A_BLUE,        A_BLACK    )
  118.  
  119. #    niceColor[ maxNice++ ] = ATTR( A_DARKGREY,    A_WHITE    )
  120. #    niceColor[ maxNice++ ] = ATTR( A_WHITE,        A_DARKGREY )
  121.  
  122.     niceColor[ maxNice++ ] = ATTR( A_GREEN,        A_BLACK    )
  123. #    niceColor[ maxNice++ ] = ATTR( A_GREEN,        A_WHITE    )
  124.  
  125.     niceColor[ maxNice++ ] = ATTR( A_RED,        A_BLACK    )
  126.     niceColor[ maxNice++ ] = ATTR( A_RED,        A_WHITE    )
  127.  
  128.     niceColor[ maxNice++ ] = ATTR( A_WHITE,        A_BLUE    )
  129. #    niceColor[ maxNice++ ] = ATTR( A_WHITE,        A_BROWN    )
  130.     niceColor[ maxNice++ ] = ATTR( A_WHITE,        A_BLACK    )
  131.     niceColor[ maxNice++ ] = ATTR( A_WHITE,        A_RED    )
  132.     niceColor[ maxNice++ ] = ATTR( A_WHITE,        A_GREEN    )
  133.  
  134. #    niceColor[ maxNice++ ] = ATTR( A_YELLOW,    A_BROWN    )
  135. #    niceColor[ maxNice++ ] = ATTR( A_YELLOW,    A_BLACK    )
  136. #    niceColor[ maxNice++ ] = ATTR( A_YELLOW,    A_RED    )
  137. #    niceColor[ maxNice++ ] = ATTR( A_YELLOW,    A_GREEN )
  138. #    niceColor[ maxNice++ ] = ATTR( A_YELLOW,    A_BLUE    )
  139.  
  140.     # the yellows do look nice, but the current border colors
  141.     # use the reverse of yellow which is, like, red.  Some good
  142.     # combinations would utilize the above yellows foregrounds,
  143.     # and something other than brown for the window borders.
  144.  
  145.     colorNames[ 0 ] = "black(0)"
  146.     colorNames[ 1 ] = "blue(1)"
  147.     colorNames[ 2 ] = "green(2)"
  148.     colorNames[ 3 ] = "cyan(3)"
  149.     colorNames[ 4 ] = "red(4)"
  150.     colorNames[ 5 ] = "magenta(5)"
  151.     colorNames[ 6 ] = "brown(6)"
  152.     colorNames[ 7 ] = "white(7)"
  153. }
  154.  
  155. function colorName( c ){
  156.     local s = " on " colorNames[ and( 7, c/16 )]
  157.     s = colorNames[ and( 7, c )] s
  158.     if( and( 8, c ))
  159.         s = "bright " s
  160.     if( and( 128, c ))
  161.         s = "blink " s
  162.     return s
  163. }
  164.  
  165.  
  166. # a crude way to adjust color variables
  167.  
  168.  
  169. local cur_attr
  170. local color_attr
  171. local adjust_keymap
  172. local max_attr = 10
  173.  
  174. function adjust_colors(){
  175.     local prev_keymap = current_keymap
  176.  
  177.     if( !adjust_keymap ){
  178.         current_keymap = adjust_keymap = create_keymap( empty_keymap )
  179.         assign_key( "<Up>",        "adjust_color 0xF0  16" )
  180.         assign_key( "<Down>",        "adjust_color 0xF0 -16" )
  181.         assign_key( "<Right>",        "adjust_color 0x0F   1" )
  182.         assign_key( "<Left>",        "adjust_color 0x0F  -1" )
  183.         assign_key( "<PgUp>",        "adjust_color_key  1" )
  184.         assign_key( "<PgDn>",        "adjust_color_key  2" )
  185.         assign_key( "<Keypad-+>",    "adjust_color_key  3" )
  186.         assign_key( "<Keypad-Minus>",    "adjust_color_key  4" )
  187.         assign_key( "<Keypad-Enter>",    "process_end 0" )
  188.         assign_key( "<Enter>",        "process_end 0" )
  189.         assign_key( "<Esc>",        "process_end 1" )
  190.     } else
  191.         current_keymap = adjust_keymap
  192.  
  193.     cur_attr = 0
  194.     color_attr[ 0 ] = "color_window"
  195.     color_attr[ 1 ] = "color_highlight"
  196.     color_attr[ 2 ] = "color_linenumbers"
  197.     color_attr[ 3 ] = "color_text"
  198.     color_attr[ 4 ] = "color_border"
  199.     color_attr[ 5 ] = "color_title"
  200.     color_attr[ 6 ] = "color_errors"
  201.     color_attr[ 7 ] = "color_warnings"
  202.     color_attr[ 8 ] = "color_messages"
  203.     color_attr[ 9 ] = "color_background"
  204.     
  205.     adjust_color_notice()
  206.     
  207.     if( process_begin()){             # canceled...
  208.         message( "Color adjustments canceled.")
  209.     } else {                 # accepted...
  210.         message("")
  211.     }
  212.  
  213.     current_keymap = prev_keymap
  214. }
  215.  
  216.  
  217. function adjust_color_key( s ){
  218.         if( 0+s == 1 )        # "<PgUp>"
  219.             cur_attr = ( cur_attr + max_attr - 1 ) % max_attr
  220.     else    if( 0+s == 2 )        # "<PgDn>"
  221.             cur_attr = ( cur_attr + 1 ) % max_attr
  222.  
  223.     adjust_color_notice()
  224. }
  225.  
  226. function adjust_color( mask, inc ){
  227.     local col = color_attr[ cur_attr ]
  228.     local val = execute_function(( cur_attr == 0 ? "color_text" : col ))
  229.     local val2
  230.  
  231.     mask = 0+mask
  232.     inc = 0+inc
  233.  
  234.     val = or( and( mask, val + inc ), and( val, not( mask )))
  235.  
  236.     if( cur_attr != 0 )
  237.         execute_function( col "=" val )
  238.     else {
  239.         # "color_window":
  240.         val2 = or( and( val, 15 )*16, and( val/16, 15 ))
  241.         color_text = color_border = val
  242.         color_highlight = color_title = val2
  243.     }
  244.  
  245.     adjust_color_notice( )
  246. }
  247.  
  248.  
  249. local function adjust_color_notice(){
  250.     local col = color_attr[ cur_attr ]
  251.     local val = execute_function(( cur_attr == 0 ? "color_text" : col ))
  252.  
  253.     message( "%s = %d / 0x%2X", col, val, val )
  254. }
  255.