[Drawkit] DKImageShape swatchImageWithSize problem

Linan Wang tali.wang at gmail.com
Fri Jul 18 16:01:34 PDT 2008


Hi list,I found that the [DKImageShape swatchImageWithSize:size] method does
not work. it's due to the missing of hooking drawImage method into
drawContent method. Here is my quick and dirty fix:

- (NSImage*)swatchImageWithSize:(NSSize)size
{
NSImage* image = [[NSImage alloc] initWithSize:size];
[image setFlipped:YES];

    NSRect br = [self bounds];
float sx, sy;
 sx = br.size.width / size.width;
sy = br.size.height / size.height;
 NSAffineTransform* ot = [NSAffineTransform transform];
[ot translateXBy:-br.origin.x yBy:-br.origin.y];
[ot scaleXBy:sx yBy:sy];
    [image lockFocus];
[[NSColor clearColor] set];
NSRectFill( NSMakeRect( 0, 0, size.width, size.height ));

    [ot concat];

NSAffineTransform* xt = [self containerTransform];
 [[self transformedPath] addClip];
 NSAffineTransform*  tx = [self imageTransform];
[tx appendTransform:xt];
[tx concat];
 NSRect ir;
 ir.size = [[self image] size];
 if([self imageCroppingOptions] == kDKImageScaleToPath)
{
ir.origin.x = m_imageOffset.x - ( ir.size.width / 2.0 );
ir.origin.y = m_imageOffset.y - ( ir.size.height / 2.0 );
}
else
{
ir.origin.x = m_imageOffset.x;
ir.origin.y = m_imageOffset.y;
}
 [[self image] drawInRect:ir
fromRect:NSZeroRect
operation:NSCompositeCopy
fraction:[self imageOpacity]];

[image unlockFocus];
return [image autorelease];
}

-- 
Best regards

Linan Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20080719/954374f0/attachment.htm>


More information about the Drawkit mailing list