Welcome, guest! Login / Register - Why register?
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
Your Name: Code Language: