Guest User

Untitled

a guest
Jun 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. //
  2. // IconView.m
  3. // gridView
  4. //
  5. // Created by Tim on [Feb 17].
  6. // Copyright 2009 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "IconView.h"
  10.  
  11. @implementation IconView
  12.  
  13. @synthesize avatars;
  14.  
  15. int row;
  16. int col;
  17.  
  18. - (void) drawItems
  19. {
  20. row = self.bounds.size.height - 250;
  21.  
  22. int spacing = self.bounds.size.width / 160;
  23. col = self.bounds.size.width / spacing - 160 ;
  24.  
  25. buttons = [[NSArray alloc] initWithObjects:@"Apocalypto",
  26. @"The Whole Ten Yards",
  27. @"Wall•E",
  28. @"Iron Man",
  29. @"Hellboy",
  30. @"The Incredible Hulk",
  31. @"Platoon",
  32. @"For the Birds",nil];
  33. }
  34.  
  35. - (void)setNeedsDisplay:(BOOL)flag
  36. {
  37. [container removeFromSuperview];
  38. container = [[NSView alloc]initWithFrame:self.bounds];
  39. [self addSubview:container];
  40. [self drawItems];
  41. }
  42.  
  43. - (void)drawRect:(CGRect)rect {
  44. [container removeFromSuperview];
  45. container = [[NSView alloc]initWithFrame:self.bounds];
  46. [self addSubview:container];
  47. [self drawItems];
  48. for(int i = 0; i < [buttons count]; i++){
  49. [self gridViewWithLabel:[buttons objectAtIndex:i]];
  50. }
  51.  
  52. }
  53.  
  54. - (void) coverPressed:(NSButton *)sender
  55. {
  56. NSBeep();
  57. NSBeginInformationalAlertSheet([NSString stringWithFormat:@"%@", sender.title],
  58. @"Dismiss", nil, nil,
  59. [[NSApplication sharedApplication] mainWindow], self,
  60. nil, nil, nil, @"You cannot edit this library item at this time!");
  61. }
  62.  
  63.  
  64. static int noOfRows = 0;
  65.  
  66. - (void) gridViewWithLabel:(NSString *)userGroup
  67. {
  68. int spacing = self.bounds.size.width / 160;
  69.  
  70. //create the containing view
  71.  
  72. NSView *buttonView = [[NSView alloc] initWithFrame:NSMakeRect(col, row, 160, 300)];
  73.  
  74. //create the buttton representing the icon in the grid
  75. NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(10, 35, 140, 198)];
  76. [button setTitle:userGroup];
  77. [button setTarget:self];
  78. [button setAction:@selector(coverPressed:)];
  79. if([NSImage imageNamed:userGroup] == nil)
  80. [button setImage:[NSImage imageNamed:@"noCover.png"]];
  81. else
  82. [button setImage:[NSImage imageNamed:userGroup]];
  83.  
  84. [[button image] setSize:NSMakeSize(140.00, 198.00)];
  85. [button setBordered:NO];
  86.  
  87. NSButton *buttonOverlay = [[NSButton alloc] initWithFrame:NSMakeRect(0, 20, 160, 228)];
  88. [buttonOverlay setTitle:userGroup];
  89. [buttonOverlay setTarget:self];
  90. [buttonOverlay setAction:@selector(coverPressed:)];
  91. [buttonOverlay setImage:[NSImage imageNamed:@"overlay.png"]];
  92. //[buttonOverlay setTransparent:YES];
  93. [buttonOverlay setBordered:NO];
  94.  
  95.  
  96. //set positioning variables
  97. col = col + self.bounds.size.width / spacing ;
  98. //if the button should be on the next row pop it down
  99. if((buttonView.frame.origin.x) > (self.bounds.size.width - 150))
  100. {
  101. noOfRows = noOfRows + 1;
  102. buttonView.frame = NSMakeRect(self.bounds.size.width / spacing - 160, row - 265, 160, 300);
  103. col = self.bounds.size.width / spacing;
  104. col = col + self.bounds.size.width / spacing - 160;
  105. row = row - 265;
  106. }
  107.  
  108. //set final subviews
  109. [buttonView addSubview:button];
  110. NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, button.frame.size.width, 18)];
  111. [label setBordered:NO];
  112. [label setBackgroundColor:[NSColor clearColor]];
  113. [label setAlignment:NSCenterTextAlignment];
  114. [label setTextColor:[NSColor whiteColor]];
  115. [label setDrawsBackground:NO];
  116. [label setSelectable:NO];
  117. [label setFont:[NSFont systemFontOfSize:12.0]];
  118. [label setTitleWithMnemonic:userGroup];
  119.  
  120. NSTextField *timelabel = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 0, button.frame.size.width, 10)];
  121. [timelabel setBordered:NO];
  122. [timelabel setBackgroundColor:[NSColor clearColor]];
  123. [timelabel setAlignment:NSCenterTextAlignment];
  124. [timelabel setTextColor:[NSColor lightGrayColor]];
  125. [timelabel setDrawsBackground:NO];
  126. [timelabel setSelectable:NO];
  127. [timelabel setFont:[NSFont systemFontOfSize:10.0]];
  128. [timelabel setTitleWithMnemonic:@"140 Minutes"];
  129.  
  130. [buttonView addSubview:label];
  131. [buttonView addSubview:buttonOverlay];
  132.  
  133. [buttonView addSubview:timelabel];
  134. [container addSubview:buttonView];
  135. }
  136.  
  137. @end
Add Comment
Please, Sign In to add comment