• 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
NSImage inside(?) NSBezierPath
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage inside(?) NSBezierPath


  • Subject: NSImage inside(?) NSBezierPath
  • From: "Hell's KItchen Hell's KItchen" <email@hidden>
  • Date: Thu, 13 Sep 2007 15:39:16 +0200

Hello,
I've tried to make a simple custom NSView object as like event view in
iPhoto 2008. I've created the rounded rectangle with the method listed
above and tried to apply in it an NSImage.
Unfortunatly the NSImage does not fill correctly because my NSView
contains rounded angles while the image is a rectangle. Is there a way
to put this image *inside* the closed path? Or is there another way to
remove the borders of the image (it should be more diffucult I think).

I would also add a shadow so I've used the code listed in ADC Ref Lib
but it does not work because the shadow itself is inside my path and
not outside it; is it normal?

This is the creation code of the view (here the result with the
problem: http://img178.imageshack.us/img178/2625/immagine2um5.png):

- (void)drawRect:(NSRect)rect {
	[NSGraphicsContext saveGraphicsState];
	NSBezierPath * path = [self bezierPathWithRoundRectInRect:rect];
	[path stroke];
	[NSGraphicsContext restoreGraphicsState];
}

- (NSBezierPath *)bezierPathWithRoundRectInRect:(NSRect)aRect {


	NSBezierPath * path = [NSBezierPath bezierPath];
	[NSBezierPath setDefaultLineCapStyle: NSButtLineCapStyle];
	[NSBezierPath setDefaultLineWidth: 1];

	NSPoint topMid = NSMakePoint(NSMidX(aRect)+space, NSMaxY(aRect)-space);
	NSPoint topLeft = NSMakePoint(NSMinX(aRect)+space, NSMaxY(aRect)-space);
	NSPoint topRight = NSMakePoint(NSMaxX(aRect)-space, NSMaxY(aRect)-space);
	NSPoint bottomRight = NSMakePoint(NSMaxX(aRect)-space, NSMinY(aRect)+space);
	NSPoint originPoint = aRect.origin;
	originPoint.x+=space;
	originPoint.y+=space;

	[path moveToPoint:topMid];
	[path appendBezierPathWithArcFromPoint:topLeft toPoint:aRect.origin
radius:radius];
	[path appendBezierPathWithArcFromPoint:originPoint
toPoint:bottomRight radius:radius];
	[path appendBezierPathWithArcFromPoint:bottomRight toPoint:topRight
radius:radius];
	[path appendBezierPathWithArcFromPoint:topRight toPoint:topLeft radius:radius];
	[path closePath];

	[[NSColor redColor] set];

	NSImage *im = [NSImage imageNamed:@"big"];
	[im drawInRect: [path controlPointBounds] fromRect: [path
controlPointBounds] operation:NSCompositeSourceOver fraction:1];

	return (path);
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSImage inside(?) NSBezierPath
      • From: "Alan Smith" <email@hidden>
    • Re: NSImage inside(?) NSBezierPath
      • From: Keith Duncan <email@hidden>
  • Prev by Date: Re: Cocoa won't draw CMYK jpeg
  • Next by Date: Re: NSImage inside(?) NSBezierPath
  • Previous by thread: Re: Incremental Development?
  • Next by thread: Re: NSImage inside(?) NSBezierPath
  • Index(es):
    • Date
    • Thread