// // PPDragTarget.m // PastePacker // // Created by Daniel Grover on 11/12/07. // Copyright 2007 Wonder Warp Software. All rights reserved. // #import "PPDragTarget.h" #import "AppController.h" @implementation PPDragTarget - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { // Register for every conceivable type (there ought to be a better way to do this). [self registerForDraggedTypes:[NSImage imagePasteboardTypes]]; [self registerForDraggedTypes:[NSArray arrayWithObjects:NSVCardPboardType,NSURLPboardType, NSTabularTextPboardType, NSStringPboardType, NSSoundPboardType, NSRulerPboardType, NSRTFDPboardType, NSRTFPboardType, NSPostScriptPboardType, NSPDFPboardType, NSHTMLPboardType, NSFontPboardType,NSFilenamesPboardType, NSFilesPromisePboardType, NSFileContentsPboardType, NSInkTextPboardType, NSColorPboardType, nil]]; } return self; } - (void)drawRect:(NSRect)rect { // Draw a bullseye. // Darken it if they're in the middle of dragging something. NSColor *red = [NSColor redColor]; NSColor *white = [NSColor whiteColor]; if ([self over]){ red = [red blendedColorWithFraction:0.3 ofColor:[NSColor blackColor]]; white = [white blendedColorWithFraction:0.3 ofColor:[NSColor blackColor]]; } float dim = MIN([self bounds].size.height, [self bounds].size.width)/12; int i; for (i = 12; i >= 0; i--){ float width = dim * i; [(((i % 2) == 0) ? red : white) set]; [[NSBezierPath bezierPathWithOvalInRect:NSMakeRect([self bounds].size.width/2 - (width/2), [self bounds].origin.y + [self bounds].size.height/2 - (width/2), width,width)] fill]; } } - (BOOL)prepareForDragOperation:(id )sender { return YES; } - (BOOL)performDragOperation:(id )sender { return YES; } - (NSDragOperation)draggingEntered:(id )sender { [self setOver:YES]; return NSDragOperationCopy; } - (void)concludeDragOperation:(id )sender { [AppController docFromPasteboard:[sender draggingPasteboard]]; [self setOver:NO]; } - (void)draggingExited:(id )sender { [self setOver:NO]; } - (BOOL) over{ return over; } - (void) setOver:(BOOL)n{ over = n; [self setNeedsDisplay:YES]; } @end