// // DSImageCategories.m // Shared categories // // Created by David Sinclair on Fri Oct 11 2002. // Copyright © 2002 - 2007 Dejal Systems, LLC. All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // Redistributions of source code must retain this list of conditions and the following disclaimer. // // The name of Dejal Systems, LLC may not be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE AUTHORS OR // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS SOFTWARE. // #import "DSImageCategories.h" @implementation NSImage (DSImageCategories) - (void)drawFlippedInRect:(NSRect)rect operation:(NSCompositingOperation)op fraction:(float)delta { CGContextRef context; context = [[NSGraphicsContext currentContext] graphicsPort]; CGContextSaveGState(context); { CGContextTranslateCTM(context, 0, NSMaxY(rect)); CGContextScaleCTM(context, 1, -1); rect.origin.y = 0; [self drawInRect:rect fromRect:NSZeroRect operation:op fraction:delta]; } CGContextRestoreGState(context); } - (void)drawFlippedInRect:(NSRect)rect operation:(NSCompositingOperation)op { [self drawFlippedInRect:rect operation:op fraction:1.0]; } - (void)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale { NSImage *newBadge; if (!badge) return; newBadge = [[badge copy] autorelease]; [newBadge setScalesWhenResized:YES]; [newBadge setSize:NSMakeSize([self size].width * scale,[self size].height * scale)]; [self lockFocus]; [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; [newBadge dissolveToPoint:NSMakePoint([self size].width - [newBadge size].width,0) fraction:alpha]; [self unlockFocus]; } @end