home *** CD-ROM | disk | FTP | other *** search
- # $Header: P:/source/ppee/macros/colors.pev 1.19 12 Jun 1990 15:15:04 skipr $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: colors.pel $:
- #
- # colors for windows:
- #
- # These colors are accessed via select_color(), which returns color
- # codes compatible with color_text, color_messages, etc.
- #
- # For compatibility with mono displays, select_color() always returns
- # codes for black on white unless/until initColors() is called.
- #
-
- local A_BLACK = 0 # foreground or background
- local A_BLUE = 1
- local A_GREEN = 2
- #local A_CYAN = 3
- local A_RED = 4
- #local A_MAGENTA = 5
- #local A_BROWN = 6
- #local A_LIGHTGREY = 7
- local A_WHITE = 7
-
- #local A_GREY = 8 # high-intensity foreground
- #local A_DARKGREY = 8 # or blinking background
- #local A_LIGHTBLUE = 9
- #local A_LIGHTGREEN = 10
- #local A_LIGHTCYAN = 11
- #local A_LIGHTRED = 12
- #local A_LIGHTMAGENTA = 13
- #local A_LIGHTBROWN = 14
- #local A_YELLOW = 14
- #local A_LIGHTWHITE = 15
- #local A_BRIGHTWHITE = 15
-
- local nextNice = 0
- local maxNice = 0
- local niceColor
- local colorNames
-
- function ATTR( fg, bg ){
- return fg + bg*16
- }
-
- function foreground( c ){
- return and( c, 15 )
- }
-
- function background( c ){
- return and( c/16, 7 )
- }
-
- function reverseVideo( c ){
- return ATTR( background( c ), and( foreground( c ), 7 ))
- }
-
-
- function color_current_window(){
- local c = select_color()
-
- if( c ){
- color_text = color_border = c
- color_highlight = reverseVideo( c )
- }
- }
-
-
- function select_color(){
- local c
-
- if( maxNice <= 0 )
- return 0 # signal error with bad color combo
-
- c = niceColor[ nextNice ]
- # message( " color[ %d ] = %s", nextNice, colorName( c ))
- nextNice = ( nextNice + 1 ) % maxNice
-
- return c
- }
-
-
- function init_colors( cancel ){
-
- if( cancel ){
- maxNice = 0
- return
- }
-
- # pleasing (high contrast) color combinations:
-
- # brown and red are nearly indistinguishable on my VGA display
- # they might look nice on someone else's
-
- # FG BG
-
- niceColor[ maxNice++ ] = ATTR( A_BLACK, A_GREEN )
- niceColor[ maxNice++ ] = ATTR( A_BLACK, A_RED )
- # niceColor[ maxNice++ ] = ATTR( A_BLACK, A_BLUE )
- niceColor[ maxNice++ ] = ATTR( A_BLACK, A_WHITE )
-
- niceColor[ maxNice++ ] = ATTR( A_BLUE, A_WHITE )
- # niceColor[ maxNice++ ] = ATTR( A_BLUE, A_BLACK )
-
- # niceColor[ maxNice++ ] = ATTR( A_DARKGREY, A_WHITE )
- # niceColor[ maxNice++ ] = ATTR( A_WHITE, A_DARKGREY )
-
- niceColor[ maxNice++ ] = ATTR( A_GREEN, A_BLACK )
- # niceColor[ maxNice++ ] = ATTR( A_GREEN, A_WHITE )
-
- niceColor[ maxNice++ ] = ATTR( A_RED, A_BLACK )
- niceColor[ maxNice++ ] = ATTR( A_RED, A_WHITE )
-
- niceColor[ maxNice++ ] = ATTR( A_WHITE, A_BLUE )
- # niceColor[ maxNice++ ] = ATTR( A_WHITE, A_BROWN )
- niceColor[ maxNice++ ] = ATTR( A_WHITE, A_BLACK )
- niceColor[ maxNice++ ] = ATTR( A_WHITE, A_RED )
- niceColor[ maxNice++ ] = ATTR( A_WHITE, A_GREEN )
-
- # niceColor[ maxNice++ ] = ATTR( A_YELLOW, A_BROWN )
- # niceColor[ maxNice++ ] = ATTR( A_YELLOW, A_BLACK )
- # niceColor[ maxNice++ ] = ATTR( A_YELLOW, A_RED )
- # niceColor[ maxNice++ ] = ATTR( A_YELLOW, A_GREEN )
- # niceColor[ maxNice++ ] = ATTR( A_YELLOW, A_BLUE )
-
- # the yellows do look nice, but the current border colors
- # use the reverse of yellow which is, like, red. Some good
- # combinations would utilize the above yellows foregrounds,
- # and something other than brown for the window borders.
-
- colorNames[ 0 ] = "black(0)"
- colorNames[ 1 ] = "blue(1)"
- colorNames[ 2 ] = "green(2)"
- colorNames[ 3 ] = "cyan(3)"
- colorNames[ 4 ] = "red(4)"
- colorNames[ 5 ] = "magenta(5)"
- colorNames[ 6 ] = "brown(6)"
- colorNames[ 7 ] = "white(7)"
- }
-
- function colorName( c ){
- local s = " on " colorNames[ and( 7, c/16 )]
- s = colorNames[ and( 7, c )] s
- if( and( 8, c ))
- s = "bright " s
- if( and( 128, c ))
- s = "blink " s
- return s
- }
-
-
- # a crude way to adjust color variables
-
-
- local cur_attr
- local color_attr
- local adjust_keymap
- local max_attr = 10
-
- function adjust_colors(){
- local prev_keymap = current_keymap
-
- if( !adjust_keymap ){
- current_keymap = adjust_keymap = create_keymap( empty_keymap )
- assign_key( "<Up>", "adjust_color 0xF0 16" )
- assign_key( "<Down>", "adjust_color 0xF0 -16" )
- assign_key( "<Right>", "adjust_color 0x0F 1" )
- assign_key( "<Left>", "adjust_color 0x0F -1" )
- assign_key( "<PgUp>", "adjust_color_key 1" )
- assign_key( "<PgDn>", "adjust_color_key 2" )
- assign_key( "<Keypad-+>", "adjust_color_key 3" )
- assign_key( "<Keypad-Minus>", "adjust_color_key 4" )
- assign_key( "<Keypad-Enter>", "process_end 0" )
- assign_key( "<Enter>", "process_end 0" )
- assign_key( "<Esc>", "process_end 1" )
- } else
- current_keymap = adjust_keymap
-
- cur_attr = 0
- color_attr[ 0 ] = "color_window"
- color_attr[ 1 ] = "color_highlight"
- color_attr[ 2 ] = "color_linenumbers"
- color_attr[ 3 ] = "color_text"
- color_attr[ 4 ] = "color_border"
- color_attr[ 5 ] = "color_title"
- color_attr[ 6 ] = "color_errors"
- color_attr[ 7 ] = "color_warnings"
- color_attr[ 8 ] = "color_messages"
- color_attr[ 9 ] = "color_background"
-
- adjust_color_notice()
-
- if( process_begin()){ # canceled...
- message( "Color adjustments canceled.")
- } else { # accepted...
- message("")
- }
-
- current_keymap = prev_keymap
- }
-
-
- function adjust_color_key( s ){
- if( 0+s == 1 ) # "<PgUp>"
- cur_attr = ( cur_attr + max_attr - 1 ) % max_attr
- else if( 0+s == 2 ) # "<PgDn>"
- cur_attr = ( cur_attr + 1 ) % max_attr
-
- adjust_color_notice()
- }
-
- function adjust_color( mask, inc ){
- local col = color_attr[ cur_attr ]
- local val = execute_function(( cur_attr == 0 ? "color_text" : col ))
- local val2
-
- mask = 0+mask
- inc = 0+inc
-
- val = or( and( mask, val + inc ), and( val, not( mask )))
-
- if( cur_attr != 0 )
- execute_function( col "=" val )
- else {
- # "color_window":
- val2 = or( and( val, 15 )*16, and( val/16, 15 ))
- color_text = color_border = val
- color_highlight = color_title = val2
- }
-
- adjust_color_notice( )
- }
-
-
- local function adjust_color_notice(){
- local col = color_attr[ cur_attr ]
- local val = execute_function(( cur_attr == 0 ? "color_text" : col ))
-
- message( "%s = %d / 0x%2X", col, val, val )
- }
-