Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted by VikingoSegundo ( 17 years ago )
Â
#import "VSNodeView.h"
#import "VSGraphView.h"
Â
@implementation VSNodeView
@synthesize name;
@synthesize offset;
@synthesize newLocation;
@synthesize color;
Â
-(id)initWithOrigin:(NSPoint)origin
              Name:(NSString *)theName
             Color:(NSColor *)aColor
{ Â Â Â
    NSRect rect;
    rect.size.width = 120;
    rect.size.height= 50;
    rect.origin=origin;
    [super initWithFrame:rect];
   Â
    [self setName:theName];
    [self setColor:aColor];
    [color retain];
    return self;
}
Â
-(id)initWithOrigin:(NSPoint)origin
              Name:(NSString *)theName
{ Â Â Â
    return [self initWithOrigin:origin
                          Name:theName
                         Color:[NSColor colorWithCalibratedRed:.3
                                                         green:.6
                                                          blue:.45
                                                         alpha:1]];
}
Â
- (id)initWithFrame:(NSRect)frame
{
  [self dealloc];
    @throw [NSException exceptionWithName:@"VSBadInitCall"
                                  reason:@"Initialize NodeView with initWithOrigin:Name: or initWithOrigin:Name:Color:" userInfo:nil];
    return nil;
}
Â
- (void)drawRect:(NSRect)rect
{
    [NSGraphicsContext saveGraphicsState];
   Â
    [[self color] set];
   Â
    NSShadow* shadow = [[NSShadow alloc] init];
    [shadow setShadowOffset:NSMakeSize(7.0, -7.0)];
    [shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:.3]];
    [shadow setShadowBlurRadius:3.0];
    [shadow set];
   Â
    NSRect r;
    r.origin.x   = rect.origin.x;
    r.origin.y   = rect.origin.y+7;
    r.size.width = [self bounds].size.width-7;
    r.size.height= [self bounds].size.height-7;
    NSBezierPath* thePath = [NSBezierPath bezierPath];
  [thePath appendBezierPathWithRoundedRect:r
                                     xRadius:3.0
                                     yRadius:3.0];
    [thePath fill];
   Â
    [NSGraphicsContext restoreGraphicsState];
    [shadow release];
   Â
    [[NSFont fontWithName:@"Helvetica" size:9.0]set];
    NSPoint p;
    p.x = 10.0;
    p.y=20;
    [[self name] drawAtPoint:p withAttributes:nil];
   Â
}
Â
-(void)mouseDown:(NSEvent *)event
{
    NSLog(@"%@: %@ -> mouseDown",[self class], name);
    [[self superview] addSubview:self];
    offset =  [self convertPoint:[event locationInWindow] fromView:nil];
    [[self superview] setNeedsDisplay:YES];
}
Â
-(void)mouseUp:(NSEvent *)event
{
    NSLog(@"%@: %@ -> mouseUp %f %f",[self class], [self name], [self frame].origin.x, [self frame].origin.y);
}
Â
-(void)mouseDragged:(NSEvent *)event
{ Â Â Â
    newLocation.x = [event locationInWindow].x - offset.x;
    newLocation.y = [event locationInWindow].y - offset.y;
    [self setFrameOrigin: newLocation];
    [[self superview] setNeedsDisplay:YES];
}
Â
-(void)rightMouseDown:(NSEvent *)event
{
    NSLog(@"%@: %@ -> rightMouseDown",[self class], [self name]);
    [(VSGraphView*)[self superview] setStartingPoint:[event locationInWindow]];
    [(VSGraphView*)[self superview] setEndPoint:[event locationInWindow]];
    [[self superview] setNeedsDisplay:YES];
}
Â
-(void)rightMouseDragged:(NSEvent *)event
{
    [(VSGraphView*)[self superview] setEndPoint:[event locationInWindow]];
    [[self superview] setNeedsDisplay:YES];
}
Â
-(void)rightMouseUp:(NSEvent *)event
{
    NSLog(@"%@: %@ -> rightMouseUp",[self class] ,[self name]);
    [(VSGraphView*)[self superview] setStartingPoint];
    [(VSGraphView*)[self superview] setEndPoint];
    [[self superview] setNeedsDisplay:YES];
}
@end
Â
Â
Revise this Paste
Parent: 5507