[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ccl:clip-rect has no effect?



Attached is a straightforward use of ccl:clip-rect, but it doesn't affect
the graphics that are drawn in the window at all.  This example draws a
big rectangle in a window, but sets the clip-region so that only a section
of the rectangle should show up.  Instead, we get the whole rectangle, as if
I hadn't set the clip-region at all.

Am I using this function improperly, or should I be using a different function
to get the desired effect?  Thanks for any advice,

--Andrew Mickish


(in-package :COMMON-LISP-USER)

;; Load required MCL files
   (progn (require 'traps)
          (require 'interfaces)
          (require 'quickdraw)
          (ccl::require-interface 'quickdraw)
          (ccl::require-interface 'events)
          (terpri))
;;;
;;; Class that will be used for the main window
;;;
(defparameter *MAC-DRAWABLE*
  (defclass MAC-DRAWABLE
    (ccl:window)
    ((plist :initarg :plist
            :initform :plist-init))))


(defun MAC-draw-rectangle (drawable left top width height fill-color)
  (let* ((right (+ left width))
         (bottom (+ top height)))
    (ccl:with-focused-view drawable
      (ccl:with-fore-color fill-color
        (ccl:paint-rect drawable left top right bottom))
      )))


(defun MAC-create-window (parent-window x y width height title)
  (let ((drawable
             (make-instance 'MAC-DRAWABLE
               :view-position (ccl:make-point x y)
               :view-size (ccl:make-point width height)
               :close-box-p T
               :window-type :document-with-zoom
               :window-show NIL
               :window-title title
               :color-p T
               :plist NIL)))
    drawable))


(let ((counter -1))
  (defun next-color ()
    (incf counter)
    (case counter
      (0 ccl:*red-color*)
      (1 ccl:*green-color*)
      (2 ccl:*yellow-color*)
      (3 (setf counter -1)
         ccl:*blue-color*))))

(defun draw-colored-rect ()
  (MAC-draw-rectangle main 20 20 100 100 (next-color)))

(defun clip-it ()
  (ccl:clip-rect main 40 40 80 80))

;;;
;;;  Now show the undesirable behavior
;;;

;;;  Create a window
(setf main (mac-create-window NIL 515 45 200 150 "Main"))
(ccl:window-show main)

;;;  Draw the rectangle
(draw-colored-rect)

;;; For subsequent drawing of the rectangle, try setting the clip-region of
;;; the drawable so that only part of the rectangle is drawn.  But calling
;;; clip-it doesn't have any effect!
#|
(clip-it)
(draw-colored-rect)
|#