/* Objective_C Implementation of the Fruit Class: Fruit.m */

#import "Fruit.h"

@implementation Fruit

/* Initialize a new fruit. */

/* Intialize display to be showing correct current values. */
-appDidInit:sender
{
	[self displayValues:self];
	return self;
}

- initFrame:(const NXRect *)frameRect
{
	[super initFrame:frameRect];
	[self setDiameter:1];		// init the diameter
	[self setColor:NX_COLORRED]; 	// init the color
	return self;			// return the new instance
}

//set color by having a color chip dropped onto the view
-acceptColor:(NXColor)aColor atPoint:(NXPoint *)aPoint
{
	[self setColor:aColor];
	return self;
}

/* Action method for setting the color of the fruit. */
-takeColorFrom:sender
{
	[self setColor:[sender color]];
	return self;
}

/* Set the color of the fruit. */
-setColor:(NXColor)aColor
{
	color = aColor;
	[self display];
	return self;
}

/* Return the fruit's color. */
- (NXColor)color
{
	return color;
}

/* Action method for setting the diameter of the fruit. */
-takeDiameterFrom:sender
{
	[self setDiameter:[sender intValue]];
	return self;
}

/* Set the fruit's diameter. */
-setDiameter: (int) aSize
{
	diameter = aSize;
	[self display];
	return self;
}

/* Return the fruit's diameter. */
- (int) diameter
{
	return diameter;
}

/* Tell the fruit to increase its diameter. */
- grow:sender
{
	[self setDiameter:([self diameter] + 1)];
	return self;
}

- displayValues:sender
{
	[colorDisplay setColor:color];
	[diameterDisplay setIntValue:diameter];
	return self;
}

- drawSelf:(const NXRect*)r :(int)c
{
	PSsetgray(NX_LTGRAY);
	NXRectFill(&bounds);		//"erase" to gray

    NXSetColor(color);	//for drawing, set to selected color
	
	/* Draw the fruit. */
	PSnewpath();
	PSarc(bounds.size.width/2.0, bounds.size.height/2.0,
				[self diameter]/2.0,0.,360.);
	PSclosepath();

	PSfill();		//fill the defined path
	return self;
}

@end
