Skip to content

Instantly share code, notes, and snippets.

@hlship
Created June 25, 2009 22:58
Show Gist options
  • Save hlship/136221 to your computer and use it in GitHub Desktop.
Save hlship/136221 to your computer and use it in GitHub Desktop.
@import <AppKit/CPPanel.j>
@import <AppKit/CPView.j>
@implementation PhotoPanel : CPPanel
{
CPArray images;
}
- (id)init
{
self = [self initWithContentRect:CGRectMake(0.0, 0.0, 300.0, 400.0)
styleMask:CPHudBackgroundWindowMask | CPClosableWindowMask | CPResizableWindowMask];
if (self)
{
[self setTitle:"Photos"];
[self setFloatingPanel:YES];
var contentView = [self contentView],
bounds = [contentView bounds];
bounds.size.height -= 20.0;
var photosView = [[CPCollectionView alloc] initWithFrame: bounds];
[photosView setAutoresizingMask:CPViewWidthSizable];
[photosView setMinItemSize:CGSizeMake(100, 100)];
[photosView setMaxItemSize:CGSizeMake(100, 100)];
var itemPrototype = [[CPCollectionViewItem alloc] init],
photoView = [[PhotoView alloc] initWithFrame:CGRectMakeZero()];
[itemPrototype setView:photosView];
[photosView setItemPrototype:itemPrototype];
var scrollView = [[CPScrollView alloc] initWithFrame:bounds];
[scrollView setDocumentView:photosView];
[scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[scrollView setAutohidesScrollers:YES];
[[scrollView contentView] setBackgroundColor:[CPColor whiteColor]];
[contentView addSubview:scrollView];
images = [CPArray arrayWithObjects: [[CPImage alloc] initWithContentsOfFile:"Resources/sample.jpg" size:CGSizeMake(500.0, 430.0)],
[[CPImage alloc] initWithContentsOfFile:"Resources/sample2.jpg" size:CGSizeMake(500.0, 389.0)],
[[CPImage alloc] initWithContentsOfFile:"Resources/sample3.jpg" size:CGSizeMake(413.0, 400.0)],
[[CPImage alloc] initWithContentsOfFile:"Resources/sample4.jpg" size:CGSizeMake(500.0, 375.0)],
[[CPImage alloc] initWithContentsOfFile:"Resources/sample5.jpg" size:CGSizeMake(500.0, 375.0)],
[[CPImage alloc] initWithContentsOfFile:"Resources/sample6.jpg" size:CGSizeMake(500.0, 375.0)]];
[photosView setContent:images];
}
return self;
}
@end
@implementation PhotoView : CPView
{
CPImageView imageView;
}
- (void)setSelected:(BOOL)isSelected
{
[self setBackgroundColor:(isSelected ? [CPColor grayColor] : nil)];
}
- (void)setRepresentedObject:(id)anObject
{
if (!imageView)
{
var bounds = [self bounds],
frame = CGRectInset(bounds, 5.0., 5.0);
imageView = [[CPImageView alloc] initWithFrame:frame];
[imageView setImageScaling:CPScaleProportionally];
[imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[self addSubview:imageView];
}
[imageView setImage:anObject];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment