diff options
author | Damiano Galassi <[email protected]> | 2019-02-13 17:56:02 +0100 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2019-02-13 17:56:02 +0100 |
commit | 3f9a7051407be2562721471e2829bb2e73d391ed (patch) | |
tree | 59f51c88a97b41ee9d416495ae3a62005370332e /macosx/HBDockTextField.m | |
parent | d0e37ca0d75fbcef5bdf47aafe8543e262314ec5 (diff) |
MacGui: remove two old unused classes, remove some old compatibility hacks, and fix warnings.
Diffstat (limited to 'macosx/HBDockTextField.m')
-rw-r--r-- | macosx/HBDockTextField.m | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/macosx/HBDockTextField.m b/macosx/HBDockTextField.m new file mode 100644 index 000000000..25d22b5b3 --- /dev/null +++ b/macosx/HBDockTextField.m @@ -0,0 +1,86 @@ +/* HBDockTextField.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 "HBDockTextField.h" + +#define DOCK_TEXTFIELD_ALPHA 0.8 +#define DOCK_TEXTFIELD_FONTSIZE 28.0 + +@interface HBDockTextField () + +@property (nonatomic, readonly) NSDictionary *textAttributes; +@property (nonatomic, readonly) NSDictionary *smallTextAttributes; + +@property (nonatomic, readwrite) NSGradient *gradient; + +@end + +@implementation HBDockTextField + +- (instancetype)initWithFrame:(NSRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + [[self cell] setBezelStyle:NSBezelStyleRounded]; + _textToDisplay = @""; + _textAttributes = [self textAttributesWithFontSize:DOCK_TEXTFIELD_FONTSIZE]; + _smallTextAttributes = [self textAttributesWithFontSize:DOCK_TEXTFIELD_FONTSIZE - 2]; + [self changeGradientColors:[NSColor grayColor] endColor:[NSColor blackColor]]; + } + + return self; +} + +- (NSDictionary *)textAttributesWithFontSize:(CGFloat)fontSize +{ + NSShadow *shadow = [[NSShadow alloc] init]; + shadow.shadowColor = [NSColor blackColor]; + shadow.shadowOffset = NSMakeSize(2, -2); + shadow.shadowBlurRadius = 6; + + NSFont *font = [NSFont monospacedDigitSystemFontOfSize:fontSize weight:NSFontWeightBold]; + + return @{ NSForegroundColorAttributeName: [NSColor whiteColor], + NSFontAttributeName: font, + NSShadowAttributeName: shadow}; +} + +- (void)changeGradientColors:(NSColor *)startColor endColor:(NSColor *)endColor +{ + self.startColor = [startColor colorWithAlphaComponent:DOCK_TEXTFIELD_ALPHA]; + self.endColor = [endColor colorWithAlphaComponent:DOCK_TEXTFIELD_ALPHA]; + self.gradient = [[NSGradient alloc] initWithStartingColor:self.startColor endingColor:self.endColor]; +} + +- (void)drawRect:(NSRect)dirtyRect +{ + if (self.isHidden) + return; + + NSSize size = self.bounds.size; + NSRect blackOutlineFrame = NSMakeRect(0.0, 0.0, size.width, size.height - 1.0); + double radius = self.bounds.size.height / 2; + + [self.gradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:blackOutlineFrame xRadius:radius yRadius:radius] angle:90]; + + NSDictionary *attributes = self.textAttributes; + NSString *budgetString = _textToDisplay; + NSSize stringSize = [budgetString sizeWithAttributes:attributes]; + + if (size.width - 4 < stringSize.width) + { + attributes = self.smallTextAttributes; + stringSize = [budgetString sizeWithAttributes:attributes]; + } + + 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:attributes]; +} + +@end |