Re: Thumbnail hints
Re: Thumbnail hints
- Subject: Re: Thumbnail hints
- From: "Klaus L. Greulich" <email@hidden>
- Date: Tue, 16 May 2006 17:02:51 +0200
Hi!
Am 16.05.2006 um 15:45 schrieb Angelo Chen:
Hi Klaus,
Where can i find ThumbnailView/humbnailControls?
Thanks.
You'll find them in your Editor, after you have written them ... ;-)
It's quite simple.
For the View, create a new NSView subclass.
Drawing the background can be implemented in
- (void)drawRect:(NSRect)rect
Your ThumbnailControl is simply as subclass of NSControl:
#import <Cocoa/Cocoa.h>
@interface ThumbnailControl : NSControl
{
}
with the important method:
@implementation ThumbnailControl
+ (Class)cellClass
{
return [ThumbnailCell class];
}
All the drawing will hapen in the Cell Class
@interface ThumbnailCell : NSActionCell
{
}
@end
in the method
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)
controlView
For further reading I recommend:
http://developer.apple.com/documentation/Cocoa/Conceptual/ControlCell/
ControlCell.html
In your controlling class, do something like that:
-(void)setupImageControls
{
int i=0;
int xCounter = 0;
int yCounter = 0;
NSRect viewFrame = [theView frame];
NSRect scrollFrame = [theScrollView frame];
int controlsPerRow = viewFrame.size.width / TN_WIDTH;
float frows = (float)[theImages count] / (float)controlsPerRow;
int rows = ceil(frows);
height = rows * TN_WIDTH;
if (height < scrollFrame.size.height) {
height = scrollFrame.size.height - 18;
}
[theView setFrame:NSMakeRect
(viewFrame.origin.x,viewFrame.origin.y,viewFrame.size.width,height)];
for(i=0;i<[theImages count];i++) {
ThumbnailControl* ic = [[ThumbnailControl alloc] init];
if (xCounter >= controlsPerRow) {
xCounter = 0;
yCounter = yCounter++;
}
[ic setFrame:NSMakeRect(5+(xCounter*TN_WIDTH+BORDER),5+
(yCounter*TN_HEIGHT+BORDER),TN_WIDTH,TN_HEIGHT)];
[ic setImage:[theImages objectAtIndex:i]];
xCounter++;
[theView addSubview:ic positioned:NSWindowAbove relativeTo:nil];
}
[theView setNeedsDisplay:YES];
}
That is what I did, I don't know if there is a better or more elegant
solution.
Please note: the above source-code(s) are written in Mail, without
access to XCode or my Projects, so they are not for copy-n-paste,
only sort of a description what I did ...
klg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden