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

Re: clip-region interaction with princ

At 10:33 AM 12/29/93 -0500, Peter Szolovits wrote:
>I need to clip text to a region (really a rect) in a window, but it seems that
>the standard princ function applied to a window does not obey the clip region.
>E.g., if you evaluate the following code, the paint-rect is properly clipped,
>but the princ is not.
>(defclass foowin (window) ())
>(defparameter w1 (make-instance 'foowin))
>(defmethod view-draw-contents :after ((w foowin))
>  (with-region rgn
>    (clip-region w rgn)
>    (clip-rect w 100 100 150 150)
>    (paint-rect w 90 90 140 210)
>    (#_MoveTo 102 110)
>    (princ "The quick brown fox did something?" w)
>    (set-clip-region w rgn))
>  )
>Am I misunderstanding something, or is this a bug?  In either case, is there
>anything simple to do short of creating a static-text-dialog-item of the right
>size and using that?  (I'd prefer not to have to do that, and I'd also prefer
>not having to figure out how to truncate the string to the right length to fit
>in its "cell".)

Mark Tapia & Doug Currie gave solutions that will work (though Doug forgot
to set the font), but I think your example illustrates a bug in FOCUS-VIEW.
Currently, if either the view or the font-view are different it does the
entire focusing gig: set-gworld, #_SetOrigin, #_SetClip, and set the font.
Since PRINC is eventually calling STREAM-WRITE-STRING, the SIMPLE-VIEW
method for which executes its body inside of a WITH-FONT-FOCUSED-VIEW,
the view is refocused (VIEW-DRAW-CONTENTS is executed inside a
WITH-FOCUSED-VIEW, hence CALL-WITH-FOCUSED-VIEW will notice that the font
has not yet been focused and will call FOCUS-VIEW). I think that FOCUS-VIEW
should skip the set-gworld, #_SetOrigin, & #_SetClip if the only thing changing
is the font-view. I have prepared a patch that makes your example work as
written (modulo defining the WITH-REGION macro, which is not part of MCL). If
you want it, ask for "focused-clip-region-patch".