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

Re: ccl:clip-rect has no effect?

Excerpts from internet.listserv.info-mcl: 26-Feb-94 ccl:clip-rect has no
effect? by Andrew N. Mickish@andrew 
> 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
> to get the desired effect?  Thanks for any advice,
Short Answer: you're doing it wrong.  with-focused-view resets the
              and so does paint-rect.

Long answer with some background:

Windows are the natural abstraction of the location of input and output
on the Macintosh.  I say natural because all input and output events are
associated with a port, which is a synonym for a window.

You usually want to parition windows into more than one region.  You
want this region to be drawn independantly of it's position on the
screen.  You also want drawing to this region to be clipped.  You would
also like seemless event-handling of mouse-clicks within this region. 
The MCL view system provides the view system for this purpose.

With the abstraction comes the cost of implementing it.  Before drawing
is done to a view, MCL calls with-focused-view to set things up for
drawing in that view.

When you call with-focused-view, MCL does the following:

1. Sets the port to the port associated with the view, in this case your
   so that drawing will not go to some random port.

2. Sets up the coordinate system so that (0,0) is aligned with the upper left 
   corner of the view, so that all drawing is done relative to (0,0).

3. Changes the font to the view's asscoiated font.

4. Sets the clip-region to the rectanglular region that defines the view.

Now the scary part:

All of calls in the ccl pacakge that do drawing, e.g.,
{paint | erase | frame}{rect | oval | arc},
and many others, call with-focused-view on their first argument, the
view, to ensure that the port is set up correctly for drawing to the
view.  Obviously, a tight loop that calls paint-rect 1000 times is doing
too much work.

Wrapping all drawing calls inside a with-focused-view and calling the
traps directly is the solution.  Example:

(defmethod bad ((view view))
  (dotimes (i 1000)
    (paint-rect view i i i i)))

(defmethod good ((view view))
  (with-focused-view view
    (dotimes (i 1000)
      (ccl::with-rectangle-arg (r i i i i)
        (#_PaintRect r)))))