Permalink
Browse files

Refactored TUIColor to use NSImage

  • Loading branch information...
1 parent fd1b8b6 commit b90a0e629f713ea74876b5b961499b2da3f8af82 @jspahrsummers jspahrsummers committed Jul 24, 2012
Showing with 10 additions and 10 deletions.
  1. +2 −4 lib/UIKit/TUIColor.h
  2. +8 −6 lib/UIKit/TUIColor.m
@@ -16,8 +16,6 @@
#import <Foundation/Foundation.h>
-@class TUIImage;
-
@interface TUIColor : NSObject
{
CGColorRef _cgColor; // backing color
@@ -28,12 +26,12 @@
+ (TUIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
+ (TUIColor *)colorWithCGColor:(CGColorRef)cgColor;
+ (TUIColor *)colorWithNSColor:(NSColor *)nsColor;
-+ (TUIColor *)colorWithPatternImage:(TUIImage *)image;
++ (TUIColor *)colorWithPatternImage:(NSImage *)image;
- (TUIColor *)initWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
- (TUIColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (TUIColor *)initWithCGColor:(CGColorRef)cgColor;
-- (TUIColor *)initWithPatternImage:(TUIImage *)image;
+- (TUIColor *)initWithPatternImage:(NSImage *)image;
// cached
+ (TUIColor *)blackColor; // 0.0 white
View
@@ -16,11 +16,10 @@
#import "TUIColor.h"
#import "TUICGAdditions.h"
-#import "TUIImage.h"
@implementation TUIColor
-+ (TUIColor *)colorWithPatternImage:(TUIImage *)image
++ (TUIColor *)colorWithPatternImage:(NSImage *)image
{
return [[self alloc] initWithPatternImage:image];
}
@@ -76,20 +75,23 @@ - (TUIColor *)initWithCGColor:(CGColorRef)cgColor
static void patternDraw(void *info, CGContextRef ctx)
{
- TUIImage *image = (__bridge TUIImage *)info;
+ NSImage *image = (__bridge NSImage *)info;
+
CGRect rect;
rect.origin = CGPointZero;
rect.size = image.size;
- CGContextDrawImage(ctx, rect, image.CGImage);
+
+ CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil];
+ CGContextDrawImage(ctx, rect, cgImage);
}
static void patternRelease(void *info)
{
// transfer the object back to ARC, thus releasing it
- (void)(__bridge_transfer TUIImage *)info;
+ (void)(__bridge_transfer NSImage *)info;
}
-- (TUIColor *)initWithPatternImage:(TUIImage *)image
+- (TUIColor *)initWithPatternImage:(NSImage *)image
{
if((self = [super init]))
{

0 comments on commit b90a0e6

Please sign in to comment.