;;;; ;;;; C o l o r b o x . s t k l o s -- A color pcicker ;;;; ;;;; Copyright © 1998-1999 Erick Gallesio - I3S-CNRS/ESSI ;;;; ;;;; Permission to use, copy, modify, distribute,and license this ;;;; software and its documentation for any purpose is hereby granted, ;;;; provided that existing copyright notices are retained in all ;;;; copies and that this notice is included verbatim in any ;;;; distributions. No written agreement, license, or royalty fee is ;;;; required for any of the authorized uses. ;;;; This software is provided ``AS IS'' without express or implied ;;;; warranty. ;;;; ;;;; Author: Erick Gallesio [eg@unice.fr] ;;;; Creation date: 2-Jan-1998 14:00 ;;;; Last file update: 3-Sep-1999 20:12 (eg) (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