Re: Tracking visibleRect changes using Autolayout
Re: Tracking visibleRect changes using Autolayout
- Subject: Re: Tracking visibleRect changes using Autolayout
- From: Kyle Sluder <email@hidden>
- Date: Mon, 18 Feb 2013 08:41:20 -0800
Resending to the list.
On Feb 18, 2013, at 2:50 AM, iain <email@hidden> wrote:
>
>
> On Mon, Feb 18, 2013 at 7:17 PM, Kyle Sluder <email@hidden> wrote:
>> On Sun, Feb 17, 2013, at 11:46 PM, iain wrote:
>> > I'll give this a go, does -setFrameSize just deal with the visible
>> > portion
>> > when inside an NSScrollView/NSClipView? If so, thank you, that's great.
>>
>> No. You're missing my point.
>>
>> You have -viewWillDraw, an override point at which you know your view
>> will draw. You don't need to track your visible rect. You will only be
>> asked to draw rects that intersect with your visible rect[1]. Just query
>> -getRectsBeingDrawn:count: from within -drawRect, and render your
>> waveform for those rects.
>
> Well, that's essentially what I'm doing, by only drawing in the dirtyRect (yeah, I know that's just one big union of the results of getRectsBeingDrawn, but "essentially").
Right, but you're missing the crucial step of caching this drawing.
I'm obviously not being clear. Here's some pseudocode:
- setFrameSize:(NSSize)size {
[super setFrameSize:size];
[self discardEntireWaveformCache];
}
- setNeedsDisplayInRect:(NSRect)rect {
[super setNeedsDisplayInRect:rect];
[self invalidateWaveformCacheForReft:rect];
}
- viewWillDraw {
if ([self waveformCacheDiscarded]) {
[self allocateWaveformCacheOfSize:self.bounds.size];
}
for (NSRect rect in [self getRectsBeingDrawn]) {
if (!([self waveformCacheIsValidForRect:rect])) {
[self cacheWaveformForRect:rect];
}
}
}
- drawRect:(NSRect)unused {
for (NSRect rect in [self getRectsBeingDrawn]) {
[self drawWaveformCacheForRect:rect];
}
}
Implementation of the waveform cache, as well as more sophisticated techniques like background rendering the waveform cache are left as exercises to the reader.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden