(defpackage :copy-from-pixmap-test
  (:use :clim-lisp :clim))

(in-package :copy-from-pixmap-test)

(defun run ()
  (run-frame-top-level (make-application-frame 'copy-from-pixmap-test)))

(define-application-frame copy-from-pixmap-test ()
  ()
  (:menu-bar nil)
  (:panes
   (canvas :application :display-time nil :background +white+ 
	   :width 300 :height 300))
  (:layouts
   (:main canvas)))

(defmethod handle-repaint :after ((pane application-pane) region)
  (declare (ignore region))
  (let (temp-pixmap target-pixmap)
    (unwind-protect
	 (progn
	   (setq temp-pixmap
		 (with-output-to-pixmap (mv pane :width 200 :height 200)
		   (draw-rectangle* mv 0 0 199 199 :filled t :ink +yellow+)
		   (draw-circle* mv 100 100 50 :filled t :ink +blue+)))
	   (setq target-pixmap
		 (with-output-to-pixmap (mv pane :width 200 :height 200)
		   (copy-from-pixmap temp-pixmap 0 0 199 199 mv 0 0)
		   (draw-circle* mv 100 100 30 :filled t :ink +black+)))
	   (copy-from-pixmap target-pixmap 0 0 199 199 pane 0 0))
      (deallocate-pixmap temp-pixmap)
      (deallocate-pixmap target-pixmap))))