vlc | branch: master | Marvin Scholz <epira...@gmail.com> | Sun Jun  5 11:28:31 
2016 +0200| [6ff805ad7f06c44da560501af5287eca05632410] | committer: Felix Paul 
Kühne

macosx: Improve VLCHUDButtonCell drawing

Signed-off-by: Felix Paul Kühne <fkue...@videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6ff805ad7f06c44da560501af5287eca05632410
---

 modules/gui/macosx/VLCHUDButtonCell.h |    4 ++++
 modules/gui/macosx/VLCHUDButtonCell.m |   31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/modules/gui/macosx/VLCHUDButtonCell.h 
b/modules/gui/macosx/VLCHUDButtonCell.h
index cceded2..fd808f0 100644
--- a/modules/gui/macosx/VLCHUDButtonCell.h
+++ b/modules/gui/macosx/VLCHUDButtonCell.h
@@ -31,7 +31,11 @@
 @interface VLCHUDButtonCell : NSButtonCell
 
 @property NSGradient *normalGradient;
+@property NSGradient *disabledGradient;
 @property NSGradient *highlightGradient;
 @property NSGradient *pushedGradient;
 
+@property NSColor *enabledTextColor;
+@property NSColor *disabledTextColor;
+
 @end
diff --git a/modules/gui/macosx/VLCHUDButtonCell.m 
b/modules/gui/macosx/VLCHUDButtonCell.m
index bf9670d..f042510 100644
--- a/modules/gui/macosx/VLCHUDButtonCell.m
+++ b/modules/gui/macosx/VLCHUDButtonCell.m
@@ -29,21 +29,25 @@
 {
     self = [super initWithCoder:coder];
     if (self) {
-        _normalGradient    = [[NSGradient alloc] 
initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f 
blue:0.255f alpha:1.0f]
+        _disabledGradient  = [[NSGradient alloc] 
initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f 
blue:0.255f alpha:1.0f]
                                                            
endingColor:[NSColor colorWithDeviceRed:0.118f green:0.118f blue:0.118f 
alpha:1.0f]];
+        _normalGradient    = [[NSGradient alloc] 
initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f 
blue:0.255f alpha:0.7f]
+                                                           
endingColor:[NSColor colorWithDeviceRed:0.118f green:0.118f blue:0.118f 
alpha:0.7f]];
         _highlightGradient = [[NSGradient alloc] 
initWithStartingColor:[NSColor colorWithDeviceRed:0.451f green:0.451f 
blue:0.455f alpha:1.0f]
                                                            
endingColor:[NSColor colorWithDeviceRed:0.318f green:0.318f blue:0.318f 
alpha:1.0f]];
         _pushedGradient    = [[NSGradient alloc] 
initWithStartingColor:[NSColor colorWithDeviceRed:0.451f green:0.451f 
blue:0.455f alpha:1.0f]
                                                            
endingColor:[NSColor colorWithDeviceRed:0.318f green:0.318f blue:0.318f 
alpha:1.0f]];
+        _enabledTextColor  = [NSColor whiteColor];
+        _disabledTextColor = [NSColor grayColor];
     }
     return self;
 }
 
 - (void) drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView
 {
-    NSLog(@"Bezel style: %lu", self.bezelStyle);
     // Set frame to the correct size
     frame.size.height = self.cellSize.height;
+
     // Inset rect to have enough room for the stroke
     frame = NSInsetRect(frame, 1, 1);
     if (self.bezelStyle == NSRoundRectBezelStyle) {
@@ -53,13 +57,32 @@
     }
 }
 
+- (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame 
inView:(NSView *)controlView
+{
+    NSMutableAttributedString *coloredTitle = [[NSMutableAttributedString 
alloc]
+                                               initWithAttributedString:title];
+    if (self.isEnabled) {
+        [coloredTitle addAttribute:NSForegroundColorAttributeName
+                             value:_enabledTextColor
+                             range:NSMakeRange(0, coloredTitle.length)];
+    } else {
+        [coloredTitle addAttribute:NSForegroundColorAttributeName
+                             value:_disabledTextColor
+                             range:NSMakeRange(0, coloredTitle.length)];
+    }
+
+    return [super drawTitle:coloredTitle withFrame:frame inView:controlView];
+}
+
 - (void) drawRoundRectButtonBezelInRect:(NSRect)rect
 {
     NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect 
xRadius:8.0 yRadius:8.0];
     if (self.highlighted) {
-        [_normalGradient drawInBezierPath:path angle:90.0f];
-    } else {
         [_pushedGradient drawInBezierPath:path angle:90.0f];
+    } else if (!self.enabled) {
+        [_disabledGradient drawInBezierPath:path angle:90.0f];
+    } else {
+        [_normalGradient drawInBezierPath:path angle:90.0f];
     }
     [[NSColor colorWithCalibratedWhite:1.0 alpha:1.0] setStroke];
     [path setLineWidth:0.5];

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to