home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------------ */
- /* Macro: CLRCHART.AML */
- /* Written by: nuText Systems */
- /* */
- /* Description: This macro displays a color chart with color */
- /* attribute codes in decimal and hexidecimal. It is */
- /* used by CFGCOLOR.X, but also be used independently. */
- /* */
- /* Usage: To enter a color string (e.g. 'red on blue') at */
- /* the cursor position in your text: */
- /* 1. run this macro */
- /* 2. position the cursor to the desired color */
- /* 3. press <enter> */
- /* ------------------------------------------------------------------ */
-
- include bootpath "define.aml"
-
- define
- set display_str ' '
- end
-
- var basecolor
- var foreground
- var background
- var lforeground
- var lbackground
- var xbackground
- var retvalue
- var colorstring
-
- xposition = arg 2
- yposition = arg 3
- initialattr = arg 4
- notifyobject = arg 5
-
- if initialattr then
- foreground = initialattr & 0fh
- background = (initialattr & 0f0h) shr 4
- if background > 7 then
- background = background - 8
- basecolor = 128
- end
- end
-
- // inherit window handling from 'win' object
- inheritfrom "win"
-
- // create the color chart window
- createwindow
- setframe ">b"
- setcolor border_color color gray on black
- setcolor text_color color black on black
- setcolor border_flash_color color brightgreen on black
- settitle "Color Chart"
- setwinctrl (if? basecolor "≡" "≡") 2
-
- if xposition then
- sizewindow xposition yposition xposition + 23 yposition + 17
- "a1" '' (getprevwin)
- else
- // center the window
- width = 24
- height = 18
- ox = (getvidcols - width) / 2
- oy = (getvidrows - height) / 2
- sizewindow ox oy ox + width - 1 oy + height - 1 "ad"
- end
- setborder "1f"
-
- // draw the color chart
- function drawchart
- var b
- var f
- gotoxy 1 1
- while f < 16 do
- while b < 8 do
- writestr display_str (b * 16 + f) + basecolor
- b = b + 1
- end
- writeline
- b = 0
- f = f + 1
- end
- gotoxy 19 17
- writestr " O" (color black on green)
- writestr "k " (color red on green)
- end
-
- drawchart
-
- // return the color name for a color attribute
- function attrname (attr)
- case attr
- when 0 "black" when 8 "darkgray"
- when 1 "blue" when 9 "brightblue"
- when 2 "green" when 10 "brightgreen"
- when 3 "cyan" when 11 "brightcyan"
- when 4 "red" when 12 "brightred"
- when 5 "magenta" when 13 "pink"
- when 6 "brown" when 14 "yellow"
- when 7 "gray" when 15 "white"
- end
- end
-
- function draw
-
- // clear the old bracket cursor
- if xbackground then
- writestr display_str lforeground + (lbackground * 16) + basecolor xbackground - 1
- end
-
- attr = foreground + (background * 16) + basecolor
- //attr = getattr
- colorstring = (attrname foreground) + ' on ' + (attrname background + (if? basecolor 8))
-
- // write color info at the bottom of the chart
- writestr (pad '[dec=' + attr + ',hex=' + (base attr 16) + ']' 16 'l')
- (color gray on black) 1 17
- writestr (pad colorstring 24 'l') (color gray on black) 1 18
-
- // move the cursor to the appropriate color cell
- xbackground = background * 3 + 2
- gotoxy xbackground foreground + 1
-
- // write the bracket [ ] cursor
- attr = (if? background + (if? basecolor 8) > brightblue black white) + (background * 16) + basecolor
- writestr '[' attr xbackground - 1
- writestr ']' attr xbackground + 1
- gotoxy xbackground foreground + 1
-
- lforeground = foreground
- lbackground = background
-
- sendobject notifyobject "oncolor" (getattr)
- end
-
- draw
- showcursor 50 99
-
- // local close function for this window
- function close (value)
- // call 'close' in object 'win'
- pass
- destroyobject
- endprocess
- retvalue = if? (arg) value -1
- end
-
- // toggle background base color
- function togglebase
- if basecolor then
- basecolor = 0
- setwinctrl '≡' 2
- else
- basecolor = 128
- setwinctrl '≡' 2
- end
- xbackground = 0
- drawchart
- draw
- end
-
- function "≡"
- close
- end
-
- // exit the chart
- key <esc>
- close
- end
-
- // exit the chart when switching windows
- function onkillfocus
- close
- end
-
- // enter the color description in an edit window and exit
- key <enter>
- queue "write" colorstring
- close (getattr)
- end
-
- function <lbutton> (m)
- pass
- case getregion
- // client area
- when 1
- if virtorow <= 16 then
- foreground = (virtorow - 1) mod 16
- else
- // Ok button
- if not m and virtorow == 17 and virtocol >= 19 then
- call <enter>
- end
- return
- end
- background = (virtocol - 1) / 3
- draw
- when 52
- togglebase
- end
- end
-
- function <move>
- pass
- if (button? 1) and getregion == 1 then
- send <lbutton> 1
- end
- end
-
- function <ldouble>
- call <enter>
- end
-
- // check for 'Ok' hotkey
- function <char> (c)
- if icompare c 'k' then
- call <enter>
- else
- pass
- end
- end
-
- // move the cursor around in the chart
- key <left>
- if not background then
- togglebase
- end
- background = if? background (background - 1) 7
- draw
- end
-
- key <right>
- if background == 7 then
- togglebase
- end
- background = (background + 1) mod 8
- draw
- end
-
- key <up>
- foreground = if? foreground (foreground - 1) 15
- draw
- end
-
- key <down>
- foreground = (foreground + 1) mod 16
- draw
- end
-
- // toggle background base color
- key <tab>
- togglebase
- end
-
- // toggle background base color
- key <shift tab>
- togglebase
- end
-
- // invoke the editor recursively
- // wait for endprocess to return here
- process
-
- // return the ascii value
- return retvalue
-