• 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: Beveled outline around a view(BevelBox): How to?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beveled outline around a view(BevelBox): How to?


  • Subject: Re: Beveled outline around a view(BevelBox): How to?
  • From: Segher Boessenkool <email@hidden>
  • Date: Mon, 25 Apr 2005 01:37:03 +0200

iTunes and iPhoto have a nice beveled outline to their views that I'd like to implement. Poking around in the nib file, I see a custom class called BevelBox, which I suppose is an NSBox subclass. Can someone give me an idea to draw this type of effect? I've used NSFrameRect() in other parts to good effect to draw a colored line around an NSRect, but I clearly need something more specific.

Looks like it could be done fairly easily with NSRectFillListWithGrays(). You'll probably need to spend a bit of time examining it with Pixie.

If this is the kind of box you (that is, the original poster) want...

===> WhiteBox.h
/* WhiteBox */

#import <Cocoa/Cocoa.h>

@interface WhiteBox : NSBox
{
}
@end
===> WhiteBox.m
#import "WhiteBox.h"

@implementation WhiteBox

- (BOOL)isFlipped
{
	return YES;
}

static void drawLine(float x0, float y0, float x1, float y1, float grey)
{
[[NSColor colorWithDeviceWhite:grey alpha:1.0] set];
[NSBezierPath setDefaultLineWidth: 0.0];
[NSBezierPath strokeLineFromPoint:NSMakePoint(x0, y0) toPoint:NSMakePoint(x1, y1)];
}


- (void)drawRect:(NSRect)rect
{
	[[self contentView] setFrame:NSInsetRect([self bounds], 2.0, 2.0)];

	NSRect r = [self bounds];
	float x0 = NSMinX(r);
	float y0 = NSMinY(r);
	float x1 = NSMaxX(r);
	float y1 = NSMaxY(r);

	drawLine(x0 + 1.0, y0 + 0.5, x1 - 1.0, y0 + 0.5, 0.5765); // T
	drawLine(x0 + 0.5, y0 + 1.0, x0 + 0.5, y1 - 1.0, 0.8784); // L
	drawLine(x1 - 0.5, y0 + 1.0, x1 - 0.5, y1 - 1.0, 0.8784); // R
	drawLine(x0 + 1.0, y1 - 0.5, x1 - 1.0, y1 - 0.5, 0.9412); // B

	[[NSColor colorWithDeviceWhite:0.4 alpha:1.0] set];
	NSFrameRect(NSInsetRect([self bounds], 1.0, 1.0));

	[[NSColor /*whiteColor*/controlBackgroundColor] set];
	NSRectFill(NSInsetRect([self bounds], 2.0, 2.0));
}

@end
===> DISCLAIMER

Yes, I know it's not optimized; yes, I know there are missing
features.  But it works for my purposes, and it might help someone
get their required result.  Any helpful hints how to make this
better are appreciated, of course.

Have fun with it,


Segher


p.s. Yes I did use Pixie ;-)

_______________________________________________
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


  • Follow-Ups:
    • Re: Beveled outline around a view(BevelBox): How to?
      • From: John Fox <email@hidden>
    • Re: Beveled outline around a view(BevelBox): How to?
      • From: John Fox <email@hidden>
References: 
 >Beveled outline around a view(BevelBox): How to? (From: John Fox <email@hidden>)
 >Re: Beveled outline around a view(BevelBox): How to? (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: Re: Calling original method implementation from category
  • Next by Date: Re: Calling original method implementation from category
  • Previous by thread: Re: Beveled outline around a view(BevelBox): How to?
  • Next by thread: Re: Beveled outline around a view(BevelBox): How to?
  • Index(es):
    • Date
    • Thread