home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprogs / colrname.icn < prev    next >
Text File  |  2000-08-03  |  3KB  |  126 lines

  1. ############################################################################
  2. #    File:     colrname.icn
  3. #    Subject:  Program to browse color names
  4. #    Author:   Clinton L. Jeffery
  5. #
  6. #    Date:     August 3, 2000
  7. ############################################################################
  8. #
  9. #   This file is in the public domain.
  10. #
  11. ############################################################################
  12. #
  13. #    Version:  1.1
  14. #
  15. #    Extension to output color specification added by Ralph E. Griswold
  16. #
  17. ############################################################################
  18. #
  19. #     An X color name browser.
  20. #
  21. #     Click on a colorname to change the window's background color.
  22. # Not very interesting on a monochrome server.
  23. #
  24. ############################################################################
  25. #
  26. # Requires:  Version 9 graphics with mutable colors and X.
  27. #
  28. ############################################################################
  29. #
  30. #  Links: sort, wopen
  31. #
  32. ############################################################################
  33.  
  34. link sort
  35. link wopen
  36.  
  37. global w, L, startcols, rows, theBackGround
  38.  
  39. procedure drawit()
  40.    local curcol, i, maxcol
  41.    curcol := 1
  42.    i := 0
  43.    startcols := [1]
  44.    maxcol := 0
  45.    every name := !L do {
  46.       maxcol <:= *name
  47.       GotoRC(i % rows + 1,curcol)
  48.       writes(&window,name)
  49.       i +:= 1
  50.       if (i>0) & (i % rows = 0) then {
  51.      curcol +:= maxcol + 2
  52.      maxcol := 0
  53.      put(startcols,curcol)
  54.      }
  55.       }
  56. end
  57.  
  58.  
  59. procedure doevents()
  60.    local e, varcol, lastvarcol, lastrow
  61.    repeat {
  62.       Active()
  63.       while Pending()[1] do {
  64.      e := Event()
  65.      case e of {
  66.             "o":      write(ColorValue(\name))
  67.         "q"|"\e": exit(0)
  68.         &lpress|&mpress|&rpress|&ldrag|&mdrag|&rdrag: {
  69.            varcol := 0
  70.            every &col >= !startcols do varcol +:= 1
  71.            if varcol === lastvarcol & &row===lastrow then next
  72.            lastvarcol := varcol
  73.            lastrow := &row
  74.            name := L[(varcol-1)*rows+&row]
  75.            Color(theBackGround,name)
  76.            WAttrib("label=Color Names: " || name)
  77.         }
  78.      }
  79.       }
  80.    }
  81. end
  82.  
  83. procedure main(av)
  84.    local filename, f, i, t, max, line, t2, r, g, b, rgb
  85.  
  86.    filename := av[1] | "/usr/lib/X11/rgb.txt"
  87.    WOpen("label=Color Names","x","cursor=on","lines=50","columns=175") |
  88.       stop("no window")
  89.    rows := WAttrib("lines")
  90.    f := open(filename) | stop("no rgb.txt")
  91.  
  92.    theBackGround := NewColor("white")
  93.    Bg(theBackGround)
  94.    EraseArea()
  95.  
  96.    i := 1
  97.    t := set()
  98.    t2 := table() # skip redundant colors by storing their rgb
  99.    max := 0
  100.    every line := !f do {
  101.       line ? {
  102.      tab(upto(&digits))
  103.      r := tab(many(&digits))
  104.      tab(upto(&digits))
  105.      g := tab(many(&digits))
  106.      tab(upto(&digits))
  107.      b := tab(many(&digits))
  108.      rgb := ishift(r,16)+ishift(g,8)+b
  109.      name := (tab(upto(&letters)) & tab(0))
  110.      if /t2[rgb] := name then {
  111.         insert(t,name)
  112.         max <:= *name
  113.         i +:= 1
  114.         }
  115.      }
  116.       }
  117.    L := isort(t)
  118.  
  119.    drawit()
  120.    doevents()
  121. end
  122.