FROM : Douglas Davidson
DATE : Wed Apr 06 21:49:04 2005
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
DATE : Wed Apr 06 21:49:04 2005
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
| Related mails | Author | Date |
|---|---|---|
| Keith Blount | Apr 6, 19:25 | |
| Douglas Davidson | Apr 6, 21:49 |






Cocoa mail archive

