Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSRectFill does not render alpha component

NSRectFill does not render alpha component
Thread Tools
jonsaunders
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Mar 14, 2002, 05:35 PM
 
When using NSRectFill with a colour set with an alpha component, the fill rect is not transparent, but if I use a NSBezierPath the rect is transparent.

thus

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
-(void)drawRect NSRect*) aRect
{
[[[NSColor whiteColor] colorWithAlphaComponent:<font color = blue>0.5</font>] set];
NSRectFill(aRect)
</font>[/code]

... no transparency...

but

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> -(void)drawRect NSRect*) aRect
{
NSBezierPath *path;
[[[NSColor whiteColor] colorWithAlphaComponent:<font color = blue>0.5</font>] set];
path = [NSBezierPath bezierPathWithRect:aRect];
[path fill];
</font>[/code]
...draws transparent...

Does anyone know if there is a reason for this or is it a bug?

Cheers,

Jon
     
lindberg
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Mar 15, 2002, 04:35 PM
 
I think NSRectFill() uses NSCompositeCopy (i.e. replace the existing color) when drawing. I've not actually done this myself, but you might want to try NSRectFillUsingOperation() using NSCompositeSourceOver as the operation.
     
jonsaunders  (op)
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Mar 15, 2002, 05:25 PM
 
That works! Cheers!

Now I am having fun with images made up from data from drawn NSViews. The only problem is that I get a black background for my images and cannot get rid of it

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
- (void)drawRect NSRect)rect
{
NSRect xrect;
NSBezierPath* path;

[[NSColor clearColor] set];
path = [NSBezierPath bezierPathWithRect:rect];
[path fill];

xrect = NSMakeRect(<font color = blue>10</font>,<font color = blue>10</font>,<font color = blue>10</font>,<font color = blue>10</font>);

[[NSColor redColor] set];

NSRectFill(xrect);
}

-(NSImage*)imageData
{
return [[NSImage alloc] initWithData:[self dataWithPDFInsideRect:[self bounds]]];
}

</font>[/code]

in my back view and

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>

backView = [[WSBackView alloc] initWithFrame:aRect];
image = [backView imageData];

[image compositeToPoint:NSMakePoint(<font color = blue>0</font>,<font color = blue>0</font>) operation:NSCompositeSourceOver];

</font>[/code]

in the drawRect of my visible view. I am stuck with a black background..

Any Ideas?

Jon.
     
jonsaunders  (op)
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Mar 17, 2002, 12:59 PM
 
I've now sorted it!

I've been doing completely the wrong thing in using a hidden NSView (but I am new to Cocoa!). The correct way is to use a NSCustomImageRep with a delegate draw function. See the CompositeLab sample app in the apple developer samples if you want to know how..

(I am adding this post so that anyone else having the same problems will not fall into the same trap).

Also if you get a strange set of errors with NSCalibratedWhiteColor involved it may be due to you not returning self back from an initWithFrame...

Still having fun,

Jon.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:41 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,