patch from nickshanks to improve filter button code
This commit is contained in:
parent
95345006a0
commit
51ba44470f
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
@class CTGradient;
|
||||||
@interface FilterBarButton : NSButton
|
@interface FilterBarButton : NSButton
|
||||||
{
|
{
|
||||||
int fCount;
|
int fCount;
|
||||||
|
@ -33,6 +34,10 @@
|
||||||
NSBezierPath * fPath, * fEdgePath, * fStepPath;
|
NSBezierPath * fPath, * fEdgePath, * fStepPath;
|
||||||
NSDictionary * fNormalAttributes, * fNormalDimAttributes,
|
NSDictionary * fNormalAttributes, * fNormalDimAttributes,
|
||||||
* fHighlightedAttributes, * fHighlightedDimAttributes;
|
* fHighlightedAttributes, * fHighlightedDimAttributes;
|
||||||
|
CTGradient * fHighlightedBackground, * fHighlightedOutline,
|
||||||
|
* fActiveBackground, * fActiveOutline,
|
||||||
|
* fHoveringBackground;
|
||||||
|
NSColor * fHoveringOutline;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setCount: (int) count;
|
- (void) setCount: (int) count;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
@interface FilterBarButton (Private)
|
@interface FilterBarButton (Private)
|
||||||
|
|
||||||
- (void) createPaths;
|
- (void) createPaths;
|
||||||
|
- (void) createGradients;
|
||||||
- (void) createFontAttributes;
|
- (void) createFontAttributes;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
fCount = -1;
|
fCount = -1;
|
||||||
[self setCount: 0];
|
[self setCount: 0];
|
||||||
[self createPaths];
|
[self createPaths];
|
||||||
|
[self createGradients];
|
||||||
[self createFontAttributes];
|
[self createFontAttributes];
|
||||||
|
|
||||||
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
||||||
|
@ -62,10 +64,18 @@
|
||||||
[fPath release];
|
[fPath release];
|
||||||
[fEdgePath release];
|
[fEdgePath release];
|
||||||
[fStepPath release];
|
[fStepPath release];
|
||||||
|
|
||||||
[fNormalAttributes release];
|
[fNormalAttributes release];
|
||||||
[fNormalDimAttributes release];
|
[fNormalDimAttributes release];
|
||||||
[fHighlightedAttributes release];
|
[fHighlightedAttributes release];
|
||||||
|
|
||||||
[fHighlightedDimAttributes release];
|
[fHighlightedDimAttributes release];
|
||||||
|
[fHighlightedBackground release];
|
||||||
|
[fHighlightedOutline release];
|
||||||
|
[fActiveBackground release];
|
||||||
|
[fActiveOutline release];
|
||||||
|
[fHoveringBackground release];
|
||||||
|
[fHoveringOutline release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -73,7 +83,7 @@
|
||||||
- (void) sizeToFit
|
- (void) sizeToFit
|
||||||
{
|
{
|
||||||
NSSize size = [[self title] sizeWithAttributes: fNormalAttributes];
|
NSSize size = [[self title] sizeWithAttributes: fNormalAttributes];
|
||||||
size.width = floorf(size.width + 18.5);
|
size.width = floorf(size.width + 14.5);
|
||||||
size.height += 1;
|
size.height += 1;
|
||||||
[self setFrameSize: size];
|
[self setFrameSize: size];
|
||||||
[self setBoundsSize: size];
|
[self setBoundsSize: size];
|
||||||
|
@ -90,64 +100,36 @@
|
||||||
// draw background
|
// draw background
|
||||||
if ([[self cell] isHighlighted])
|
if ([[self cell] isHighlighted])
|
||||||
{
|
{
|
||||||
[[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 134.0/255 green: 151.0/255
|
[fHighlightedBackground fillBezierPath: fPath angle: -90.0];
|
||||||
blue: 176.0/255 alpha: 1.0]
|
[fHighlightedOutline fillBezierPath: fStepPath angle: -90.0];
|
||||||
endingColor: [NSColor colorWithCalibratedRed: 104.0/255 green: 125.0/255
|
|
||||||
blue: 157.0/255 alpha: 1.0]]
|
|
||||||
fillBezierPath: fPath angle: -90.0];
|
|
||||||
[[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.25]
|
|
||||||
// middleColor: [NSColor colorWithCalibratedWhite: 0.5 alpha: 0.00]
|
|
||||||
middleColor1: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.25]
|
|
||||||
middleColor2: [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.50]
|
|
||||||
endingColor: [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.50]]
|
|
||||||
fillBezierPath: fStepPath angle: -90.0];
|
|
||||||
}
|
|
||||||
else switch (fState)
|
|
||||||
{
|
|
||||||
case 1: // active
|
|
||||||
[[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 151.0/255 green: 166.0/255
|
|
||||||
blue: 188.0/255 alpha: 1.0]
|
|
||||||
endingColor: [NSColor colorWithCalibratedRed: 126.0/255 green: 144.0/255
|
|
||||||
blue: 171.0/255 alpha: 1.0]]
|
|
||||||
fillBezierPath: fPath angle: -90.0];
|
|
||||||
[[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.25]
|
|
||||||
// middleColor: [NSColor colorWithCalibratedWhite: 0.5 alpha: 0.00]
|
|
||||||
middleColor1: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.25]
|
|
||||||
middleColor2: [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.50]
|
|
||||||
endingColor: [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.50]]
|
|
||||||
fillBezierPath: fStepPath angle: -90.0];
|
|
||||||
break;
|
|
||||||
case 2: // hovering
|
|
||||||
[[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 164.0/255 green: 177.0/255
|
|
||||||
blue: 196.0/255 alpha: 1.0]
|
|
||||||
endingColor: [NSColor colorWithCalibratedRed: 141.0/255 green: 158.0/255
|
|
||||||
blue: 182.0/255 alpha: 1.0]]
|
|
||||||
fillBezierPath: fPath angle: -90.0];
|
|
||||||
[[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.075] set];
|
|
||||||
[fEdgePath stroke];
|
|
||||||
break;
|
|
||||||
case 3: // clicked but cell is not highlighted
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
switch (fState)
|
||||||
|
{
|
||||||
|
case 1: // active
|
||||||
|
[fActiveBackground fillBezierPath: fPath angle: -90.0];
|
||||||
|
[fActiveOutline fillBezierPath: fStepPath angle: -90.0];
|
||||||
|
break;
|
||||||
|
case 2: // hovering
|
||||||
|
case 3: // clicked but cell is not highlighted
|
||||||
|
[fHoveringBackground fillBezierPath: fPath angle: -90.0];
|
||||||
|
[fHoveringOutline setStroke];
|
||||||
|
[fEdgePath stroke];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// draw title
|
// draw title
|
||||||
NSSize titleSize = [[self title] sizeWithAttributes: fNormalAttributes];
|
NSSize titleSize = [[self title] sizeWithAttributes: fNormalAttributes];
|
||||||
NSPoint titlePos = NSMakePoint(([self bounds].size.width - titleSize.width) * 0.5,
|
NSPoint titlePos = NSMakePoint(([self bounds].size.width - titleSize.width) * 0.5,
|
||||||
([self bounds].size.height - titleSize.height) * 0.5 + 1.5);
|
([self bounds].size.height - titleSize.height) * 0.5 + 1.5);
|
||||||
if (fEnabled)
|
|
||||||
{
|
NSDictionary * attributes;
|
||||||
if (fState && !(fState == 3 && ![[self cell] isHighlighted]))
|
if (fState)
|
||||||
[[self title] drawAtPoint: titlePos withAttributes: fHighlightedAttributes];
|
attributes = fEnabled ? fHighlightedAttributes : fHighlightedDimAttributes;
|
||||||
else
|
|
||||||
[[self title] drawAtPoint: titlePos withAttributes: fNormalAttributes];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
attributes = fEnabled ? fNormalAttributes : fNormalDimAttributes;
|
||||||
if (fState)
|
|
||||||
[[self title] drawAtPoint: titlePos withAttributes: fHighlightedDimAttributes];
|
[[self title] drawAtPoint: titlePos withAttributes: attributes];
|
||||||
else
|
|
||||||
[[self title] drawAtPoint: titlePos withAttributes: fNormalDimAttributes];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setCount: (int) count
|
- (void) setCount: (int) count
|
||||||
|
@ -256,6 +238,24 @@
|
||||||
[fStepPath setWindingRule: NSEvenOddWindingRule];
|
[fStepPath setWindingRule: NSEvenOddWindingRule];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) createGradients
|
||||||
|
{
|
||||||
|
NSColor *quarterAlphaBlack = [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.25];
|
||||||
|
NSColor *thirdAlphaWhite = [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.3333];
|
||||||
|
fHighlightedBackground = [[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 134.0/255 green: 151.0/255 blue: 176.0/255 alpha: 1.0]
|
||||||
|
endingColor: [NSColor colorWithCalibratedRed: 104.0/255 green: 125.0/255 blue: 157.0/255 alpha: 1.0]] retain];
|
||||||
|
fHighlightedOutline = [[CTGradient gradientWithBeginningColor: quarterAlphaBlack
|
||||||
|
middleColor1: quarterAlphaBlack
|
||||||
|
middleColor2: thirdAlphaWhite
|
||||||
|
endingColor: thirdAlphaWhite] retain];
|
||||||
|
fActiveBackground = [[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 151.0/255 green: 166.0/255 blue: 188.0/255 alpha: 1.0]
|
||||||
|
endingColor: [NSColor colorWithCalibratedRed: 126.0/255 green: 144.0/255 blue: 171.0/255 alpha: 1.0]] retain];
|
||||||
|
fActiveOutline = [fHighlightedOutline retain];
|
||||||
|
fHoveringBackground = [[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 164.0/255 green: 177.0/255 blue: 196.0/255 alpha: 1.0]
|
||||||
|
endingColor: [NSColor colorWithCalibratedRed: 141.0/255 green: 158.0/255 blue: 182.0/255 alpha: 1.0]] retain];
|
||||||
|
fHoveringOutline = [[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.075] retain];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) createFontAttributes
|
- (void) createFontAttributes
|
||||||
{
|
{
|
||||||
NSFont * boldSystemFont = [NSFont boldSystemFontOfSize: 12.0];
|
NSFont * boldSystemFont = [NSFont boldSystemFontOfSize: 12.0];
|
||||||
|
|
Loading…
Reference in New Issue