Permalink
Browse files

Refactoring to change uses of TUIColor to NSColor

  • Loading branch information...
jspahrsummers committed Jul 27, 2012
1 parent a8dfa16 commit ce1fef35304fb984d47789c9b678fb1146d2a64c
@@ -17,7 +17,6 @@
#import <Cocoa/Cocoa.h>
#import "TUIGeometry.h"
-@class TUIColor;
@class TUIStretchableImage;
@interface NSImage (TUIExtensions)
@@ -63,6 +62,6 @@
- (NSImage *)tui_roundImage:(CGFloat)radius;
- (NSImage *)tui_invertedMask;
- (NSImage *)tui_embossMaskWithOffset:(CGSize)offset; // subtract reciever from itself offset by 'offset', use as a mask to draw emboss
-- (NSImage *)tui_innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(TUIColor *)color backgroundColor:(TUIColor *)backgroundColor; // 'backgroundColor' is used as the color the shadow is drawn with, it is mostly masked out, but a halo will remain, leading to artifacts unless it is close enough to the background color
+- (NSImage *)tui_innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(NSColor *)color backgroundColor:(NSColor *)backgroundColor; // 'backgroundColor' is used as the color the shadow is drawn with, it is mostly masked out, but a halo will remain, leading to artifacts unless it is close enough to the background color
@end
@@ -15,8 +15,8 @@
*/
#import "NSImage+TUIExtensions.h"
+#import "NSColor+TUIExtensions.h"
#import "TUICGAdditions.h"
-#import "TUIColor.h"
#import "TUIStretchableImage.h"
@implementation NSImage (TUIExtensions)
@@ -162,21 +162,22 @@ - (NSImage *)tui_invertedMask
}];
}
-- (NSImage *)tui_innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(TUIColor *)color backgroundColor:(TUIColor *)backgroundColor
+- (NSImage *)tui_innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(NSColor *)color backgroundColor:(NSColor *)backgroundColor
{
CGFloat padding = ceil(radius);
NSImage *paddedImage = [self tui_pad:padding];
NSImage *shadowImage = [NSImage tui_imageWithSize:paddedImage.size drawing:^(CGContextRef ctx) {
CGContextSaveGState(ctx);
CGRect r = CGRectMake(0, 0, paddedImage.size.width, paddedImage.size.height);
CGContextClipToMask(ctx, r, paddedImage.tui_CGImage); // clip to image
- CGContextSetShadowWithColor(ctx, offset, radius, color.CGColor);
+ CGContextSetShadowWithColor(ctx, offset, radius, color.tui_CGColor);
CGContextBeginTransparencyLayer(ctx, NULL);
{
CGContextClipToMask(ctx, r, [[paddedImage tui_invertedMask] tui_CGImage]); // clip to inverted
- CGContextSetFillColorWithColor(ctx, backgroundColor.CGColor);
+ CGContextSetFillColorWithColor(ctx, backgroundColor.tui_CGColor);
CGContextFillRect(ctx, r); // draw with shadow
}
+
CGContextEndTransparencyLayer(ctx);
CGContextRestoreGState(ctx);
}];
@@ -15,7 +15,6 @@
*/
#import "TUIActivityIndicatorView.h"
-#import "TUIColor.h"
@implementation TUIActivityIndicatorView
@@ -26,7 +25,7 @@ - (id)initWithActivityIndicatorStyle:(TUIActivityIndicatorViewStyle)style
_activityIndicatorViewStyle = style;
spinner = [[TUIView alloc] initWithFrame:self.bounds];
- spinner.backgroundColor = [TUIColor blackColor];
+ spinner.backgroundColor = [NSColor blackColor];
spinner.alpha = 0.2;
spinner.layer.cornerRadius = 10.0;
[self addSubview:spinner];
@@ -20,8 +20,6 @@ extern NSString * const TUIAttributedStringBackgroundColorAttributeName;
extern NSString * const TUIAttributedStringBackgroundFillStyleName;
extern NSString * const TUIAttributedStringPreDrawBlockName;
-@class TUIColor;
-
typedef void (^TUIAttributedStringPreDrawBlock)(NSAttributedString *attributedString, NSRange substringRange, CGRect rects[], CFIndex rectCount);
typedef enum {
@@ -61,8 +59,8 @@ typedef enum {
// write-only properties, reading will return nil
@property (nonatomic, retain) NSFont *font;
-@property (nonatomic, retain) TUIColor *color;
-@property (nonatomic, retain) TUIColor *backgroundColor;
+@property (nonatomic, retain) NSColor *color;
+@property (nonatomic, retain) NSColor *backgroundColor;
@property (nonatomic, assign) TUIBackgroundFillStyle backgroundFillStyle;
@property (nonatomic, retain) NSShadow *shadow;
@property (nonatomic, assign) TUITextAlignment alignment; // setting this will set lineBreakMode to word wrap, use setAlignment:lineBreakMode: for more control
@@ -74,8 +72,8 @@ typedef enum {
- (NSRange)_stringRange;
- (void)setFont:(NSFont *)font inRange:(NSRange)range;
-- (void)setColor:(TUIColor *)color inRange:(NSRange)range;
-- (void)setBackgroundColor:(TUIColor *)color inRange:(NSRange)range;
+- (void)setColor:(NSColor *)color inRange:(NSRange)range;
+- (void)setBackgroundColor:(NSColor *)color inRange:(NSRange)range;
- (void)setBackgroundFillStyle:(TUIBackgroundFillStyle)fillStyle inRange:(NSRange)range;
- (void)setPreDrawBlock:(TUIAttributedStringPreDrawBlock)block inRange:(NSRange)range; // the pre-draw block is called before the text or text background has been drawn
- (void)setShadow:(NSShadow *)shadow inRange:(NSRange)range;
@@ -86,7 +84,7 @@ typedef enum {
@interface NSShadow (TUIAdditions)
-+ (NSShadow *)shadowWithRadius:(CGFloat)radius offset:(CGSize)offset color:(TUIColor *)color;
++ (NSShadow *)shadowWithRadius:(CGFloat)radius offset:(CGSize)offset color:(NSColor *)color;
@end
@@ -15,7 +15,6 @@
*/
#import "TUIAttributedString.h"
-#import "TUIColor.h"
NSString * const TUIAttributedStringBackgroundColorAttributeName = @"TUIAttributedStringBackgroundColorAttributeName";
NSString * const TUIAttributedStringBackgroundFillStyleName = @"TUIAttributedStringBackgroundFillStyleName";
@@ -47,9 +46,9 @@ - (void)setFont:(NSFont *)font inRange:(NSRange)range
}
}
-- (void)setColor:(TUIColor *)color inRange:(NSRange)range
+- (void)setColor:(NSColor *)color inRange:(NSRange)range
{
- [self addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[color CGColor] range:range];
+ [self addAttribute:NSForegroundColorAttributeName value:color range:range];
}
- (void)setShadow:(NSShadow *)shadow inRange:(NSRange)range
@@ -67,19 +66,19 @@ - (void)setFont:(NSFont *)font
[self setFont:font inRange:[self _stringRange]];
}
-- (void)setColor:(TUIColor *)color
+- (void)setColor:(NSColor *)color
{
[self setColor:color inRange:[self _stringRange]];
}
-- (void)setBackgroundColor:(TUIColor *)color
+- (void)setBackgroundColor:(NSColor *)color
{
[self setBackgroundColor:color inRange:[self _stringRange]];
}
-- (void)setBackgroundColor:(TUIColor *)color inRange:(NSRange)range
+- (void)setBackgroundColor:(NSColor *)color inRange:(NSRange)range
{
- [self addAttribute:TUIAttributedStringBackgroundColorAttributeName value:(id)[color CGColor] range:range];
+ [self addAttribute:TUIAttributedStringBackgroundColorAttributeName value:color range:range];
}
- (void)setBackgroundFillStyle:(TUIBackgroundFillStyle)fillStyle
@@ -208,7 +207,7 @@ - (NSFont *)font
return nil;
}
-- (TUIColor *)color
+- (NSColor *)color
{
return nil;
}
@@ -233,7 +232,7 @@ - (CGFloat)lineHeight
return 0.0;
}
-- (TUIColor *)backgroundColor
+- (NSColor *)backgroundColor
{
return nil;
}
@@ -258,12 +257,12 @@ - (void)setText:(NSString *)text {
@implementation NSShadow (TUIAdditions)
-+ (NSShadow *)shadowWithRadius:(CGFloat)radius offset:(CGSize)offset color:(TUIColor *)color
++ (NSShadow *)shadowWithRadius:(CGFloat)radius offset:(CGSize)offset color:(NSColor *)color
{
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowBlurRadius:radius];
[shadow setShadowOffset:offset];
- [shadow setShadowColor:[color nsColor]];
+ [shadow setShadowColor:color];
return shadow;
}
@@ -19,8 +19,8 @@
@interface TUIButtonContent : NSObject
@property (nonatomic, strong) NSString *title;
-@property (nonatomic, strong) TUIColor *titleColor;
-@property (nonatomic, strong) TUIColor *shadowColor;
+@property (nonatomic, strong) NSColor *titleColor;
+@property (nonatomic, strong) NSColor *shadowColor;
@property (nonatomic, strong) NSImage *image;
@property (nonatomic, strong) NSImage *backgroundImage;
@end
@@ -55,15 +55,15 @@ - (void)setTitle:(NSString *)title forState:(TUIControlState)state
[self _stateDidChange];
}
-- (void)setTitleColor:(TUIColor *)color forState:(TUIControlState)state
+- (void)setTitleColor:(NSColor *)color forState:(TUIControlState)state
{
[self _stateWillChange];
[[self _contentForState:state] setTitleColor:color];
[self setNeedsDisplay];
[self _stateDidChange];
}
-- (void)setTitleShadowColor:(TUIColor *)color forState:(TUIControlState)state
+- (void)setTitleShadowColor:(NSColor *)color forState:(TUIControlState)state
{
[self _stateWillChange];
[[self _contentForState:state] setShadowColor:color];
@@ -92,12 +92,12 @@ - (NSString *)titleForState:(TUIControlState)state
return [[self _contentForState:state] title];
}
-- (TUIColor *)titleColorForState:(TUIControlState)state
+- (NSColor *)titleColorForState:(TUIControlState)state
{
return [[self _contentForState:state] titleColor];
}
-- (TUIColor *)titleShadowColorForState:(TUIControlState)state
+- (NSColor *)titleShadowColorForState:(TUIControlState)state
{
return [[self _contentForState:state] shadowColor];
}
@@ -122,19 +122,19 @@ - (NSString *)currentTitle
return title;
}
-- (TUIColor *)currentTitleColor
+- (NSColor *)currentTitleColor
{
- TUIColor *color = [self titleColorForState:self.state];
+ NSColor *color = [self titleColorForState:self.state];
if(color == nil) {
color = [self titleColorForState:TUIControlStateNormal];
}
return color;
}
-- (TUIColor *)currentTitleShadowColor
+- (NSColor *)currentTitleShadowColor
{
- TUIColor *color = [self titleShadowColorForState:self.state];
+ NSColor *color = [self titleShadowColorForState:self.state];
if(color == nil) {
color = [self titleShadowColorForState:TUIControlStateNormal];
}
View
@@ -74,20 +74,20 @@ typedef enum {
@interface TUIButton (Content)
- (void)setTitle:(NSString *)title forState:(TUIControlState)state;
-- (void)setTitleColor:(TUIColor *)color forState:(TUIControlState)state;
-- (void)setTitleShadowColor:(TUIColor *)color forState:(TUIControlState)state;
+- (void)setTitleColor:(NSColor *)color forState:(TUIControlState)state;
+- (void)setTitleShadowColor:(NSColor *)color forState:(TUIControlState)state;
- (void)setImage:(NSImage *)image forState:(TUIControlState)state;
- (void)setBackgroundImage:(NSImage *)image forState:(TUIControlState)state;
- (NSString *)titleForState:(TUIControlState)state;
-- (TUIColor *)titleColorForState:(TUIControlState)state;
-- (TUIColor *)titleShadowColorForState:(TUIControlState)state;
+- (NSColor *)titleColorForState:(TUIControlState)state;
+- (NSColor *)titleShadowColorForState:(TUIControlState)state;
- (NSImage *)imageForState:(TUIControlState)state;
- (NSImage *)backgroundImageForState:(TUIControlState)state;
@property(nonatomic, readonly, strong) NSString *currentTitle;
-@property(nonatomic, readonly, strong) TUIColor *currentTitleColor;
-@property(nonatomic, readonly, strong) TUIColor *currentTitleShadowColor;
+@property(nonatomic, readonly, strong) NSColor *currentTitleColor;
+@property(nonatomic, readonly, strong) NSColor *currentTitleShadowColor;
@property(nonatomic, readonly, strong) NSImage *currentImage;
@property(nonatomic, readonly, strong) NSImage *currentBackgroundImage;
@end
View
@@ -16,7 +16,6 @@
#import "TUIButton.h"
#import "TUICGAdditions.h"
-#import "TUIColor.h"
#import "TUIControl+Private.h"
#import "TUIImageView.h"
#import "TUILabel.h"
@@ -43,7 +42,7 @@ - (id)initWithFrame:(CGRect)frame
_buttonFlags.buttonType = TUIButtonTypeCustom;
_buttonFlags.dimsInBackground = 1;
_buttonFlags.firstDraw = 1;
- self.backgroundColor = [TUIColor clearColor];
+ self.backgroundColor = [NSColor clearColor];
self.needsDisplayWhenWindowsKeyednessChanges = YES;
self.reversesTitleShadowWhenHighlighted = NO;
}
@@ -97,7 +96,7 @@ - (TUILabel *)titleLabel
if(!_titleView) {
_titleView = [[TUILabel alloc] initWithFrame:CGRectZero];
_titleView.userInteractionEnabled = NO;
- _titleView.backgroundColor = [TUIColor clearColor];
+ _titleView.backgroundColor = [NSColor clearColor];
_titleView.hidden = YES; // we'll be drawing it ourselves
[self addSubview:_titleView];
}
@@ -108,7 +107,7 @@ - (TUIImageView *)imageView
{
if(!_imageView) {
_imageView = [[TUIImageView alloc] initWithFrame:CGRectZero];
- _imageView.backgroundColor = [TUIColor clearColor];
+ _imageView.backgroundColor = [NSColor clearColor];
_imageView.hidden = YES;
}
return _imageView;
@@ -215,12 +214,12 @@ - (void)drawRect:(CGRect)r
_titleView.text = title;
}
- TUIColor *color = self.currentTitleColor;
+ NSColor *color = self.currentTitleColor;
if(color != nil) {
_titleView.textColor = color;
}
- TUIColor *shadowColor = self.currentTitleShadowColor;
+ NSColor *shadowColor = self.currentTitleShadowColor;
// they may have manually set the renderer's shadow color, in which case we
// don't want to reset it to nothing
if(shadowColor != nil) {
View
@@ -23,27 +23,12 @@
*/
@interface TUILabel : TUIView
-{
- TUITextRenderer *renderer;
- struct {
- unsigned int selectable:1;
- } _textLabelFlags;
-
- NSString *_text;
- NSFont *_font;
- TUIColor *_textColor;
- TUITextAlignment _alignment;
- TUILineBreakMode _lineBreakMode;
-}
-
-@property(nonatomic,copy) NSString *text;
-@property(nonatomic,strong) NSAttributedString *attributedString;
-
-@property(nonatomic,getter=isSelectable) BOOL selectable;
+@property(nonatomic, copy) NSString *text;
+@property(nonatomic, strong) NSAttributedString *attributedString;
+@property(nonatomic, getter=isSelectable) BOOL selectable;
@property(nonatomic, readonly) TUITextRenderer *renderer;
-@property(nonatomic,strong) NSFont *font;
-@property(nonatomic,strong) TUIColor *textColor;
-@property(nonatomic,assign) TUITextAlignment alignment;
+@property(nonatomic, strong) NSFont *font;
+@property(nonatomic, strong) NSColor *textColor;
+@property(nonatomic, assign) TUITextAlignment alignment;
@property(nonatomic, assign) TUILineBreakMode lineBreakMode;
-
@end
View
@@ -15,13 +15,17 @@
*/
#import "TUILabel.h"
-#import "TUIColor.h"
#import "TUINSView.h"
#import "TUIStringDrawing.h"
#import "TUITextRenderer.h"
#import "TUIView+Private.h"
-@interface TUILabel ()
+@interface TUILabel () {
+ struct {
+ unsigned int selectable:1;
+ } _textLabelFlags;
+}
+
- (void)_recreateAttributedString;
@end
@@ -138,7 +142,7 @@ - (void)setFont:(NSFont *)font
self.attributedString = nil;
}
-- (void)setTextColor:(TUIColor *)textColor
+- (void)setTextColor:(NSColor *)textColor
{
if(textColor == _textColor) return;
Oops, something went wrong.

0 comments on commit ce1fef3

Please sign in to comment.