;;;; ;;;; C o l o r b o x . s t k l o s -- A color pcicker ;;;; ;;;; Copyright © 1998 Erick Gallesio - I3S-CNRS/ESSI ;;;; ;;;; Permission to use, copy, and/or distribute this software and its ;;;; documentation for any purpose and without fee is hereby granted, provided ;;;; that both the above copyright notice and this permission notice appear in ;;;; all copies and derived works. Fees for distribution or use of this ;;;; software or derived works may only be charged with express written ;;;; permission of the copyright holder. ;;;; This software is provided ``as is'' without express or implied warranty. ;;;; ;;;; $Id: Colorbox.stklos 1.2 Mon, 16 Feb 1998 07:28:39 +0000 eg $ ;;;; ;;;; Author: Erick Gallesio [eg@unice.fr] ;;;; Creation date: 2-Jan-1998 14:00 ;;;; Last file update: 12-Feb-1998 15:50 (require "Basics") (select-module STklos+Tk) (export colorbox-wait-result) ;============================================================================= ; ; < C o l o r - b o x > ; ;============================================================================= ;;;; ;;;; Resources ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; Utilities ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define colorbox-lock #f) (define (colorbox-set! box v update-scales?) (let ((entry (slot-ref box 'entry)) (sample (slot-ref box 'sample))) (set! (background sample) v) (if update-scales? ;; Convert the value in RGB (let ((colors (winfo 'rgb box v))) (set! (value (slot-ref box 'R)) (modulo (car colors) 256)) (set! (value (slot-ref box 'G)) (modulo (cadr colors) 256)) (set! (value (slot-ref box 'B)) (modulo (caddr colors) 256)) ;; Update to be sure that the scales have moved (and set the ;; entry accordingly), and afer that, force the value of the entry. (update 'idletask))) (set! (value entry) v))) (define (colorbox-set-scale-callback box R G B) (let* ((color (lambda (s) (let ((n (value s))) (string-append (if (>= n 16) "" "0") (number->string n 16))))) (callback (lambda l (colorbox-set! box (format #f "#~A~A~A" (color R)(color G)(color B)) #f)))) (slot-set! R 'command callback) (slot-set! G 'command callback) (slot-set! B 'command callback))) (define (colorbox-wait-result cb) (let ((cur-grab (grab 'current cb))) (grab 'set cb) (tkwait 'variable 'colorbox-lock) (and cur-grab (grab 'set cur-grab)) ;; Compute result (case colorbox-lock ((ok) (let ((res (value cb))) (destroy cb) res)) ((cancel) (destroy cb) #f) ((destroy) #f)))) (define (colorbox-make-scale name box parent) (let* ((f (make :parent parent)) (title (make