Reordered code a little.

This commit is contained in:
Mitchell Livingston 2006-07-23 22:58:04 +00:00
parent b8cf664d01
commit 028a5d5daa
1 changed files with 65 additions and 65 deletions

View File

@ -26,7 +26,7 @@
@interface BarButton (Private)
- (void) setText;
- (void) createButtons;
@end
@ -40,6 +40,20 @@
fEnabled = NO;
fTrackingTag = 0;
[self createButtons];
[self setImage: fButtonNormal];
[self setAlternateImage: fButtonPressed];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(resetBounds:)
name: NSViewBoundsDidChangeNotification object: nil];
}
return self;
}
//call only once
- (void) createButtons
{
NSSize buttonSize = [self frame].size;
fButtonNormal = [[NSImage alloc] initWithSize: buttonSize];
fButtonNormalDim = [[NSImage alloc] initWithSize: buttonSize];
@ -99,20 +113,7 @@
//selected and dimmed button
fButtonSelectedDim = [fButtonSelected copy];
[self setText];
[self setImage: fButtonNormal];
[self setAlternateImage: fButtonPressed];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(resetBounds:)
name: NSViewBoundsDidChangeNotification object: nil];
}
return self;
}
//call only once to avoid overlapping text
- (void) setText
{
//create button text
NSString * text = [self title];
NSFont * boldFont = [[NSFontManager sharedFontManager] convertFont:
@ -154,8 +155,7 @@
shadowHighlighted, NSShadowAttributeName, nil];
NSSize textSizeNormal = [text sizeWithAttributes: normalAttributes],
textSizeBold = [text sizeWithAttributes: highlightedAttributes],
buttonSize = [self frame].size;
textSizeBold = [text sizeWithAttributes: highlightedAttributes];
NSRect textRect = NSMakeRect((buttonSize.width - textSizeNormal.width) * 0.5,
(buttonSize.height - textSizeNormal.height) * 0.5 + 1.5, textSizeNormal.width, textSizeNormal.height);