Use NSImage’s respectFlipped: parameter instead of custom code

This commit is contained in:
Allan Odgaard
2014-11-05 09:17:17 +01:00
parent b20d7610ac
commit fb929bdfdd
4 changed files with 2 additions and 39 deletions

View File

@@ -1,6 +1,3 @@
@interface NSImage (ImageFromBundle)
+ (NSImage*)imageNamed:(NSString*)aName inSameBundleAsClass:(id)anObject;
- (void)drawAdjustedAtPoint:(NSPoint)aPoint fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op fraction:(CGFloat)delta;
- (void)drawAdjustedInRect:(NSRect)dstRect fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op fraction:(CGFloat)delta;
@end

View File

@@ -21,36 +21,4 @@
return nil;
}
// ===================================================
// = Gracefully draw in potentially flipped contexts =
// ===================================================
- (void)drawAdjustedAtPoint:(NSPoint)aPoint fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op fraction:(CGFloat)delta
{
[self drawAdjustedInRect:(NSRect){ aPoint, [self size] } fromRect:srcRect operation:op fraction:delta];
}
- (void)drawAdjustedInRect:(NSRect)dstRect fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op fraction:(CGFloat)delta
{
NSGraphicsContext* context = [NSGraphicsContext currentContext];
if([context isFlipped])
{
[context saveGraphicsState];
NSAffineTransform* transform = [NSAffineTransform transform];
[transform translateXBy:0 yBy:NSMaxY(dstRect)];
[transform scaleXBy:1 yBy:-1];
[transform concat];
dstRect.origin.y = 0; // The transform above places the y-origin right where the image should be drawn.
[self drawInRect:dstRect fromRect:srcRect operation:op fraction:delta];
[context restoreGraphicsState];
}
else
{
[self drawInRect:dstRect fromRect:srcRect operation:op fraction:delta];
}
}
@end

View File

@@ -1,5 +1,4 @@
#import "OakImageAndTextCell.h"
#import "NSImage Additions.h"
@implementation OakImageAndTextCell
{
@@ -62,7 +61,7 @@
[[self backgroundColor] set];
NSRectFill(imageRect);
}
[self.image drawAdjustedInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
[self.image drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1 respectFlipped:YES hints:nil];
}
[super drawWithFrame:[self textFrameWithFrame:cellFrame inControlView:controlView] inView:controlView];

View File

@@ -1,5 +1,4 @@
#import "OakPopOutAnimation.h"
#import "NSImage Additions.h"
#import <oak/algorithm.h>
#import <oak/debug.h>
@@ -128,7 +127,7 @@ static double bounce_curve (double t)
[[NSColor whiteColor] set];
[roundedRect stroke];
[self.contentImage drawAdjustedInRect:NSInsetRect([self bounds], kExtendWidth, kExtendHeight) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
[self.contentImage drawInRect:NSInsetRect([self bounds], kExtendWidth, kExtendHeight) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1 respectFlipped:YES hints:nil];
[super drawRect:aRect];
}