From db89f64730a220f5e1be5aac5d77cca53e10e8aa Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 29 May 2007 16:17:51 +0000 Subject: [PATCH] make the number in the filter button smaller --- macosx/Controller.m | 8 ++-- macosx/FilterBarButton.h | 2 +- macosx/FilterBarButton.m | 79 +++++++++++++++++++++++++++++++++++----- 3 files changed, 74 insertions(+), 15 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 6416d16b4..61af50fd3 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1676,10 +1676,10 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy [tempTorrents setArray: fTorrents]; //set buttons with counts - [fNoFilterButton createButtonsWithCount: [fTorrents count]]; - [fDownloadFilterButton createButtonsWithCount: downloading]; - [fSeedFilterButton createButtonsWithCount: seeding]; - [fPauseFilterButton createButtonsWithCount: paused]; + [fNoFilterButton setCount: [fTorrents count]]; + [fDownloadFilterButton setCount: downloading]; + [fSeedFilterButton setCount: seeding]; + [fPauseFilterButton setCount: paused]; [fFilterBar replaceButtons]; NSString * searchString = [fSearchFilterField stringValue]; diff --git a/macosx/FilterBarButton.h b/macosx/FilterBarButton.h index f141e09bc..b92049db0 100644 --- a/macosx/FilterBarButton.h +++ b/macosx/FilterBarButton.h @@ -34,7 +34,7 @@ NSTrackingRectTag fTrackingTag; } -- (void) createButtonsWithCount: (int) count; +- (void) setCount: (int) count; - (void) setEnabled: (BOOL) enable; - (void) resetBounds: (NSNotification *) notification; diff --git a/macosx/FilterBarButton.m b/macosx/FilterBarButton.m index 9a967b6bb..ffb3e4437 100644 --- a/macosx/FilterBarButton.m +++ b/macosx/FilterBarButton.m @@ -34,7 +34,7 @@ fTrackingTag = 0; fCount = -1; - [self createButtonsWithCount: 0]; + [self setCount: 0]; NSNotificationCenter * nc = [NSNotificationCenter defaultCenter]; @@ -63,8 +63,7 @@ [super dealloc]; } -#warning rename -- (void) createButtonsWithCount: (int) count +- (void) setCount: (int) count { if (fCount == count) return; @@ -100,20 +99,20 @@ [shadowHighlighted setShadowBlurRadius: 1.0]; [shadowHighlighted setShadowColor: [NSColor colorWithDeviceWhite: 0.0 alpha: 0.4]]; - NSDictionary * normalAttributes = [[NSDictionary alloc] initWithObjectsAndKeys: + NSMutableDictionary * normalAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSColor colorWithCalibratedRed: 0.259 green: 0.259 blue: 0.259 alpha: 1.0], NSForegroundColorAttributeName, boldFont, NSFontAttributeName, shadowNormal, NSShadowAttributeName, nil], - * normalDimAttributes = [[NSDictionary alloc] initWithObjectsAndKeys: + * normalDimAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSColor disabledControlTextColor], NSForegroundColorAttributeName, boldFont, NSFontAttributeName, shadowDim, NSShadowAttributeName, nil], - * highlightedAttributes = [[NSDictionary alloc] initWithObjectsAndKeys: + * highlightedAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSColor whiteColor], NSForegroundColorAttributeName, boldFont, NSFontAttributeName, shadowHighlighted, NSShadowAttributeName, nil], - * highlightedDimAttributes = [[NSDictionary alloc] initWithObjectsAndKeys: + * highlightedDimAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSColor colorWithCalibratedRed: 0.9 green: 0.9 blue: 0.9 alpha: 1.0], NSForegroundColorAttributeName, boldFont, NSFontAttributeName, shadowHighlighted, NSShadowAttributeName, nil]; @@ -123,9 +122,8 @@ [shadowHighlighted release]; //create button text - NSString * text = [self title]; - if (fCount > 0) - text = [text stringByAppendingString: [NSString stringWithFormat: @" (%d)", fCount]]; + NSString * text = [self title], + * number = fCount > 0 ? [NSString stringWithFormat: @" (%d)", fCount] : nil; //get images NSImage * leftOver = [NSImage imageNamed: @"FilterButtonOverLeft.png"], @@ -151,6 +149,24 @@ NSRect textRect = NSMakeRect(endSize.width - overlap, (buttonSize.height - textSize.height) * 0.5 + 1.5, textSize.width, textSize.height); + NSFont * smallFont; + NSSize countSize; + if (fCount > 0) + { + smallFont = [[NSFontManager sharedFontManager] convertFont: + [NSFont fontWithName: @"Lucida Grande" size: 10.0] toHaveTrait: NSBoldFontMask]; + + NSMutableDictionary * tempAttributes = [normalAttributes mutableCopy]; + [tempAttributes setObject: smallFont forKey: NSFontAttributeName]; + + countSize = [number sizeWithAttributes: tempAttributes]; + countSize.width = ceilf(countSize.width); + mainSize.width += countSize.width; + buttonSize.width += countSize.width; + + [tempAttributes release]; + } + NSPoint leftPoint = NSZeroPoint, mainPoint = NSMakePoint(endSize.width, 0), rightPoint = NSMakePoint(mainPoint.x + mainSize.width, 0); @@ -225,6 +241,49 @@ [text drawInRect: textRect withAttributes: highlightedDimAttributes]; [fButtonSelectedDim unlockFocus]; + //append count + if (fCount > 0) + { + //change attributes + [normalAttributes setObject: smallFont forKey: NSFontAttributeName]; + [normalDimAttributes setObject: smallFont forKey: NSFontAttributeName]; + [highlightedAttributes setObject: smallFont forKey: NSFontAttributeName]; + [highlightedDimAttributes setObject: smallFont forKey: NSFontAttributeName]; + + NSRect countRect = NSMakeRect(NSMaxX(textRect), (buttonSize.height - textSize.height) * 0.5 + 1.5, + countSize.width, countSize.height); + + //normal button + [fButtonNormal lockFocus]; + [number drawInRect: countRect withAttributes: normalAttributes]; + [fButtonNormal unlockFocus]; + + //normal and dim button + [fButtonNormalDim lockFocus]; + [number drawInRect: countRect withAttributes: normalDimAttributes]; + [fButtonNormalDim unlockFocus]; + + //rolled over button + [fButtonOver lockFocus]; + [number drawInRect: countRect withAttributes: highlightedAttributes]; + [fButtonOver unlockFocus]; + + //pressed button + [fButtonPressed lockFocus]; + [number drawInRect: countRect withAttributes: highlightedAttributes]; + [fButtonPressed unlockFocus]; + + //selected button + [fButtonSelected lockFocus]; + [number drawInRect: countRect withAttributes: highlightedAttributes]; + [fButtonSelected unlockFocus]; + + //selected and dim button + [fButtonSelectedDim lockFocus]; + [number drawInRect: countRect withAttributes: highlightedDimAttributes]; + [fButtonSelectedDim unlockFocus]; + } + [normalAttributes release]; [normalDimAttributes release]; [highlightedAttributes release];