Re: Forcing drawViewBackgroundInRect to display on text change...
Re: Forcing drawViewBackgroundInRect to display on text change...
- Subject: Re: Forcing drawViewBackgroundInRect to display on text change...
- From: Douglas Davidson <email@hidden>
- Date: Wed, 6 Apr 2005 12:49:04 -0700
On Apr 6, 2005, at 10:25 AM, Keith Blount wrote:
Hello,
I have an NSTextView subclass that uses
drawViewBackgroundInRect: to draw rectangles with
corners around ranges of text with certain attributes.
To do this, in my drawViewBackgroundInRect: override
method, I get the ranges I need to draw around, and
then get the rects for these ranges using
NSLayoutManager's rectArrayForCharacterRange:...
method. Then I go about merging these rects and
rounding the corners of the resulting shape - which
will obviously be an irregular shape if the range
stretches across several lines, with its start and end
part way through lines.
The trouble is, when I type before or inside these
ranges of text, the background drawing doesn't update
properly. The selection follows the text okay, but
when text drops off to the next line, the drawing at
the edges isn't updated - strange, as
drawViewBackgroundInRect does seem to get called. I
tried forcing drawViewBackgroundInRect to update [self
visibleRect] instead of just the passed-in rect, but
this made no difference.
The only way I have found to force the display to
update properly on edits is by overriding
didChangeText and calling [self setNeedsDisplay:YES],
but this seems rather brute force and not the optimal
way of doing things.
I'm not sure I entirely understand, but the first thing I would take
a look at is whether the rect you are being passed includes the
entire region that you want to draw. drawViewBackgroundInRect: is
called from within drawRect:, and its drawing will generally be
clipped to the rect being drawn. NSTextView will automatically mark
itself dirty in regions needed to display any text that has changed,
but if you are drawing outside of the text then you may need to call
setNeedsDisplayInRect: on your view with any rects that need updating.
Douglas Davidson
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden