//
//  ClockHand.m
//  Clock-Test
//
//  Created by Ashley on 23/10/2006.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "ClockHand.h"


@implementation ClockHand

- (id) initWithCentre:(NSPoint)centre andRadius:(float)radius andWidth:(float)width
{
	if ((self = [super init]) != nil) {
		_centre = centre;
		_path = [[NSBezierPath alloc] init];
		_radius = radius;
		_width = width;	
		_angle = 0.0;
		_halfWidth = [self width]/2.0;
		_radius = [self radius];
		
		[_path moveToPoint:NSMakePoint(-_halfWidth, 0.0)];
		[_path lineToPoint:NSMakePoint(0.0, _radius)];
		[_path lineToPoint:NSMakePoint(_halfWidth, 0.0)];
		[_path appendBezierPathWithArcWithCenter:NSMakePoint(0.0, 0.0) 
			radius:_halfWidth 
			startAngle:0.0 
			endAngle:180.0 
			clockwise:YES];
		
		NSAffineTransform *transform = [NSAffineTransform transform];
		[transform translateXBy:centre.x yBy:centre.y];
		[_path transformUsingAffineTransform:transform];
		
		_colour = [NSColor blackColor];
	}
	return self;
}

- (float) width
{
	return _width;
}

- (float) radius
{
	return _radius;
}

- (void) setAngle:(float)angle
{
	NSAffineTransform *transform = [NSAffineTransform transform];
	[transform translateXBy:_centre.x yBy:_centre.y];
	[transform rotateByDegrees:(angle - _angle)];
	[transform translateXBy:-_centre.x yBy:-_centre.y];
//	NSLog(@"%@", transform);
	[_path transformUsingAffineTransform:transform];
	
	_angle = angle;
}

- (float) angle
{
	return _angle;
}

- (void) setPath:(NSBezierPath *)path
{
	[path retain];
	[_path release];
	_path = path;
}

- (NSBezierPath *) path
{
	return _path;
}

- (void) setColour:(NSColor *)colour
{
	[colour retain];
	[_colour release];
	_colour = colour;
}

- (NSColor *)colour
{
	return _colour;
}

- (void) draw
{
	[[self colour] set];
	[[self path] fill];
}


- (void) dealloc
{	
	[_path release];
	[_colour release];
	[super dealloc];
}

@end
