(in-package "CLIM-USER")

(defparameter *foo-stuff* (list 1 2 3 4))

(define-application-frame foo ()
  ((outrecord :accessor outrecord :initform nil))
  (:panes
   (output-pane :application-pane
                :display-time :command-loop
                :display-function 'draw-foo-stuff)
   (interactor :interactor-pane))
  (:layouts
   (default (vertically (:width 640 :height 480) output-pane interactor))))

(defun draw-foo-stuff (frame stream)
  (if (outrecord frame)
      (redisplay (outrecord frame) stream)
      (setf (outrecord frame)
            (updating-output (stream)
              (with-first-quadrant-coordinates (stream)
                (let ((i 1))
                  (dolist (stuff *foo-stuff*)
                    (setf (stream-cursor-position stream)
                          (values 30 (* i -20)))
                    (updating-output (stream :cache-value stuff :unique-id stuff)
                      (draw-text* stream (format nil "~A" stuff) 0 (* i -20)))
                    (incf i))))))))

(define-foo-command (com-toggle-foo-stuff :menu "Toggle Stuff") ()
  (if (equal *foo-stuff* '(1 2 3 4))
      (setf *foo-stuff* (list 12 3 4))
      (setf *foo-stuff* (list 1 2 3 4))))

(defparameter *bar-stuff* '(1 2 3 4))

(define-application-frame bar ()
  ((outrecord :accessor outrecord :initform nil))
  (:panes
   (output-pane :application-pane
                :display-time :command-loop
                :display-function 'draw-bar-stuff)
   (interactor :interactor-pane))
  (:layouts
   (default (vertically (:width 640 :height 480) output-pane interactor))))

(defun draw-bar-stuff (frame stream)
  (if (outrecord frame)
      (redisplay (outrecord frame) stream)
      (setf (outrecord frame)
            (updating-output (stream)
              (let ((i 1))
                (dolist (stuff *bar-stuff*)
                  (setf (stream-cursor-position stream)
                        (values 30 (* i 20)))
                  (updating-output (stream :cache-value stuff :unique-id stuff)
                    (draw-text* stream (format nil "~A" stuff) 0 (* i 20)))
                  (incf i)))))))

(define-bar-command (com-toggle-bar-stuff :menu "Toggle Stuff") ()
  (if (equal *bar-stuff* '(1 2 3 4))
      (setf *bar-stuff* (list 12 3 4))
      (setf *bar-stuff* (list 1 2 3 4))))

