2003-03-10 21:47:38 -05:00
|
|
|
;; Copyright (c) 2001-2003 by David Frese
|
2001-06-11 11:28:32 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-record-type color :color
|
|
|
|
(make-color pixel red green blue)
|
|
|
|
color?
|
|
|
|
(pixel color:pixel set-color:pixel!)
|
|
|
|
(red color:red set-color:red!)
|
|
|
|
(green color:green set-color:green!)
|
|
|
|
(blue color:blue set-color:blue!))
|
2002-03-17 10:41:56 -05:00
|
|
|
|
2003-03-13 08:47:17 -05:00
|
|
|
(define-exported-binding "scx-color" :color)
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-enumerated-type colormap-state :colormap-state
|
|
|
|
colormap-state? colormap-states colormap-state-name colormap-state-index
|
|
|
|
(uninstalled installed))
|
2002-03-17 10:41:56 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-exported-binding "scx-colormap-state" :colormap-state)
|
|
|
|
(define-exported-binding "scx-colormap-states" colormap-states)
|
2001-07-16 09:37:28 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; *** create, copy, or destroy colormaps ****************************
|
2001-06-11 11:28:32 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-enumerated-type colormap-alloc :colormap-alloc
|
|
|
|
colormap-alloc? colormap-allocs colormap-alloc-name colormap-alloc-index
|
|
|
|
(none all))
|
|
|
|
|
2003-03-25 13:27:18 -05:00
|
|
|
(define-exported-binding "scx-colormap-alloc" :colormap-alloc)
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function create-colormap (display window visual alloc)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Create_Colormap")
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function copy-colormap-and-free (display colormap)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Copy_Colormap_And_Free")
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function free-colormap (display colormap)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Free_Colormap")
|
|
|
|
|
|
|
|
;; *** allocate and free colors **************************************
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function alloc-color! (display colormap color)
|
2001-07-31 10:54:53 -04:00
|
|
|
"scx_Alloc_Color")
|
2001-06-11 11:28:32 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; red, green and blue can be a number between 0 (inclusive) and 1
|
|
|
|
;; (exclusive), or #f
|
|
|
|
(define (alloc-color display colormap red green blue)
|
|
|
|
(let ((color (make-color 0 red green blue)))
|
|
|
|
(and (alloc-color! display colormap color)
|
|
|
|
(color:pixel color))))
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function %alloc-named-color (display colormap color-name)
|
2001-08-22 10:53:08 -04:00
|
|
|
"scx_Alloc_Named_Color")
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; returns a pair (screen-color exact-color) or #f
|
|
|
|
(define alloc-named-color/exact %alloc-named-color)
|
2001-09-20 10:41:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; returns a color or #f
|
|
|
|
(define (alloc-named-color display colormap color-name)
|
|
|
|
(let ((res (alloc-named-color/exact display colormap color-name)))
|
|
|
|
(and res (car res))))
|
2001-09-20 10:41:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; returns a pair of two lists (plane-masks . pixels) or #f
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function alloc-color-cells/planes
|
2003-03-10 21:47:38 -05:00
|
|
|
(display colormap contig? nplanes npixels)
|
|
|
|
"scx_Alloc_Color_Cells")
|
2001-09-20 10:41:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (alloc-color-cells display colormap contig? npixels)
|
|
|
|
(let ((r (alloc-color-cells/planes display colormap contig? 0 npixels)))
|
|
|
|
(and r (cdr r))))
|
2001-09-20 10:41:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; returns a list of lists (pixels redmask greenmask bluemask) or #f
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function alloc-color-planes
|
2003-03-10 21:47:38 -05:00
|
|
|
(display colormap contig? ncolors nreds ngreens nblues)
|
|
|
|
"scx_Alloc_Color_Planes")
|
2002-03-17 10:41:56 -05:00
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function free-colors (display colormap pixels planes)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Free_Colors")
|
|
|
|
|
|
|
|
;; *** obtain color values *******************************************
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function query-colors! (display colormap colors)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Query_Colors")
|
|
|
|
|
|
|
|
(define (query-colors display colormap pixels)
|
|
|
|
(let ((colors (map (lambda (pixel) (make-color pixel #f #f #f)) pixels)))
|
|
|
|
(query-colors! display colormap colors)
|
|
|
|
colors))
|
|
|
|
|
|
|
|
(define (query-color! display colormap color)
|
|
|
|
(query-colors! display colormap (list color)))
|
2001-09-20 10:41:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (query-color display colormap pixel)
|
|
|
|
(car (query-colors display colormap (list pixel))))
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function lookup-color (display colormap color-name)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Lookup_Color")
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function parse-color (display colormap spec)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Parse_Color")
|
|
|
|
|
|
|
|
;; *** set colors ****************************************************
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function store-colors (display colormap colors)
|
2001-10-09 11:31:33 -04:00
|
|
|
"scx_Store_Colors")
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (store-color display colormap color)
|
|
|
|
(store-colors display colormap (list color)))
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function %store-named-color
|
2003-03-10 21:47:38 -05:00
|
|
|
(display colormap color-name pixel do-red do-green do-blue)
|
|
|
|
"scx_Store_Named_Color")
|
2001-10-09 11:31:33 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (store-named-color display colormap color-name pixel . args)
|
|
|
|
(let ((flags (cond
|
|
|
|
((null? args) '(#f #f #f))
|
|
|
|
((= 3 (length args)) args)
|
|
|
|
(else (error "invalid optional arguments" args))))) ;;TODO??
|
|
|
|
(%store-named-color display colormap color-name pixel
|
|
|
|
(car flags) (cadr flags) (caddr flags))))
|