/*
 * MyViewWithLayerSubclassing.j
 *
 * Created by Philippe Laval on 2009/03/24.
 * Copyright 2009 Philippe Laval. All rights reserved.
 */

@import <Foundation/CPObject.j>

@import <AppKit/CPView.j>
@import <AppKit/CPColor.j>
@import <AppKit/CPGraphicsContext.j>

@import "MyCALayer.j"

@implementation MyViewWithLayerSubclassing : CPView 
{ 
	MyCALayer _rootLayer;
} 

- (id)initWithFrame:(CGRect)aFrame 
{ 
	self = [super initWithFrame:aFrame];
	if (self) 
	{ 
		// Tell that the view will use a layer to draw itself
		[self setWantsLayer:YES];
		// Create our subclass layer and associate the layer with the view
		_rootLayer = [[MyCALayer alloc] init];
		[self setLayer:_rootLayer];
		
		// We will use the builtin behaviour of the layer 
		// (if its background color is set, it will be used to fill its bounds)
		[_rootLayer setBackgroundColor:[CPColor lightGrayColor]];
		
		// We need to tell the layer to draw itself
		[_rootLayer setNeedsDisplay];
	} 
	
	return self; 
} 

@end 