Uli's Web Site
[ Zathras.de - Uli's Web Site ]
Other Sites: Stories
Pix
Abi 2000
Stargate: Resurgence
Lost? Site Map!
 
 
     home | blog | moose | programming | articles >> blog

 Blog
 
 Archive
 
 Blog Topics
 

15 Most Recent [RSS]

 Less work through Xcode and shell scripts
2011-12-16 @600
 
 iTunesCantComplain released
2011-10-28 @954
 
 Dennis Ritchie deceased
2011-10-13 @359
 
 Thank you, Steve.
2011-10-06 @374
 
 Cocoa Text System everywhere...
2011-03-27 @788
 
 Blog migration
2011-01-29 @520
 
 All you need to know about the Mac keyboard
2010-08-09 @488
 
 Review: Sherlock
2010-07-31 @978
 
 Playing with Objective C on Debian
2010-05-08 @456
 
 Fruit vs. Obst
2010-05-08 @439
 
 Mixed-language ambiguity
2010-04-15 @994
 
 Uli's 12:07 AM Law
2010-04-12 @881
 
 Uli's 1:24 AM Law
2010-04-12 @874
 
 Uli's 6:28 AM Law
2010-04-12 @869
 
 Uli's 3:57 PM Law
2010-04-12 @867
 

More...

NSRectFill considered harmful

One of the most unfortunate citizens of Cocoa's AppKit is NSRectFill(). Why? Because NSRectFill( box ) is a shortcut for NSRectFillUsingOperation( box, NSCompositeCopy ). And the "copy" mode means that no compositing takes place. So, if you try to fill a 50% opaque rectangle with

[[NSColor colorWithDeviceRed: 0 green: 0 blue: 0 alpha: 0.5] set];
NSRectFill( box )
You get a nice, 100% opaque black box. Instead, you want to use:
[[NSColor colorWithDeviceRed: 0 green: 0 blue: 0 alpha: 0.5] set];
[NSBezierPath fillRect: box];

So, my suggestion is: Forget about those functions in NSGraphics.h whenever there's a method that does the same. You'll save yourself a lot of pain.

Reader Comments: (RSS Feed)
Cristian Draghici writes:
True, but NSRectFill is much faster so if alpha is not an issue you still may want to use it. Can't find the actual reference to nsrectfill, the following about stroking a rectangle: http://gemma.apple.com/documentation/Cocoa/Conceptual/CocoaPerformance/Articles/NSBezierPathTips.html#//apple_ref/doc/uid/20001877
Zbigniew Sobiecki writes:
Looks like it respects alpha now.
Comment on this article:
Name:
E-Mail: (not shown, hashed for Gravatar)
Web Site URL: (optional)
Comment: (plain text only)
Please Enter the following word:
Or E-Mail Uli privately.

 
Created: 2007-02-25 @906 Last change: 2014-12-20 @637 | Home | Admin | Edit
© Copyright 2003-2014 by M. Uli Kusterer, all rights reserved.