• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Thumbnail hints
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Thumbnail hints (From: Angelo Chen <email@hidden>)

  • Prev by Date: Re: More Mac like handling of OS raised exceptions
  • Next by Date: Re: More Mac like handling of OS raised exceptions
  • Previous by thread: Re: Thumbnail hints
  • Next by thread: no public API for the standard slideshow, I guess?
  • Index(es):
    • Date
    • Thread