home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / lisp / mcl / 2090 < prev    next >
Encoding:
Text File  |  1993-01-25  |  3.6 KB  |  96 lines

  1. Path: sparky!uunet!olivea!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: Windows vs. color-dialogs and getting a cpixel value
  5. Message-ID: <9301251541.AA21219@cambridge.apple.com>
  6. Date: 25 Jan 93 16:48:24 GMT
  7. Sender: owner-info-mcl@cambridge.apple.com
  8. Lines: 85
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. At 13:15 1/23/93 -0500, mdavis@media.mit.edu wrote:
  12. >Hi,
  13. >
  14. >I am really stumped on something.  I have written a simple
  15. >color-dropper function which allows the user to get a color by
  16. >positioning an eye-dropper cursor on a point and clicking to get its
  17. >color value.  The problem I have is that this function returns the
  18. >correct color when defined as the dialog-item-action of a button when
  19. >that button is the subview of a window, but not when the button is the
  20. >subview of a color-dialog (it just seems to return black or white).
  21. >What is going on here?
  22. >
  23. >Marc Davis
  24. >MIT Media Lab
  25. >
  26.  
  27. The problem was that your get-color-with-color-dropper function was
  28. using the global mouse position and the currently focused view.
  29. Since it was called from inside of:
  30.  
  31.   (method view-click-event-handler (button-dialog-item)
  32.  
  33. it ended up being focused on the right window, but it appeared to
  34. work for the window and not the color-dialog, because the window
  35. was near the upper-left hand corner of the screen where window
  36. coordinates are similar to global (screen) coordinates. The following
  37. works for both:
  38.  
  39. To: info-mcl@media.mit.edu
  40. Cc: mdavis@media.mit.edu
  41. Subject: Windows vs. color-dialogs and getting a cpixel value
  42. Date: Sat, 23 Jan 93 13:15:58 -0500
  43. From: mdavis@media.mit.edu
  44. X-Mts: smtp
  45.  
  46.  
  47. Hi,
  48.  
  49. I am really stumped on something.  I have written a simple
  50. color-dropper function which allows the user to get a color by
  51. positioning an eye-dropper cursor on a point and clicking to get its
  52. color value.  The problem I have is that this function returns the
  53. correct color when defined as the dialog-item-action of a button when
  54. that button is the subview of a window, but not when the button is the
  55. subview of a color-dialog (it just seems to return black or white).
  56. What is going on here?
  57.  
  58. Marc Davis
  59. MIT Media Lab
  60.  
  61. ;function to get a color value at an x y
  62. (defun getcpixelcolorvalue (x y)
  63.     (with-rgb (rgb *black-color*)
  64.               (#_getcpixel x y rgb)
  65.               (rgb-to-color rgb)))
  66.  
  67. ;Code to get a color value by clicking on a point 
  68. ;put your favorite cursor in here 
  69. ;(we took one from Studio 8, the *watch-cursor* from MCL works too.
  70.  
  71. (defvar *color-dropper-cursor* *watch-cursor*)
  72.  
  73. (defun get-color-with-color-dropper (window &optional (color-dropper-cursor *color-dropper-cursor*))
  74.   (with-focused-view window
  75.     (with-cursor color-dropper-cursor
  76.       (do ()
  77.           ((mouse-down-p)
  78.            (let ((mouse-position (view-mouse-position window)))
  79.              (getcpixelcolorvalue (point-h mouse-position)
  80.                                   (point-v mouse-position))))))))
  81.  
  82. (make-instance 'window
  83.      :view-subviews (list (make-instance 'button-dialog-item
  84.                 :dialog-item-action 
  85.                 #'(lambda (item)
  86.                         (declare (ignore item))
  87.                         (pprint (get-color-with-color-dropper
  88.                                   (view-window item)))))))
  89. (make-instance 'color-dialog
  90.      :view-subviews (list (make-instance 'button-dialog-item
  91.                 :dialog-item-action
  92.                 #'(lambda (item)
  93.                         (declare (ignore item))
  94.                         (pprint (get-color-with-color-dropper
  95.                                   (view-window item)))))))
  96.