This is VertLine.m in view mode; [Download] [Up]
/*---------------------------------------------------------------------------------
One method that draws the line. Farily vanilla postscript; we define
one pswrap to draw the arrows, which I lifted from NeXT's Draw app.
We don't always go all the way to the edges, since this can make the
line look ugly; eg, the pointy part of the arrow clipped off, or the
square end butt of the line messing up the arrow.
HISTORY
9Mar93 DM New
---------------------------------------------------------------------------------*/
#import "VertLine.h"
#import "line.h"
#import <dpsclient/wraps.h>
@implementation VertLine
- drawSelf:(NXRect *)rects :(int)count;
{
float redComponent, greenComponent, blueComponent, alphaComponent; // The components of the color
NXColor drawingColor; // either the enabled or disabled color
// Get the line grey and the width set, then start drawing things
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);
PSsetrgbcolor(redComponent, greenComponent, blueComponent);
PSsetlinewidth(lineWidth);
// Draw arrows on end, if so desired.
if(startArrow)
{
PSArrow(bounds.size.width/2.0, 0.0 + lineWidth,270.0); // Don't go quite all the way to the edges
PSstroke();
}
if(endArrow)
{
PSArrow(bounds.size.width/2.0, bounds.size.height - lineWidth, 90);
PSstroke();
}
PSnewpath();
// Some munging around to get the arrows looking neat, if any
if(startArrow) // Don't want square end butts screwing up my arrows
PSmoveto(bounds.size.width/2, lineWidth);
else
PSmoveto(bounds.size.width/2, 0);
if(endArrow)
PSlineto(bounds.size.width/2.0,(bounds.size.height - lineWidth));
else
PSlineto(bounds.size.width/2.0, bounds.size.height);
PSstroke();
return self;
}
- mouseDown:(NXEvent*)theEvent; // Mousedown handling
{
/*----------------------------------------------------------------------------
If the mousedown is pretty close to the vertical 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.x < ((bounds.size.width/2.0) + (lineWidth/2.0) + HIT_TOLERANCE)) &&
(viewCoordHit.x > ((bounds.size.width/2.0) - (lineWidth/2.0) - HIT_TOLERANCE)))
{
[self performClick:self];
}
else
return [self passOnEvent:theEvent];
return self; // Keep compiler happy
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.