Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Darken image



On Friday, July 20, 2001, at 12:44 , Tom Waters wrote:

well, i just wrote a tiny test harness for it, and it works as advertised.
..

this is a simple nsview subclass that lets you drag around the application icon... it shows the darkened one while you are dragging...

let me know if it doesn't work for you.

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
operation: NSCompositeCopy fraction: 1.0];

[im unlockFocus];
icon = im;
}

[icon drawInRect: imageRect fromRect: theRect
operation: NSCompositeSourceOver fraction: 1.0];

...all icons are scaled down (non-proportional).


What the hell is going on here?

andy
--
Description forthcoming.


References: 
 >Re: Darken image (From: Tom Waters <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.