home *** CD-ROM | disk | FTP | other *** search
-
- /* Generated by Interface Builder */
-
- #import "DisplayView.h"
-
- @implementation DisplayView
-
- - 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;
- return self;
- }
-
- - (float)backgroundGray
- {
- return backgroundGray;
- }
-
- - takeBackgroundGrayFrom:sender
- {
- backgroundGray = [sender floatValue];
- [self display];
- return self;
- }
-
- - drawSelf:(const NXRect *)r :(int)c
- {
- // method is invoked everytime mouse is clicked in a different location
- int i, length = sqSide/8;
-
- /* Draw background */
- PSsetgray(backgroundGray);
- NXRectFill(&bounds);
- /* Start drawing */
- PSsetgray(NX_BLACK);
- PSsetlinewidth(5.0);
-
- PSmoveto(sqRect.origin.x, sqRect.origin.y); // display the drawing
- for(i = 0; i<12; i++){
- PSrlineto(length, 0.0);
- PSrlineto(0.0, 8*length);
- PSrlineto(length, 0.0);
- PSrlineto(0.0, -8*length);
- }
- PSstroke();
-
- 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
-