#import "Thing1.h"
#import "InspectMeDoc.h"
#import "PSWraps.h"
#import <dpsclient/wraps.h>
#import <appkit/NXColorWell.h>

@implementation Thing1

/* instance methods */

- initFrame:(NXRect *)frameRect
{
    [super initFrame:frameRect];
	[self setOpaque:YES];
	selected = NO;
	number = 25;
	size = 10;
	bkgndGray = 0.5;
	bkgndColor = NXConvertGrayToColor(0.5);
	shape = SHAPE_CIRCLES;
    return self;
}
    
- drawSelf:(NXRect *)rects :(int)rectCount
{
	[window disableFlushWindow];

	if(!NXEqualColor(bkgndColor, NXConvertGrayToColor(0.5)))
		NXSetColor(bkgndColor);
	else
		PSsetgray(bkgndGray);
	NXRectFill(&rects[0]);
	if (shape == SHAPE_CIRCLES)
		PSthing1(number,size,rects[0].size.width,rects[0].size.height,0);
	else
		PSthing1(number,size,rects[0].size.width,rects[0].size.height,1);
	if(selected)
		PSsetgray(1);
	else
		PSsetgray(0);
	NXFrameRectWithWidth(&rects[0],4);
	[[window reenableFlushWindow] flushWindowIfNeeded];

    return self;
}

- (BOOL)acceptsFirstMouse
{
	return YES;
}

- mouseDown:(NXEvent *)e
{
	[[window delegate] setSelectedObject:self];
	return self;
}

- setSelected:(BOOL)yesOrNo
{
	selected = yesOrNo;
	[self display];	
		// note: if the outline is different if selected,
		//  the above should be displayFromOpaqueAncestor:::
	
	return self;
}


// ---------------------------
//      set/get attributes
// ---------------------------
- setNumber:(int)newNumber;
{
	number = newNumber;
	[self display];
	return self;
}

- (int)number {return number; }

- setSize:(int)newSize;
{
	size = newSize;
	[self display];
	return self;
}

- (int)size {return size; }

- setShape:(int)newShape;
{
	shape = newShape;
	[self display];
	return self;
}

- (int)shape {return shape; }

- setBkgndColor:(NXColor)theColor;
{
	bkgndColor = theColor;
	[self display];
	return self;
}

- (NXColor)bkgndColor {return bkgndColor; }

- setBkgndGray:(float)theGray;
{
	bkgndGray = theGray;
	bkgndColor = NXConvertGrayToColor(bkgndGray);
	[self display];
	return self;
}

- (float)bkgndGray {return bkgndGray; }

@end
