/*
 * DotView.j
 *
 * Created by Philippe Laval on 2009/04/13.
 * Copyright 2009 Philippe Laval. All rights reserved.
 */

@import <Foundation/CPObject.j>

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


@implementation DotView : CPView
{
    CPPoint center;
	CPColor color;
    float radius;
}

- (id)initWithFrame:(CGRect)aFrame
{
    if (self = [super initWithFrame:aFrame])
    {
		center = CPPointMake(50.0, 50.0);
	    radius = 10.0;
	    color = [CPColor redColor];
	}
	
	return self;
}


- (void)drawRect:(CPRect)aRect
{
    var context = [[CPGraphicsContext currentContext] graphicsPort];

    CGContextSetFillColor(context, [CPColor whiteColor]);
    CGContextFillRect(context, [self bounds]);

	var dotRect = CPRectMake(center.x - radius, center.y - radius, 2 * radius, 2 * radius);
    
    CGContextSetFillColor(context, color);
    CGContextFillEllipseInRect(context, dotRect)
}

- (BOOL)isOpaque {
    return YES;
}

- (void)mouseUp:(CPEvent *)event {
    var eventLocation = [event locationInWindow];
    center = [self convertPoint:eventLocation fromView:nil];
    [self setNeedsDisplay:YES];
}


- (void)setRadius:(id)sender {
    radius = [sender doubleValue];
    [self setNeedsDisplay:YES];
}
 
- (void)setColor:(id)sender {
    color = [sender color];
    [self setNeedsDisplay:YES];
}

@end
