(ql:quickload :clim)
(ql:quickload :clouseau)

(in-package :clim-user)

(defparameter *ink*
  #+NIL +red+
  #-NIL +flipping-ink+)

(define-application-frame test ()
  ()
  (:panes
   (main :application)))
 
(define-test-command (rubberband :menu t) ()
  (let ((x1 0) ;; x1, y1 represents the fix point
        (y1 0)
        (x2 0) ;; x2,y2 represents the point that is changing
        (y2 0)
        (mouse-button-press nil) ;; set to T when mouse button has
        ;; press to select pivot
        (stream (get-frame-pane *application-frame* 'main)))
    (tracking-pointer
     (stream)
     (:pointer-button-press
      (&key event x y)
      (setf x1 x
            y1 y
            x2 x
            y2 y)
      (draw-rectangle* stream x1 y1 x2 y2 :ink *ink* :filled nil)
      (setf mouse-button-press t))
     (:pointer-motion
      (&key window x y)
      (when mouse-button-press
	;;erase
	(draw-rectangle* stream x1 y1 x2 y2 :ink *ink* :filled nil)
	;; draw
	(draw-rectangle* stream x1 y1 x y :ink *ink* :filled nil)
	(setf x2 x y2 y)))
     (:pointer-button-release
      (&key event x y)
      (when mouse-button-press
	(clouseau:inspect event)
	(return-from rubberband (list x1 y1 x2 y2)))))))

;;(define-test-command (com-exit :menu "EXEUNT" :keystroke #-)
(define-test-command (com-exit :menu "EXEUNT")
    ()
  (frame-exit *application-frame*))

(let ((frame (make-application-frame 'test)))
  (run-frame-top-level frame))
  
