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

Re: Painting regions then saving them

On Friday 29 APR, Kemi Jona writes
  ... a better description of my problem is how does one display quickdraw
  commands *simultaneously* to both the screen and to a picture? 

  Or is there a better way to do this than with _OpenPicture?  Are regions
  the answer?
If you want to be able to do the following simultaneously: (1) draw
in a window and (2) save the drawing so that it can be redisplayed, you'll
need to save the "commands" the designer made to indicate the picture.
In your example, you'll need to save the locations of the endpoints
of line segments. Here's a brief overview of how to do this:
1. draw the lines as you have been doing
2. while drawing the lines, save the endpoints by for example pushing
   them onto a stack (push point stack). Stack could of course be a slot
   within the window.
3. when the designer is finished, reverse the endpoints, convert them
   into a picture by the sequence of starting a picture, drawing the commands,
   closing the picture. Save the resulting picture in a slot within the
   window. Just be careful to (kill-picture the-slot) before you begin.
Another possibility is to do a qdoffscreen call to create a picture
at the same time. However, this had the disadvantage of requiring you
to switch contexts.

Here's a revised copy of the view-click-handler you enclosed in your


(defvar *positions* nil)                    ; change to a window-slot
(defvar *current-pattern* *black-pattern*)  ; change to a window-slot
(defmethod view-click-event-handler ((win paint-window) where)
  (if (eq (find-view-containing-point win where) win)
  (with-focused-view win
           with oldpenloc = where and penloc = where
           initially do (setq *positions* `(,where))
                        (#_moveTo : long where)
           unless (mouse-down-p) do (return)
           unless (= penloc oldpenloc)
           do   (with-pen-state (:pnpixpat *current-pattern*
                                          :pnsize #@(15 15)
                                          :pnloc penloc)
                   (#_Lineto :long  penloc)))
                 (setq oldpenloc penloc)
                 (push penloc *positions*))
           do (setq penloc (view-mouse-position win))))))