gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Icon size auto-selection implemented


From: Eric Wasylishen
Subject: Icon size auto-selection implemented
Date: Fri, 17 Jun 2011 13:19:08 -0600

Hey,
Support for NSImage using the best size available when drawing icons is now in 
place; check out the ImageSelection test in GSTest for a demo. 

It happens at the -drawInRect:.. level, so for example if you image has reps at 
16x16 pt and 32x32 pt, and you draw in a 16x16 pt rect, it will use the 16x16 
rep. If you draw in a 18x18pt rect, it will use the 32x32 pt rep and scale it 
down. It works equally well with TIFF and ICNS images.

I also rewrote the best rep selection code; now it is very close to following 
the rules in the cocoa drawing guide.


Some quirks to watch out for:

- If you use TIFF, you have to be careful that the sub-images have the same 
properties (colorspace, bits per pixel). I had to fix some of the high-res 
versions of the common_3DArrow images I made because I accidentally made one 
sub-image greyscale and one RGB - if you do this, the rep selection code will 
discard the greyscale images (unless you happen to be rendering on a device 
that is marked as greyscale..)

- This feature is orthogonal to the existing support for filtering the image 
reps that best match the resolution (DPI) of the device. You could make an icon 
with one set of images from 16x16 pt to 512x512 pt at 72DPI, and then another 
set covering the same range of point sizes at 288 DPI, and the rep selection 
code should "just work".

- The nature of having different point sized representations in an image means 
that -[NSImage size] becomes unreliable. i.e. with code like the following, 
it's not clear how large the resulting drawing will be:

NSImage *img = [NSImage imageNamed: @"someIcon"];
NSSize s = [img size];  // since the image contains 16x16 pt up to 512x512 pt, 
who knows what this is?
[img drawInRect: NSMakeRect(100, 100, s.width, s.height) ...];

or

[img compositeToPoint: NSMakePoint(x, y) ... ];

Right now if you make an app icon that includes sizes 16x16 to 512x512, the 
application's "about" window uses the 512x512 rep, making the window huge.

In my limited testing on Cocoa, -size seems to arbitrarily return 128x128 for 
.ICNS files, and it returns the size of the last sub-image in a TIFF. Right now 
in GS I think it will return the size of the last rep returned by 
-bestRepresentationForDevice: nil.


Regards,

Eric


reply via email to

[Prev in Thread] Current Thread [Next in Thread]