//
//  MyCustomView.m
//  CustomViewTest
//
//  Created by Lieven Dekeyser on 03/12/09.
//  Copyright 2009 Lieven Dekeyser. All rights reserved.
//

#import "MyCustomView.h"


@implementation MyCustomView


- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
	
	CGSize frameSize = self.frame.size;
	// This is basically the equivalent of these lines:
	// CGRect myFrame = [self frame];
	// CGSize frameSize = myFrame.size;
	
	
	// Set the strok color, which is the color in which line segments are drawn
	[[NSColor redColor] setStroke];
	
	// Set the fill color to a semi-transparent black
	[[NSColor colorWithDeviceWhite:0.0f alpha:0.5f] setFill];
	
	
	
	// Create a path from the bottom-left corner to the top-right corner of the view...
	NSBezierPath * path = [NSBezierPath bezierPath];
	[path moveToPoint:NSMakePoint(0.0f, 0.0f)];
	[path lineToPoint:NSMakePoint(frameSize.width, frameSize.height)];
	// ... and draw it
	[path stroke];
	
	// Shortcut to create a rectangular path
	// Overwriting the path pointer, since it was an autoreleased path anyway
	path = [NSBezierPath bezierPathWithRect:self.bounds];
	
	// We could fill the rectangle with the semi-transparent black...
	// [path fill];
	
	// But let's make things a bit more interesting and draw a gradient
	NSGradient * gradient = [[NSGradient alloc] initWithStartingColor:
								[NSColor redColor] endingColor:[NSColor colorWithDeviceWhite:0.0f alpha:0.5f]];
	
	[gradient drawInBezierPath:path angle:0.0f];
	
	// I could've autoreleased the gradient upon creation, but I didn't, so I have to clean things up
	[gradient release]; gradient = nil;
}

@end
