From 239b3c9abb62d2c96e9b7f2f5cdd1f219756e44c Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Tue, 24 Jul 2012 17:00:40 -0700 Subject: [PATCH] Refactored TUICGAdditions to use NSImage --- lib/UIKit/TUICGAdditions.h | 9 ++++----- lib/UIKit/TUICGAdditions.m | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/UIKit/TUICGAdditions.h b/lib/UIKit/TUICGAdditions.h index c8198849..3a093128 100644 --- a/lib/UIKit/TUICGAdditions.h +++ b/lib/UIKit/TUICGAdditions.h @@ -29,7 +29,6 @@ typedef NSUInteger TUICGRoundedRectCorner; #import -@class TUIImage; @class TUIView; extern CGContextRef TUICreateOpaqueGraphicsContext(CGSize size); @@ -55,16 +54,16 @@ extern CGContextRef TUIGraphicsGetCurrentContext(void); extern void TUIGraphicsPushContext(CGContextRef context); extern void TUIGraphicsPopContext(void); -extern TUIImage *TUIGraphicsContextGetImage(CGContextRef ctx); +extern NSImage *TUIGraphicsContextGetImage(CGContextRef ctx); extern void TUIGraphicsBeginImageContext(CGSize size); extern void TUIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale); -extern TUIImage *TUIGraphicsGetImageFromCurrentImageContext(void); +extern NSImage *TUIGraphicsGetImageFromCurrentImageContext(void); extern void TUIGraphicsEndImageContext(void); -extern TUIImage *TUIGraphicsGetImageForView(TUIView *view); +extern NSImage *TUIGraphicsGetImageForView(TUIView *view); -extern TUIImage *TUIGraphicsDrawAsImage(CGSize size, void(^draw)(void)); +extern NSImage *TUIGraphicsDrawAsImage(CGSize size, void(^draw)(void)); /** Draw drawing as a PDF diff --git a/lib/UIKit/TUICGAdditions.m b/lib/UIKit/TUICGAdditions.m index 74f40e3c..d967a5c8 100644 --- a/lib/UIKit/TUICGAdditions.m +++ b/lib/UIKit/TUICGAdditions.m @@ -15,7 +15,6 @@ */ #import "TUICGAdditions.h" -#import "TUIImage.h" #import "TUIView.h" CGContextRef TUICreateOpaqueGraphicsContext(CGSize size) @@ -194,10 +193,11 @@ void TUIGraphicsPopContext(void) [NSGraphicsContext restoreGraphicsState]; } -TUIImage* TUIGraphicsContextGetImage(CGContextRef ctx) +NSImage *TUIGraphicsContextGetImage(CGContextRef ctx) { CGImageRef CGImage = TUICreateCGImageFromBitmapContext(ctx); - TUIImage *image = [TUIImage imageWithCGImage:CGImage]; + CGSize size = CGSizeMake(CGImageGetWidth(CGImage), CGImageGetHeight(CGImage)); + NSImage *image = [[NSImage alloc] initWithCGImage:CGImage size:size]; CGImageRelease(CGImage); return image; @@ -219,17 +219,18 @@ void TUIGraphicsBeginImageContext(CGSize size) TUIGraphicsBeginImageContextWithOptions(size, NO, 1.0f); } -TUIImage* TUIGraphicsGetImageFromCurrentImageContext(void) +NSImage *TUIGraphicsGetImageFromCurrentImageContext(void) { return TUIGraphicsContextGetImage(TUIGraphicsGetCurrentContext()); } -TUIImage* TUIGraphicsGetImageForView(TUIView *view) +NSImage *TUIGraphicsGetImageForView(TUIView *view) { TUIGraphicsBeginImageContext(view.frame.size); [view.layer renderInContext:TUIGraphicsGetCurrentContext()]; - TUIImage *image = TUIGraphicsGetImageFromCurrentImageContext(); + NSImage *image = TUIGraphicsGetImageFromCurrentImageContext(); TUIGraphicsEndImageContext(); + return image; } @@ -238,12 +239,13 @@ void TUIGraphicsEndImageContext(void) TUIGraphicsPopContext(); } -TUIImage *TUIGraphicsDrawAsImage(CGSize size, void(^draw)(void)) +NSImage *TUIGraphicsDrawAsImage(CGSize size, void(^draw)(void)) { TUIGraphicsBeginImageContext(size); draw(); - TUIImage *image = TUIGraphicsGetImageFromCurrentImageContext(); + NSImage *image = TUIGraphicsGetImageFromCurrentImageContext(); TUIGraphicsEndImageContext(); + return image; }