Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // IconView.m
- // gridView
- //
- // Created by Tim on [Feb 17].
- // Copyright 2009 __MyCompanyName__. All rights reserved.
- //
- #import "IconView.h"
- @implementation IconView
- @synthesize avatars;
- int row;
- int col;
- - (void) drawItems
- {
- row = self.bounds.size.height - 250;
- int spacing = self.bounds.size.width / 160;
- col = self.bounds.size.width / spacing - 160 ;
- buttons = [[NSArray alloc] initWithObjects:@"Apocalypto",
- @"The Whole Ten Yards",
- @"Wall•E",
- @"Iron Man",
- @"Hellboy",
- @"The Incredible Hulk",
- @"Platoon",
- @"For the Birds",nil];
- }
- - (void)setNeedsDisplay:(BOOL)flag
- {
- [container removeFromSuperview];
- container = [[NSView alloc]initWithFrame:self.bounds];
- [self addSubview:container];
- [self drawItems];
- }
- - (void)drawRect:(CGRect)rect {
- [container removeFromSuperview];
- container = [[NSView alloc]initWithFrame:self.bounds];
- [self addSubview:container];
- [self drawItems];
- for(int i = 0; i < [buttons count]; i++){
- [self gridViewWithLabel:[buttons objectAtIndex:i]];
- }
- }
- - (void) coverPressed:(NSButton *)sender
- {
- NSBeep();
- NSBeginInformationalAlertSheet([NSString stringWithFormat:@"%@", sender.title],
- @"Dismiss", nil, nil,
- [[NSApplication sharedApplication] mainWindow], self,
- nil, nil, nil, @"You cannot edit this library item at this time!");
- }
- static int noOfRows = 0;
- - (void) gridViewWithLabel:(NSString *)userGroup
- {
- int spacing = self.bounds.size.width / 160;
- //create the containing view
- NSView *buttonView = [[NSView alloc] initWithFrame:NSMakeRect(col, row, 160, 300)];
- //create the buttton representing the icon in the grid
- NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(10, 35, 140, 198)];
- [button setTitle:userGroup];
- [button setTarget:self];
- [button setAction:@selector(coverPressed:)];
- if([NSImage imageNamed:userGroup] == nil)
- [button setImage:[NSImage imageNamed:@"noCover.png"]];
- else
- [button setImage:[NSImage imageNamed:userGroup]];
- [[button image] setSize:NSMakeSize(140.00, 198.00)];
- [button setBordered:NO];
- NSButton *buttonOverlay = [[NSButton alloc] initWithFrame:NSMakeRect(0, 20, 160, 228)];
- [buttonOverlay setTitle:userGroup];
- [buttonOverlay setTarget:self];
- [buttonOverlay setAction:@selector(coverPressed:)];
- [buttonOverlay setImage:[NSImage imageNamed:@"overlay.png"]];
- //[buttonOverlay setTransparent:YES];
- [buttonOverlay setBordered:NO];
- //set positioning variables
- col = col + self.bounds.size.width / spacing ;
- //if the button should be on the next row pop it down
- if((buttonView.frame.origin.x) > (self.bounds.size.width - 150))
- {
- noOfRows = noOfRows + 1;
- buttonView.frame = NSMakeRect(self.bounds.size.width / spacing - 160, row - 265, 160, 300);
- col = self.bounds.size.width / spacing;
- col = col + self.bounds.size.width / spacing - 160;
- row = row - 265;
- }
- //set final subviews
- [buttonView addSubview:button];
- NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, button.frame.size.width, 18)];
- [label setBordered:NO];
- [label setBackgroundColor:[NSColor clearColor]];
- [label setAlignment:NSCenterTextAlignment];
- [label setTextColor:[NSColor whiteColor]];
- [label setDrawsBackground:NO];
- [label setSelectable:NO];
- [label setFont:[NSFont systemFontOfSize:12.0]];
- [label setTitleWithMnemonic:userGroup];
- NSTextField *timelabel = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 0, button.frame.size.width, 10)];
- [timelabel setBordered:NO];
- [timelabel setBackgroundColor:[NSColor clearColor]];
- [timelabel setAlignment:NSCenterTextAlignment];
- [timelabel setTextColor:[NSColor lightGrayColor]];
- [timelabel setDrawsBackground:NO];
- [timelabel setSelectable:NO];
- [timelabel setFont:[NSFont systemFontOfSize:10.0]];
- [timelabel setTitleWithMnemonic:@"140 Minutes"];
- [buttonView addSubview:label];
- [buttonView addSubview:buttonOverlay];
- [buttonView addSubview:timelabel];
- [container addSubview:buttonView];
- }
- @end
Add Comment
Please, Sign In to add comment