187 lines
6.3 KiB
Scheme
187 lines
6.3 KiB
Scheme
;; Author: David Frese
|
|
|
|
;; special colormaps
|
|
|
|
(define (special-colormap:none dpy)
|
|
(make-colormap 0 dpy #f))
|
|
|
|
;; alloc-color returns the pixel closest to the specified color
|
|
;; supported by the hardware. See XAllocColor. The color parameter is
|
|
;; mutated!
|
|
|
|
(define (alloc-color! colormap color)
|
|
(let ((Xpixel (%alloc-color (colormap-Xcolormap colormap)
|
|
(color-Xcolor color)
|
|
(display-Xdisplay (colormap-display colormap)))))
|
|
(if Xpixel
|
|
(make-pixel Xpixel colormap #t)
|
|
Xpixel)))
|
|
|
|
(import-lambda-definition %alloc-color (Xcolormap Xcolor Xdisplay)
|
|
"scx_Alloc_Color")
|
|
|
|
;; query/alloc-named-color looks up the named color with respect to
|
|
;; the screen that is associated with the specified colormap. It
|
|
;; returns the allocated pixel and both the exact database definition
|
|
;; and the closest color supported by the screen (as a list). See
|
|
;; XAllocNamedColor.
|
|
|
|
(define (query/alloc-named-color colormap color-name)
|
|
(let ((Xres (%alloc-named-color (colormap-Xcolormap colormap)
|
|
(if (symbol? color-name)
|
|
(symbol->string color-name)
|
|
color-name)
|
|
(display-Xdisplay
|
|
(colormap-display colormap)))))
|
|
(if Xres
|
|
(list (make-pixel (car Xres) colormap #t)
|
|
(apply create-color (cadr Xres))
|
|
(apply create-color (caddr Xres)))
|
|
Xres)))
|
|
|
|
(import-lambda-definition %alloc-named-color (Xcolormap name Xdisplay)
|
|
"scx_Alloc_Named_Color")
|
|
|
|
;; alloc-named-color only allocates a named color and returns the
|
|
;; allocated pixel (as one might suppose). If the color does not
|
|
;; exists it returns #f.
|
|
|
|
(define (alloc-named-color colormap color-name)
|
|
(let ((c (parse-color colormap color-name)))
|
|
(if c
|
|
(alloc-color! colormap c)
|
|
#f)))
|
|
|
|
;; parse-color looks up the string name of a color and returns the
|
|
;; exact color value. See XParseColor. See lookup-color.
|
|
|
|
(define (parse-color colormap color-name)
|
|
(let ((res (%parse-color (display-Xdisplay (colormap-display colormap))
|
|
(colormap-Xcolormap colormap)
|
|
(if (symbol? color-name)
|
|
(symbol->string color-name)
|
|
color-name))))
|
|
(if res
|
|
(create-color (vector-ref res 0)
|
|
(vector-ref res 1)
|
|
(vector-ref res 2))
|
|
#f)))
|
|
|
|
(import-lambda-definition %parse-color (Xdisplay Xcolormap string)
|
|
"scx_Parse_Color")
|
|
|
|
;; The create-colormap function creates a colormap of the specified
|
|
;; visual type for the screen on which the specified window resides.
|
|
;; alloc can be (colormap-alloc none) or (colormap-alloc all). See
|
|
;; XCreateColormap.
|
|
|
|
(define (create-colormap window visual alloc)
|
|
(let ((Xcolormap (%create-colormap (display-Xdisplay (window-display window))
|
|
(window-Xwindow window)
|
|
(visual-Xvisual visual)
|
|
(colormap-alloc->integer alloc))))
|
|
(make-colormap Xcolormap (window-display window) #t)))
|
|
|
|
(import-lambda-definition %create-colormap (Xdisplay Xwindow Xvisual alloc)
|
|
"scx_Create_Colormap")
|
|
|
|
(define-enumerated-type colormap-alloc :colormap-alloc
|
|
colormap-alloc? colormap-allocs colormap-alloc-name colormap-alloc-index
|
|
(none all))
|
|
|
|
(define (colormap-alloc->integer v)
|
|
(colormap-alloc-index v))
|
|
|
|
;; The alloc-color-cells function allocates read/write color cells.
|
|
;; The number of colors must be positive and the number of planes
|
|
;; nonnegative, or a BadValue error results. See XAllocColorCells.
|
|
;; The return value is a pair who's car is the list of the planes
|
|
;; (integers), and who's cdr is a list of the pixels.
|
|
|
|
(define (alloc-color-cells colormap contigous nplanes npixels)
|
|
(let ((res (%alloc-color-cells (display-Xdisplay (colormap-display colormap))
|
|
(colormap-Xcolormap colormap)
|
|
contigous
|
|
nplanes npixels)))
|
|
(if res
|
|
(cons (vector->list (car res))
|
|
(map (lambda (Xpixel)
|
|
(make-pixel Xpixel colormap #t))
|
|
(vector->list (cdr res))))
|
|
res)))
|
|
|
|
(import-lambda-definition %alloc-color-cells (Xdisplay Xcolormap contig
|
|
nplanes npixels)
|
|
"scx_Alloc_Color_Cells")
|
|
|
|
;; The store-color function uses XStoreColor(s) to set the content
|
|
;; of the color cell specified by pixel (a pixel is an index to a
|
|
;; colormap) to color. An optional parameter is a list of the symbols
|
|
;; 'do-red 'do-gree and 'do-blue, that specify which components of the
|
|
;; color should be used. It defaults to '(do-red do-green
|
|
;; do-blue). See XStoreColors.
|
|
|
|
(define (store-color colormap pixel color . flags)
|
|
(%store-color (display-Xdisplay (colormap-display colormap))
|
|
(colormap-Xcolormap colormap)
|
|
(pixel-Xpixel pixel) (color-Xcolor color)
|
|
(color-flags->integer
|
|
(if (null? flags)
|
|
'(do-red do-green do-blue)
|
|
(car flags)))))
|
|
|
|
(define (color-flags->integer flags)
|
|
(fold-right (lambda (s res)
|
|
(case s
|
|
((do-red) (bitwise-ior res 1))
|
|
((do-green) (bitwise-ior res 2))
|
|
((do-blue) (bitwise-ior res 4))
|
|
(else (error "illegal color-flag" s))))
|
|
0 flags))
|
|
|
|
(import-lambda-definition %store-color (Xdisplay Xcolormap Xpixel Xcolor
|
|
flags)
|
|
"scx_Store_Color")
|
|
|
|
;; store-colors does the same as store-color, but for multiple
|
|
;; colorcells. The paramter cells must be a list of lists consisting
|
|
;; of 2 or 3 elements: a pixel, a color and an optional flags list
|
|
;; (see above).
|
|
|
|
(define (store-colors colormap cells)
|
|
(let ((cells (list->vector
|
|
(map (lambda (p-c-f)
|
|
(list->vector
|
|
(list (pixel-Xpixel (car p-c-f))
|
|
(color-Xcolor (cadr p-c-f))
|
|
(color-flags->integer
|
|
(if (null? (cddr p-c-f))
|
|
'(do-red do-green do-blue)
|
|
(caddr p-c-f))))))
|
|
cells))))
|
|
(%store-colors (display-Xdisplay (colormap-display colormap))
|
|
(colormap-Xcolormap colormap)
|
|
cells)))
|
|
|
|
(import-lambda-definition %store-colors (Xdisplay Xcolormap cells)
|
|
"scx_Store_Colors")
|
|
|
|
;; copy-colormap-and-free function creates a colormap of the same
|
|
;; visual type and for the same screen as the specified colormap and
|
|
;; returns the new colormap. It also moves all of the client's
|
|
;; existing allocation from the specified colormap to the new colormap
|
|
;; with their color values intact and their read-only or writable
|
|
;; characteristics intact and frees those entries in the specified
|
|
;; colormap. See XCopyColormapAndFree
|
|
|
|
(define (copy-colormap-and-free colormap)
|
|
(make-colormap (%copy-colormap-and-free
|
|
(display-Xdisplay (colormap-display colormap))
|
|
(colormap-Xcolormap colormap))
|
|
(colormap-display colormap)
|
|
#t))
|
|
|
|
(import-lambda-definition %copy-colormap-and-free (Xdisplay Xcolormap)
|
|
"scx_Copy_Colormap_And_Free")
|
|
|