diff options
author | dynaflash <[email protected]> | 2012-09-15 17:08:16 +0000 |
---|---|---|
committer | dynaflash <[email protected]> | 2012-09-15 17:08:16 +0000 |
commit | 1faac76d071993d03fb93ad8e58b3ef41e9b4c2a (patch) | |
tree | 3ab4505ea6e1eb42c9650dad578b65cff0eac700 /macosx/DockTextField.m | |
parent | 8329bf01460521587889fd4133f76b32ccf13217 (diff) |
MacGui: New dock icon progess behavior with percent & ETA "badges".
- Patch by Jerome Lacube Thanks !!
- Details can be found here https://reviews.handbrake.fr/r/344/
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4964 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/DockTextField.m')
-rw-r--r-- | macosx/DockTextField.m | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/macosx/DockTextField.m b/macosx/DockTextField.m new file mode 100644 index 000000000..0b71d632f --- /dev/null +++ b/macosx/DockTextField.m @@ -0,0 +1,74 @@ +/* DockTextField.m $ + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ + +#import "DockTextField.h" + +#define DOCK_TEXTFIELD_ALPHA 0.8 +#define DOCK_TEXTFIELD_FONTSIZE 28.0 + +@implementation DockTextField + +@synthesize textToDisplay = _textToDisplay; +@synthesize startColor = _startColor; +@synthesize endColor = _endColor; + +- (id)initWithFrame:(NSRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + [[self cell] setBezelStyle: NSTextFieldRoundedBezel]; + _textToDisplay = @""; + + [self changeGradientColors:[NSColor grayColor] withEndColor:[NSColor blackColor]]; + } + + return self; +} + +- (void)changeGradientColors:(NSColor*)startColor withEndColor:(NSColor*)endColor +{ + NSColor *startRGBColor = [startColor colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]]; + NSColor *endRGBColor = [endColor colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]]; + + self.startColor = [NSColor colorWithSRGBRed:startRGBColor.redComponent green:startRGBColor.greenComponent blue:startRGBColor.blueComponent alpha:DOCK_TEXTFIELD_ALPHA]; + self.endColor = [NSColor colorWithSRGBRed:endRGBColor.redComponent green:endRGBColor.greenComponent blue:endRGBColor.blueComponent alpha:DOCK_TEXTFIELD_ALPHA]; +} + +- (void)drawRect:(NSRect)dirtyRect +{ + if (self.isHidden) + return; + + NSRect blackOutlineFrame = NSMakeRect(0.0, 0.0, [self bounds].size.width, [self bounds].size.height-1.0); + double radius = self.bounds.size.height / 2; + + NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:self.startColor endingColor:self.endColor]; + [gradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:blackOutlineFrame xRadius:radius yRadius:radius] angle:90]; + + NSMutableDictionary *drawStringAttributes = [[NSMutableDictionary alloc] init]; + [drawStringAttributes setValue:[NSColor whiteColor] forKey:NSForegroundColorAttributeName]; + [drawStringAttributes setValue:[NSFont boldSystemFontOfSize:DOCK_TEXTFIELD_FONTSIZE] forKey:NSFontAttributeName]; + NSShadow *stringShadow = [[NSShadow alloc] init]; + [stringShadow setShadowColor:[NSColor blackColor]]; + NSSize shadowSize; + shadowSize.width = 2; + shadowSize.height = -2; + [stringShadow setShadowOffset:shadowSize]; + [stringShadow setShadowBlurRadius:6]; + [drawStringAttributes setValue:stringShadow forKey:NSShadowAttributeName]; + [stringShadow release]; + + NSString *MRString = _textToDisplay; + NSString *budgetString = [NSString stringWithFormat:@"%@", MRString]; + NSSize stringSize = [budgetString sizeWithAttributes:drawStringAttributes]; + NSPoint centerPoint; + centerPoint.x = (dirtyRect.size.width / 2) - (stringSize.width / 2); + centerPoint.y = dirtyRect.size.height / 2 - (stringSize.height / 2) - 2; + [budgetString drawAtPoint:centerPoint withAttributes:drawStringAttributes]; + [drawStringAttributes release]; +} + +@end |