Skip to content

Instantly share code, notes, and snippets.

@nickjs
Created November 6, 2008 04:20
Show Gist options
  • Save nickjs/22519 to your computer and use it in GitHub Desktop.
Save nickjs/22519 to your computer and use it in GitHub Desktop.
@implementation LEThumbnailView : CPView
{
CPView _root;
CPShadowView _shadow;
CPImageView _image;
CPTextField _label;
CPView _tooltip;
id _object;
}
- (void)setRepresentedObject:(id)object
{
if(!_root)
{
_root = [[CPButton alloc] initWithFrame:CGRectMake(0,0,200,169)];
[_root setBordered:NO];
[_root setBackgroundColor:[CPColor whiteColor]];
_shadow = [[CPShadowView alloc] initWithFrame:CGRectMakeZero()];
[_shadow setFrameForContentFrame:[_root frame]];
[_shadow setWeight:CPHeavyShadow];
[_shadow setHitTests:NO];
_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;
[_image setImage:[[CPImage alloc] initWithContentsOfFile:[_object photo]]];
[_label setStringValue:[_object name]];
}
- (void)setSelected:(BOOL)flag
{
}
- (void)mouseMoved:(CPEvent)anEvent
{
// [tooltipWindow setFrameOrigin:[[self window] convertBaseToBridge:[anEvent locationInWindow]]];
}
- (void)mouseEntered:(CPEvent)anEvent
{
[tooltipWindow setTitle:[_object name]];
if([_object photo])
[tooltipImage setImage:[[CPImage alloc] initWithContentsOfFile:[_object photo]]];
[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