Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating the button background image sizing logic

  • Loading branch information...
commit 1202e71d75ce3698ad7a197911128f51c1a0b1b4 1 parent 4ed0acb
@kgn authored
Showing with 7 additions and 7 deletions.
  1. +7 −7 NSButton+BBlock.m
View
14 NSButton+BBlock.m
@@ -15,30 +15,30 @@ - (NSImage *)imageForSize:(NSSize)size withBackgroundImage:(NSImage *)background
@implementation NSButton(BBlock)
-- (NSImage *)imageForSize:(NSSize)size withBackgroundImage:(NSImage *)background andIcon:(NSImage *)icon{
- return [NSImage imageForSize:size withDrawingBlock:^{
+- (NSImage *)imageWithBackgroundImage:(NSImage *)background andIcon:(NSImage *)icon{
+ return [NSImage imageForSize:background.size withDrawingBlock:^{
NSRect bounds = NSZeroRect;
- bounds.size = size;
+ bounds.size = background.size;
+
NSRect iconRect = NSZeroRect;
iconRect.size = icon.size;
iconRect.origin.x = round(background.size.width*0.5f-iconRect.size.width*0.5f);
iconRect.origin.y = round(background.size.height*0.5f-iconRect.size.height*0.5f);
+
[background drawInRect:bounds fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
[icon drawInRect:iconRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
}];
}
- (void)setBackgroundImage:(NSImage *)backgroundImage{
- [self setImage:[self imageForSize:self.bounds.size
- withBackgroundImage:backgroundImage
+ [self setImage:[self imageWithBackgroundImage:backgroundImage
andIcon:self.image]];
[self setButtonType:NSMomentaryChangeButton];
[self setBordered:NO];
}
- (void)setAlternateBackgroundImage:(NSImage *)alternateBackgroundImage{
- [self setAlternateImage:[self imageForSize:self.bounds.size
- withBackgroundImage:alternateBackgroundImage
+ [self setAlternateImage:[self imageWithBackgroundImage:alternateBackgroundImage
andIcon:self.alternateImage ?: self.image]];
[self setButtonType:NSMomentaryChangeButton];
[self setBordered:NO];
Please sign in to comment.
Something went wrong with that request. Please try again.