
/* Generated by Interface Builder */

#import "DPSUPView.h"

@implementation DPSUPView

- initFrame:(const NXRect *)theFrame
{
    [super initFrame:theFrame];
    sqSide=100.; 				 			// and length of a side
    NXSetRect(&sqRect,bounds.size.width/2.0,bounds.size.height/2.0,3*sqSide,sqSide);
    backgroundGray=NX_WHITE;				// init the background gray level

    return self;
}

- (float)backgroundGray
{
    return backgroundGray;
}

- takeBackgroundGrayFrom:sender
{
    backgroundGray = [sender floatValue];	// read the background gray slider
    [self display];
    return self;
}

- drawSelf:(const NXRect *)r :(int)c
{
    int	i, length = sqSide/8;
    float	*cArray;
    char	*oArray;
    float	bbox[4];
    int	oi=0,ci=0;

 /* Draw background */
	PSsetgray(backgroundGray);
	NXRectFill(&bounds);
 /* Start Drawing */
	PSsetgray(NX_BLACK);
	PSsetlinewidth(5.0);

	/* fill cArray and oArray */	
	NX_ZONEMALLOC([self zone],cArray,float,98);
	NX_ZONEMALLOC([self zone],oArray,char,51);
    oArray[oi++] = dps_ucache;
    oArray[oi++] = dps_setbbox;
	
	cArray[ci++] = sqRect.origin.x;
	cArray[ci++] = sqRect.origin.y;
	oArray[oi++] = dps_moveto;

		for(i = 0; i<12; i++){
			cArray[ci++] = length;
			cArray[ci++] = 0.0;
			oArray[oi++] = dps_rlineto;
			cArray[ci++] = 0.0;
			cArray[ci++] = 8*length;
			oArray[oi++] = dps_rlineto;
			cArray[ci++] = length;
			cArray[ci++] = 0.0;
			oArray[oi++] = dps_rlineto;
			cArray[ci++] = 0.0;
			cArray[ci++] = -8*length;
			oArray[oi++] = dps_rlineto;
		}
	
	/* fill bbox */
    bbox[0] = -1.0e6;
    bbox[1] = -1.0e6;
    bbox[2] = 1.0e6;
    bbox[3] = 1.0e6;
	
    PSsetgray(NX_BLACK);

    DPSDoUserPath(cArray,ci,dps_float,oArray,oi,bbox, dps_ustroke);

    NX_FREE(cArray);
    NX_FREE(oArray);

    return self;
}

- mouseDownAction:(NXPoint *)currentLocation
{	
    [self mouseDraggedAction:currentLocation];  //now do same as when dragging
    return self;
}

- mouseDraggedAction:(NXPoint *)currentLocation
{
    xOffset = sqRect.size.width/2;	// set the offsets for movement wrt the center
    yOffset = sqRect.size.height/2;
    sqRect.origin.x  = currentLocation->x - xOffset; // new x and y locations are center
    sqRect.origin.y  = currentLocation->y - yOffset; // of drawing
    [self display];
    return self;
}

@end
