Re: Darken image
Re: Darken image
- Subject: Re: Darken image
- From: Tom Waters <email@hidden>
- Date: Thu, 19 Jul 2001 17:18:48 -0700
assuming the method signature that you left out was:
- (void)drawRect:(NSRect)theRect
you are using theRect (which has nothing to do with the size of
anything, since it's merely the rectangle that has been exposed via the
union of a bunch of calls to needsDisplayInRect) as the fromRect
parameter in your call to drawInRect... this would cause random results..
use NSZeroRect there to indicate you want the whole source image.
[icon drawInRect: imageRect fromRect: NSZeroRect
operation: NSCompositeSourceOver fraction: 1.0];
I've hacked on a more complete version of the sample I sent you last
time, I'll send it along in the next email...
-Tom
On Thursday, July 19, 2001, at 05:09 PM, Andreas Monitzer wrote:
>
Yes, your example works fine. However, when I try to insert it into my
>
code, it goes crazy.
>
>
Here's what I converted it to:
>
>
// theRect = the NSRect I got via drawRect
>
// imageRect = the NSRect I should draw into (part of theRect)
>
if (selected) {
>
NSSize iconSize = [icon size];
>
NSRect iconRect = {NSZeroPoint, iconSize};
>
NSImage *im = [[icon copyWithZone:[self zone]] autorelease];
>
>
[im lockFocus];
>
[im unlockFocus];
>
icon = im;
>
}
>
>
[icon drawInRect: imageRect fromRect: theRect
>
operation: NSCompositeSourceOver fraction: 1.0];
>
>
When selected==NO, everything is fine. But when it's YES, the icon is
>
scaled up, scaled down, changes DPI or does something else (depends on
>
the icon). When I remove lockFocus and unlockFocus, it's fine again,
>
but I can'
>
t draw into it!
>
>
When using this code...
>
>
if (selected) {
>
NSSize iconSize = [icon size];
>
NSRect iconRect = {NSZeroPoint, iconSize};
>
NSImage *im = [[[NSImage alloc] initWithSize: iconSize]
>
autorelease];
>
>
[im lockFocus];
>
// copy the icon into the new one
>
[icon drawInRect: iconRect fromRect: theRect /*** BAD ***/
>
operation: NSCompositeCopy fraction: 1.0];
>
>
[im unlockFocus];
>
icon = im;
>
}
>
>
[icon drawInRect: imageRect fromRect: theRect /**** BAD ***/
>
operation: NSCompositeSourceOver fraction: 1.0];
>
>
...all icons are scaled down (non-proportional).
>
>
>
What the hell is going on here?