[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Windows vs. color-dialogs and getting a cpixel value
- To: mdavis@media.mit.edu
 
- Subject: Re: Windows vs. color-dialogs and getting a cpixel value
 
- From: bill@cambridge.apple.com (Bill St. Clair)
 
- Date: Mon, 25 Jan 1993 10:48:24 -0600
 
- Cc: info-mcl
 
At 13:15 1/23/93 -0500, mdavis@media.mit.edu wrote:
>Hi,
>
>I am really stumped on something.  I have written a simple
>color-dropper function which allows the user to get a color by
>positioning an eye-dropper cursor on a point and clicking to get its
>color value.  The problem I have is that this function returns the
>correct color when defined as the dialog-item-action of a button when
>that button is the subview of a window, but not when the button is the
>subview of a color-dialog (it just seems to return black or white).
>What is going on here?
>
>Marc Davis
>MIT Media Lab
>
The problem was that your get-color-with-color-dropper function was
using the global mouse position and the currently focused view.
Since it was called from inside of:
  (method view-click-event-handler (button-dialog-item)
it ended up being focused on the right window, but it appeared to
work for the window and not the color-dialog, because the window
was near the upper-left hand corner of the screen where window
coordinates are similar to global (screen) coordinates. The following
works for both:
To: info-mcl@media.mit.edu
Cc: mdavis@media.mit.edu
Subject: Windows vs. color-dialogs and getting a cpixel value
Date: Sat, 23 Jan 93 13:15:58 -0500
From: mdavis@media.mit.edu
X-Mts: smtp
Hi,
I am really stumped on something.  I have written a simple
color-dropper function which allows the user to get a color by
positioning an eye-dropper cursor on a point and clicking to get its
color value.  The problem I have is that this function returns the
correct color when defined as the dialog-item-action of a button when
that button is the subview of a window, but not when the button is the
subview of a color-dialog (it just seems to return black or white).
What is going on here?
Marc Davis
MIT Media Lab
;function to get a color value at an x y
(defun getcpixelcolorvalue (x y)
    (with-rgb (rgb *black-color*)
              (#_getcpixel x y rgb)
              (rgb-to-color rgb)))
;Code to get a color value by clicking on a point 
;put your favorite cursor in here 
;(we took one from Studio 8, the *watch-cursor* from MCL works too.
(defvar *color-dropper-cursor* *watch-cursor*)
(defun get-color-with-color-dropper (window &optional (color-dropper-cursor *color-dropper-cursor*))
  (with-focused-view window
    (with-cursor color-dropper-cursor
      (do ()
          ((mouse-down-p)
           (let ((mouse-position (view-mouse-position window)))
             (getcpixelcolorvalue (point-h mouse-position)
                                  (point-v mouse-position))))))))
(make-instance 'window
     :view-subviews (list (make-instance 'button-dialog-item
                :dialog-item-action 
                #'(lambda (item)
                        (declare (ignore item))
                        (pprint (get-color-with-color-dropper
                                  (view-window item)))))))
(make-instance 'color-dialog
     :view-subviews (list (make-instance 'button-dialog-item
                :dialog-item-action
                #'(lambda (item)
                        (declare (ignore item))
                        (pprint (get-color-with-color-dropper
                                  (view-window item)))))))