CocoaDev

Edit AllPages

Hello!

I was wondering if anyone knew how to make that neat iPhoto 5 Adjustment window? Looking at the nibs it seems that there are several custom views that are imported into a borderless window.

Any hints and tricks are most welcome


Yes it is a borderless window with custom controls.


Thanks, anyone that has some example code?


Check out BorderlessWindow and NSBezierPathCategory - these two together will give you everything you need. Just create a borderless window using custom view. In that custom view, draw a rounded rect (with NSBezierPath - the category provided in NSBezierPathCategory will help you here) with an alpha faded black color as the bezier path’s fill color). Make some controls and add them to the custom view and viola!


THANKS!!


I recently found myself implementing some of the HUD interface for the preview window in Pixen. Along the way, I made a custom view that behaves just like the button in the HUD there. A screenshot:

http://www.opensword.org/Images/hudbuttons.jpg

PXHUDButton.h:

// // PXHUDButton.h // Pixen-XCode // // Created by Andy Matuschak on 5/7/05. // Copyright 2005 Open Sword Group. All rights reserved. //

#import <Cocoa/Cocoa.h>

@interface PXHUDButton : NSView { NSString * title; NSImage * buttonFillUp, * buttonFillDown; NSImage * buttonLeftUp, * buttonLeftDown; NSImage * buttonRightUp, * buttonRightDown; int pressed;

id target;
SEL action; }

@end

PXHUDButton.m:

// // PXHUDButton.m // Pixen-XCode // // Created by Andy Matuschak on 5/7/05. // Copyright 2005 Open Sword Group. All rights reserved. //

#import “PXHUDButton.h”

@implementation PXHUDButton

@end

You’ll need the images for it (ganked from iPhoto ^_^;;). You can download them (hudButton*.tiff) from our SVN repository here: http://www.andymatuschak.org/websvn/listing.php?repname=Open%20Sword%20SVN&path=/Pixen/trunk/&rev=0&sc=1

Just do PXHUDButton *myButton = [[PXHUDButton alloc] initWithFrame:someFrame] and make it a subview of something. The height has to be 20, I’m afraid. Use setTitle: to set the caption that appears inside the button, and setTarget: and setAction: to set up what happens when you click it. If someone feels like making an IBPalette, that’d be kinda sweet. I’m not entirely sure how.

I was thinking of making a whole suite of these things. Like, an overridden NSWindow, too, and so on. iPhoto has images for these widgets: spinner, slider, and button. It seems like Motion has many, many more, but I can’t find the images for them in any of the frameworks included. Other things like text boxes can be drawn with bezier paths. Oh, and the window that contains this button should have 66% alpha if you’re trying to replicate the HUD look. Here’s the code I use to draw the main window view:

id path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 1, 1) cornerRadius:8]; [[NSColor blackColor] set]; [path fill];

Pretty simple. It uses the RoundedRectangles category.

Oh, and I couldn’t figure out how to make the tiny drop shadow draw under the button. It just didn’t want to render no matter what I did. Anyone have any advice on that?

– AndyMatuschak


Andy,

It appears that the images you’re rendering are being drawn upside-down. If you look closely, you’ll notice that the gradient is flipped, and the shadow is on top. Just to make sure I wasn’t seeing things (no pun intended), I flipped the images vertically in Photoshop and sure enough, they drew as expected.

Unfortunately, I can’t figure out why they’re being drawn upside-down. There doesn’t seem to be anything explicity wrong with your drawing code.

The non-destructive workaround would be to set the isFlipped attribute of each image to YES with -setFlipped and then adjust the vertical positioning of the title string with:

// minus one extra pixel for the shadow at the bottom stringPoint.y = [self frame].size.height / 2 - [actual size].height / 2 - 1;

– Michael Watson


Hmm… I can’t seem to make the close button draw correctly. I’m using the same close button image that apple includes with iPhoto 06, but mine draws lighter. I’ve set it as the image of a button I put in the upper left corner of the window, which sits atop a view that draws the titlebar and rounded rect background. My background and titlebar seem to be the same color as iPhoto’s, but the image is lighter… Any ideas? – Devin Lane