Re: IKImageBrowserView, drawing on layers and retina display

2014-02-10 Thread Dragan Milić
Again replying to myself…

On pon 10.02.2014., at 11.59, Dragan Milić wrote:

> The remaining issue is that strings drawn on the layer (using standard string 
> drawing methods) still don't have antialiasing.

This is also solved, perhaps it may help someone else to:
 
https://developer.apple.com/library/mac/documentation/graphicsimaging/Reference/CATextLayer_class/Introduction/Introduction.html

If a text is drawn on a non-opaque (transparent) background on a layer, it 
won't be antialiased. An opaque background on the layer (at least in the frame 
where the text will be drawn) is needed for antialiased text.

-- Dragan
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: IKImageBrowserView, drawing on layers and retina display

2014-02-10 Thread Dragan Milić
Okay, replying to myself here…

On pon 10.02.2014., at 10.30, Dragan Milić wrote:

> I haven't done many things with CALayers in the past, so maybe I'm missing 
> some setting to make this work, but it doesn't look like that looking at that 
> class' public API. On the other hand I find it hard to believe that 
> IKImageBrowserView custom drawing onto its layers is not retina-compliant!


Setting layer's contentsScale like:

[result setContentsScale:self imageBrowserView] window] screen] 
backingScaleFactor]];

solves the retina issue! Drawing on retina displays works fine now.

The remaining issue is that strings drawn on the layer (using standard string 
drawing methods) still don't have antialiasing.

-- Dragan
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

IKImageBrowserView, drawing on layers and retina display

2014-02-10 Thread Dragan Milić
I'm trying to use IKImageBrowser class for something which is supposed to 
resemble Finder's icon view appearance. Hence, I need quite customized item 
titles, e.g. multiline string, oval gradient background (like Finder's label 
indicators), etc. Customizing item's title frame and views title (setting 
custom paragraph style with custom truncating etc.) didn't give any results, 
item titles remained single-lined. And besides, I would't be able to do 
anything about other graphics element, which are part of item's title in my 
case.

Therefore I took an approach to drive item titles myself in the item's cell 
background (IKImageBrowserCellBackgroundLayer) layer. I supplied a custom 
CALayer for that layer and implemented it's drawing delegate method. Here's how 
that code looks like:

- (CALayer *)layerForType:(NSString *)aType
{
if ([aType isEqualToString:IKImageBrowserCellBackgroundLayer])
{
CALayer *result = [CALayer layer];

[result setDelegate:self];
[result setFrame:[self frame]];
[result setName:aType];

[result setNeedsDisplay];

return result;
}

return [super layerForType:aType];
}

- (void)drawLayer:(CALayer *)aLayer inContext:(CGContextRef)aContext
{
if ([[aLayer name] isEqualToString:IKImageBrowserCellBackgroundLayer])
{
// Set the current context.
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext 
graphicsContextWithGraphicsPort:aContext flipped:[self imageBrowserView]]];

// Draw here...

[NSGraphicsContext restoreGraphicsState];
}
}

This works fine in general, but I'm facing two problems I can't find a way to 
solve:

1.   All string drawing in the cell's background layer appear without 
antialiasing. Other drawing (Bezier Paths, images…) produce expected results.

2.   All drawing in the cell's background layer in NOT retina-compliant! Not 
strings, not any other drawing.

I should note that I used standard NSImage, NSBezierPath and NSString drawing 
methods. Drawing exactly the same contents with the same code in a custom view 
produces expected results (antialiased strings, all fine on both non-retina and 
retina screens).

I haven't done many things with CALayers in the past, so maybe I'm missing some 
setting to make this work, but it doesn't look like that looking at that class' 
public API. On the other hand I find it hard to believe that IKImageBrowserView 
custom drawing onto its layers is not retina-compliant!

If necessary, I can provide sample snapshots of results on displays of both 
type.

Hopefully will someone know how to solve this. Thanks in advance.

-- Dragan
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com