Hi All,

I recently posted a message with subject "View with Subviews + Drawing on top of everything" and I got convinced to use CALayers in my view instead of NSView's.

summary: I added few CALayers to myView and tried to resize myView and result was rusty and snaggy. When I used NSView's (initially) even adding 120-150 NSView's was faster and responsive. I assumed using CALayer (instead of NSView's) makes my app faster and more responsive with appealing looks and animations but my code seems made the opposite of fast (http://theocacao.com/document.page/ 595 )
 There could be some possible flaw or I misunderstood the concept.

but the code is simple as of now ( I have to do lot of animation and image additions in future ) still myView is slow ,
 Shark app shows (If, of any use )
        8.0%    8.0%    CoreGraphics    sseCGSFill8by1  
        3.0%    3.0%    CoreGraphics    sse64CGSFill8by1        
        2.6%    2.6%    ATIRadeonX1000GLDriver  gldInitDispatch 
        2.4%    2.4%    mach_kernel     ml_set_interrupts_enabled       
        1.9%    1.9%    ATIRadeonX1000GLDriver  gldUpdateDispatch       

Quartz Debug.app shows a too much delay in updating the myView.
Any help is appreciated.

Thanks
Rajesh

Code:
@implementation MyView
-(void)awakeFromNib
{
        pages = [[NSMutableArray alloc] init];
        rootLayer = [[CALayer layer] retain];
        rootLayer.name = @"root";
        rootLayer.backgroundColor = CGColorCreateGenericRGB(1.0,1.0,1.0,1.0);
        [self setLayer:rootLayer];
        [self setWantsLayer:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleFrameChange:) name:NSViewFrameDidChangeNotification object:self];

}

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}
- (void)handleFrameChange:(NSNotification *)aNotification
{
        [self layout];
}
-(IBAction)addPage:(id)sender
{
        CALayer *page = [PageLayer create];
        [pages addObject:page];
        page.name = [NSString stringWithFormat:@"%d",[pages count]+1];
        [self layout];

}
- (BOOL)isFlipped
{
        return YES;
}
- (void) mouseDown: (NSEvent*)ev
{
        NSPoint pt = [ev locationInWindow];
        CALayer *layer = [rootLayer hitTest:NSPointToCGPoint(pt)];
}

-(void)layout
{
        NSEnumerator *pageEnumr = [pages objectEnumerator];
        id pg;
        float widthMargin = [self frame].size.width;
        NSRect rect;
        while(pg = [pageEnumr nextObject])
        {
                
                rect = [pg bounds];
                rect.origin.x = x;
                rect.origin.y = y;
                [pg setFrame:rect];

                x += rect.size.width + spacing;
                if ( x  >= widthMargin )
                {
                        x = xOffset;
                        y += rect.size.height + spacing ;
                }
                [rootLayer addSublayer:pg];
        }

}
@end


@implementation PageLayer
+(CALayer *)create
{
        
        CALayer* myLayer = [CALayer layer];
                myLayer.bounds = CGRectMake(0, 0, 150, 200);
                myLayer.borderWidth = 1.0f ;
                myLayer.borderColor = CGColorCreateGenericRGB(0.0,0.0,0.0,0.9);
                myLayer.backgroundColor = CGColorCreateGenericGray(0.7, 1.0);
                myLayer.name = @"page";
        return myLayer;
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to