NSDrawNinePartImage draws slowly in CALayer
NSDrawNinePartImage draws slowly in CALayer
- Subject: NSDrawNinePartImage draws slowly in CALayer
- From: Sebastian Morsch <email@hidden>
- Date: Fri, 06 Mar 2009 20:33:15 +0100
Hello,
I wrote a delegate that draws a bezel inside a CALayer using
NSDrawNinePartImage. The drawing happens inside the
drawLayer:inContext: method and it works well. The only problem is
that it redraws really slow when the layers frame is resized by the
user.
The layer is simply attached to a custom view for testing the whole
thing. This view is the only view of a window, and when I resize that
window, my layer is resized too. But it feels very clunky.
I was wondering if I'm doing something really stupid here... Does
anybody know if there's a better way to tackle this?
Thank you!
Sebastian
There's no other code than these two methods in my custom view:
- (void)awakeFromNib {
CALayer *rootLayer = [CALayer layer];
rootLayer.delegate = self;
rootLayer.needsDisplayOnBoundsChange = YES;
[self setLayer:rootLayer];
[self setWantsLayer:YES];
[rootLayer setNeedsDisplay];
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
CGRect boundsRect = CGContextGetClipBoundingBox(ctx);
// Draw colored interior
CGRect bgRect = CGRectInset(boundsRect, 1.0, 1.0);
CGColorRef color = CGColorCreateGenericRGB(0.0, 0.0, 1.0, 0.2);
CGContextSetFillColorWithColor(ctx, color);
CGContextFillRect(ctx, bgRect);
// Draw bezel
NSDrawNinePartImage(
NSRectFromCGRect(boundsRect),
[NSImage imageNamed:@"ClipFrame-N-TL"],
[NSImage imageNamed:@"ClipFrame-N-T"],
[NSImage imageNamed:@"ClipFrame-N-TR"],
[NSImage imageNamed:@"ClipFrame-N-L"],
[NSImage imageNamed:@"ClipFrame-N-C"],
[NSImage imageNamed:@"ClipFrame-N-R"],
[NSImage imageNamed:@"ClipFrame-N-BL"],
[NSImage imageNamed:@"ClipFrame-N-B"],
[NSImage imageNamed:@"ClipFrame-N-BR"],
NSCompositeSourceOver,
1.0,
NO);
}
_______________________________________________
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