This is HorLine.m in view mode; [Download] [Up]
/*--------------------------------------------------------------------------------- A class that draws a horizontal line. FUN FACT: This will cause major problems if "ActionLine" is not compiled first. When you attempt to load the palette, IB will crash and you'll get a message on the console. The soloution is to make sure we're compiled after ActionLine, by control-dragging it in the Project window so that it's after ActionLine. This was a major debugging effort (he said humbly) to find. Couldn't figure out why "VertLine" was great, but "HoroLine" caused everything to crash. HISTORY 9Mar93 New ---------------------------------------------------------------------------------*/ #import "HorLine.h" #import "line.h" #import <dpsclient/wraps.h> @implementation HorLine - drawSelf:(NXRect *)rects :(int)count; { /*--------------------------------------------------------------------------------- Classic NeXT drawself method. Uses one pswrap we define in line.psw, PSArrow. I just lifted that from the NeXT Draw app. Other than that, this is pretty vanilla postscript. We back off on drawing the line ALL the way to the end if we have end arrows; if we don't do this, things look ugly, as the square end of the line overlaps the arrow. We also back off the arrow heads from the extreme ends a little, so the pointy part at the end doesn't get chopped off. ---------------------------------------------------------------------------------*/ float redComponent, greenComponent, blueComponent, alphaComponent; // The components of the color NXColor drawingColor; // either the enabled or disabled color drawingColor = ([self isEnabled]) ? enabledColor : disabledColor; NXConvertColorToRGBA(drawingColor, &redComponent, &greenComponent, &blueComponent, &alphaComponent); // Deal with the alpha component. If none is specified, set it to 1.0 (opaque paint); // otherwise, respect what was set in the color. if(alphaComponent == NX_NOALPHA) PSsetalpha(1.0); else PSsetalpha(alphaComponent); // Line width and color PSsetrgbcolor(redComponent, greenComponent, blueComponent); PSsetlinewidth(lineWidth); // Draw arrows on end, if so desired. if(startArrow) { PSArrow(0 + lineWidth, bounds.size.height/2, 180.0); PSstroke(); } if(endArrow) { PSArrow(bounds.size.width- lineWidth, bounds.size.height/2.0, 0); PSstroke(); } PSnewpath(); // Some munging around to get the arrows looking neat, if any if(startArrow) PSmoveto(lineWidth, bounds.size.height/2.0); else PSmoveto(0, bounds.size.height/2.0); if(endArrow) PSlineto(bounds.size.width - lineWidth, bounds.size.height/2.0); else PSlineto(bounds.size.width, bounds.size.height/2.0); PSstroke(); return self; } - mouseDown:(NXEvent*)theEvent; // Mousedown handling { /*---------------------------------------------------------------------------- If the mousedown is pretty close to the horozontal centerline of the view, assume we got hit. This should cause a perfromClick: operation to occur. ----------------------------------------------------------------------------*/ NXPoint viewCoordHit; // Coordinates of the hit in view-land, rather than window-land viewCoordHit.x = theEvent->location.x; viewCoordHit.y = theEvent->location.y; [self convertPoint:&viewCoordHit fromView:NULL]; if((viewCoordHit.y < ((bounds.size.height/2.0) + (lineWidth/2.0) + HIT_TOLERANCE)) && (viewCoordHit.y > ((bounds.size.height/2.0) - (lineWidth/2.0) - HIT_TOLERANCE))) { return [self performClick:self]; } else return [self passOnEvent:theEvent]; return self; // Keep the compiler from having kittens } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.