Skip to content

Instantly share code, notes, and snippets.

@nickjs
Created December 16, 2008 20:59
Show Gist options
  • Save nickjs/36826 to your computer and use it in GitHub Desktop.
Save nickjs/36826 to your computer and use it in GitHub Desktop.
@implementation LEConnectionDropbox : CPImageView
{
CPTextField _label;
CPView _highlight;
}
- (LEConnectionDropbox)initWithFrame:(CPRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self)
{
[self setImage:[CPImage imageWithContentsOfFile:@"Resources/Icons/DropBox.png" size:CGSizeMake(128,128)]];
[self registerForDraggedTypes:[ConnectionDragType]];
_label = [[CPTextField alloc] initWithFrame:CGRectMake(0,65,145,60)];
[_label setTextColor:[CPColor blackColor]];
[_label setFont:[CPFont boldSystemFontOfSize:14.0]];
[_label setAlignment:CPCenterTextAlignment];
[_label setTextShadow:[CPShadow shadowWithOffset:CGSizeMake(1,1) blurRadius:2.0 color:[CPColor lightGrayColor]]];
[_label setStringValue:@"Drop Here\nTo Connect"];
[self addSubview:_label];
}
return self;
}
- (void)performDragOperation:(CPDraggingInfo)aSender
{
[_highlight removeFromSuperview];
console.log('a');
var data = [[aSender draggingPasteboard] dataForType:ConnectionDragType]
console.log('b');
LEAlert("something");
}
- (void)draggingEntered:(CPDraggingInfo)aSender
{
if(!_highlight)
_highlight = [LEHighlight highlightWithFrame:CGRectMakeZero()];
[_highlight setFrame:CGRectInset([self frame],-9.0,-8.0)];
[[self superview] addSubview:_highlight];
}
- (void)draggingExited:(CPDraggingInfo)aSender
{
[_highlight removeFromSuperview];
}
@end
- (CPArray)collectionView:(CPCollectionView)aCollectionView dragTypesForItemsAtIndexes:(CPIndexSet)indices
{
return [ConnectionDragType];
}
- (CPData)collectionView:(CPCollectionView)aCollectionView dataForItemsAtIndexes:(CPIndexSet)indices forType:(CPString)aType
{
var array = [CPArray array];
for(var i = 0; i < [indices count]; i++)
[array addObject:_results[i]];
return [CPKeyedArchiver archivedDataWithRootObject:array];
}
@implementation LEConnectionThumbnailView : CPView
{
CPView _root;
CPShadowView _shadow;
CPImageView _image;
CPTextField _label;
CPView _tooltip;
id _object;
}
- (void)setRepresentedObject:(id)object
{
if(!_root)
{
_root = [[CPView alloc] initWithFrame:CGRectMake(5,5,200,169)];
[_root setBackgroundColor:[CPColor whiteColor]];
_shadow = [[CPShadowView alloc] initWithFrame:CGRectMakeZero()];
[_shadow setFrameForContentFrame:[_root frame]];
_image = [[CPImageView alloc] initWithFrame:CGRectMake(2,2,196,135)];
[_image setImageScaling:CPScaleToFit];
[_image setHitTests:NO];
_label = [[CPTextField alloc] initWithFrame:CGRectMake(0,CGRectGetHeight([_root bounds])-26,CGRectGetWidth([_root bounds]),22)];
[_label setAlignment:CPCenterTextAlignment];
[_label setLineBreakMode:CPLineBreakByTruncatingTail];
[_label setFont:[CPFont fontWithName:@"Marker Felt" size:13.0]];
[_label setHitTests:NO];
[self addSubview:_shadow];
[self addSubview:_root];
[_root addSubview:_image];
[_root addSubview:_label];
}
_object = object;
if(_object.user)
{
_object.user = [[LEUser alloc] initWithJSONObject:_object.user];
[_image setImage:[_object.user photoAsImage]];
[_label setStringValue:[_object.user name]];
}
else
data = _object.profile;
}
- (void)setSelected:(BOOL)flag
{
}
- (void)mouseDown:(CPEvent)anEvent
{
[super mouseDown:anEvent];
[self mouseExited:anEvent];
}
- (void)mouseEntered:(CPEvent)anEvent
{
var data;
if(_object.user)
data = _object.user;
else
data = _object.profile;
[tooltipWindow setTitle:_object.user ? @"Person" : @"Profile"];
var string = [data name];
if([data photoAsImage])
[[tooltipWindow image] setImage:[data photoAsImage]];
else
[[tooltipWindow image] setImage:nil];
if([data location])
string += @"\n"+[[_object.user location] areaString];
if(_object.distance)
string += @"\n" + [[[LELoginController user] location] distanceFrom:[data location]].toFixed(2) + " mi away";
// if(_object.matches)
// for(var i in _object.matches)
// string += @"\n" + i;
[[tooltipWindow label] setStringValue:string];
[tooltipWindow orderFront:self];
}
- (void)mouseExited:(CPEvent)anEvent
{
[tooltipWindow orderOut:self];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment