Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored TUIButton to use NSImage

  • Loading branch information...
commit 5467b74f3b5341df11b91d3e6822d4a4c8a5b9ac 1 parent b90a0e6
Justin Spahr-Summers jspahrsummers authored
43 lib/UIKit/TUIButton+Content.m
View
@@ -16,34 +16,21 @@
#import "TUIButton.h"
#import "TUIControl+Private.h"
-#import "TUIImage.h"
@interface TUIButtonContent : NSObject
-{
- NSString *title;
- TUIColor *titleColor;
- TUIColor *shadowColor;
- TUIImage *image;
- TUIImage *backgroundImage;
-}
-
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) TUIColor *titleColor;
@property (nonatomic, strong) TUIColor *shadowColor;
-@property (nonatomic, strong) TUIImage *image;
-@property (nonatomic, strong) TUIImage *backgroundImage;
-
+@property (nonatomic, strong) NSImage *image;
+@property (nonatomic, strong) NSImage *backgroundImage;
@end
@implementation TUIButtonContent
-
-@synthesize title;
-@synthesize titleColor;
-@synthesize shadowColor;
-@synthesize image;
-@synthesize backgroundImage;
-
-
+@synthesize title = title;
+@synthesize titleColor = titleColor;
+@synthesize shadowColor = shadowColor;
+@synthesize image = image;
+@synthesize backgroundImage = backgroundImage;
@end
@@ -84,7 +71,7 @@ - (void)setTitleShadowColor:(TUIColor *)color forState:(TUIControlState)state
[self _stateDidChange];
}
-- (void)setImage:(TUIImage *)i forState:(TUIControlState)state
+- (void)setImage:(NSImage *)i forState:(TUIControlState)state
{
[self _stateWillChange];
[[self _contentForState:state] setImage:i];
@@ -92,7 +79,7 @@ - (void)setImage:(TUIImage *)i forState:(TUIControlState)state
[self _stateDidChange];
}
-- (void)setBackgroundImage:(TUIImage *)i forState:(TUIControlState)state
+- (void)setBackgroundImage:(NSImage *)i forState:(TUIControlState)state
{
[self _stateWillChange];
[[self _contentForState:state] setBackgroundImage:i];
@@ -115,12 +102,12 @@ - (TUIColor *)titleShadowColorForState:(TUIControlState)state
return [[self _contentForState:state] shadowColor];
}
-- (TUIImage *)imageForState:(TUIControlState)state
+- (NSImage *)imageForState:(TUIControlState)state
{
return [[self _contentForState:state] image];
}
-- (TUIImage *)backgroundImageForState:(TUIControlState)state
+- (NSImage *)backgroundImageForState:(TUIControlState)state
{
return [[self _contentForState:state] backgroundImage];
}
@@ -155,9 +142,9 @@ - (TUIColor *)currentTitleShadowColor
return color;
}
-- (TUIImage *)currentImage
+- (NSImage *)currentImage
{
- TUIImage *image = [self imageForState:self.state];
+ NSImage *image = [self imageForState:self.state];
if(image == nil) {
image = [self imageForState:TUIControlStateNormal];
}
@@ -165,9 +152,9 @@ - (TUIImage *)currentImage
return image;
}
-- (TUIImage *)currentBackgroundImage
+- (NSImage *)currentBackgroundImage
{
- TUIImage *image = [self backgroundImageForState:self.state];
+ NSImage *image = [self backgroundImageForState:self.state];
if(image == nil) {
image = [self backgroundImageForState:TUIControlStateNormal];
}
22 lib/UIKit/TUIButton.h
View
@@ -22,7 +22,6 @@
#import "TUIControl.h"
#import "TUIGeometry.h"
-@class TUIImage;
@class TUILabel;
@class TUIImageView;
@@ -77,19 +76,18 @@ typedef enum {
- (void)setTitle:(NSString *)title forState:(TUIControlState)state;
- (void)setTitleColor:(TUIColor *)color forState:(TUIControlState)state;
- (void)setTitleShadowColor:(TUIColor *)color forState:(TUIControlState)state;
-- (void)setImage:(TUIImage *)image forState:(TUIControlState)state;
-- (void)setBackgroundImage:(TUIImage *)image 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;
-- (TUIImage *)imageForState:(TUIControlState)state;
-- (TUIImage *)backgroundImageForState:(TUIControlState)state;
-
-@property(nonatomic,readonly,retain) NSString *currentTitle;
-@property(nonatomic,readonly,retain) TUIColor *currentTitleColor;
-@property(nonatomic,readonly,retain) TUIColor *currentTitleShadowColor;
-@property(nonatomic,readonly,retain) TUIImage *currentImage;
-@property(nonatomic,readonly,retain) TUIImage *currentBackgroundImage;
-
+- (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) NSImage *currentImage;
+@property(nonatomic, readonly, strong) NSImage *currentBackgroundImage;
@end
13 lib/UIKit/TUIButton.m
View
@@ -14,7 +14,6 @@
limitations under the License.
*/
-#import "TUIImage.h"
#import "TUIButton.h"
#import "TUICGAdditions.h"
#import "TUIColor.h"
@@ -22,6 +21,7 @@
#import "TUIImageView.h"
#import "TUILabel.h"
#import "TUINSView.h"
+#import "TUIStretchableImage.h"
#import "TUITextRenderer.h"
@interface TUIButton ()
@@ -185,14 +185,14 @@ - (void)drawRect:(CGRect)r
CGContextFillRect(TUIGraphicsGetCurrentContext(), self.bounds);
}
- TUIImage *backgroundImage = self.currentBackgroundImage;
- TUIImage *image = self.currentImage;
+ NSImage *backgroundImage = self.currentBackgroundImage;
+ NSImage *image = self.currentImage;
- [backgroundImage drawInRect:[self backgroundRectForBounds:bounds] blendMode:kCGBlendModeNormal alpha:1.0];
+ [backgroundImage drawInRect:[self backgroundRectForBounds:bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
if(image) {
CGRect imageRect;
- if(image.leftCapWidth || image.topCapHeight) {
+ if([image isKindOfClass:[TUIStretchableImage class]]) {
// stretchable
imageRect = self.bounds;
} else {
@@ -206,7 +206,8 @@ - (void)drawRect:(CGRect)r
b.size.height -= _imageEdgeInsets.bottom + _imageEdgeInsets.top;
imageRect = ButtonRectRoundOrigin(ButtonRectCenteredInRect(imageRect, b));
}
- [image drawInRect:imageRect blendMode:kCGBlendModeNormal alpha:alpha];
+
+ [image drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:alpha];
}
NSString *title = self.currentTitle;
Please sign in to comment.
Something went wrong with that request. Please try again.