[vlc-devel] [PATCH 6/9] macosx: Better drawing for VLCHUDCheckboxCell
Marvin Scholz
epirat07 at gmail.com
Sun Jun 5 11:28:28 CEST 2016
---
modules/gui/macosx/VLCHUDCheckboxCell.h | 1 +
modules/gui/macosx/VLCHUDCheckboxCell.m | 71 +++++++++++++++++++++------------
2 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/modules/gui/macosx/VLCHUDCheckboxCell.h b/modules/gui/macosx/VLCHUDCheckboxCell.h
index 59c0e62..8bca650 100644
--- a/modules/gui/macosx/VLCHUDCheckboxCell.h
+++ b/modules/gui/macosx/VLCHUDCheckboxCell.h
@@ -33,5 +33,6 @@
@property NSGradient *normalGradient;
@property NSGradient *highlightGradient;
@property NSGradient *pushedGradient;
+ at property NSColor *disabledStrokeColor;
@end
diff --git a/modules/gui/macosx/VLCHUDCheckboxCell.m b/modules/gui/macosx/VLCHUDCheckboxCell.m
index af1056a..63c6c5f 100644
--- a/modules/gui/macosx/VLCHUDCheckboxCell.m
+++ b/modules/gui/macosx/VLCHUDCheckboxCell.m
@@ -35,6 +35,7 @@ - (instancetype) initWithCoder:(NSCoder *)coder
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]];
+ _disabledStrokeColor = [NSColor colorWithCalibratedRed:0.749 green:0.761 blue:0.788 alpha:0.2];
}
return self;
}
@@ -63,41 +64,61 @@ - (void) drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)con
yRadius:2];
// Draw border and background
- [NSColor.whiteColor setStroke];
- [backgroundPath setLineWidth:1];
+ if (self.isEnabled) {
+ [NSColor.whiteColor setStroke];
+ } else {
+ [_disabledStrokeColor setStroke];
+ }
+ [backgroundPath setLineWidth:1.5f];
[backgroundPath stroke];
if([self isEnabled]) {
- [_normalGradient drawInBezierPath:backgroundPath angle:90.0];
+ if (self.isHighlighted) {
+ [_highlightGradient drawInBezierPath:backgroundPath angle:90.0];
+ } else {
+ [_normalGradient drawInBezierPath:backgroundPath angle:90.0];
+ }
} else {
- [[NSColor lightGrayColor] setFill];
- NSRectFill(backgroundFrame);
+ [_disabledStrokeColor setFill];
+ [backgroundPath fill];
+ [[NSColor grayColor] setStroke];
}
- // Drawing inner contents
- //NSRect fillFrame = NSInsetRect(frame, 4, 4);
- if([self isHighlighted]) {
+ // Draw tickmark if necessary
+ if (self.intValue) {
+ NSBezierPath* bezierPath = [NSBezierPath bezierPath];
- //[[NSColor colorWithCalibratedWhite:0.9f alpha:1.0f] setFill];
- } else {
- //[[NSColor colorWithCalibratedWhite:0.8f alpha:1.0f] setFill];
+ // Get min/mid/width for tickmark calculation
+ CGFloat minX = NSMinX(frame);
+ CGFloat minY = NSMinY(frame);
+ CGFloat midX = NSMidX(frame);
+ CGFloat midY = NSMidY(frame);
+ CGFloat width = NSWidth(frame);
+
+ // Draw tickmark
+ [bezierPath moveToPoint:NSMakePoint(minX + 3.0, midY - 2.0)];
+ [bezierPath lineToPoint:NSMakePoint(midX, midY + 2.0)];
+ [bezierPath lineToPoint:NSMakePoint(minX + width - 1, minY - 2.0)];
+ [bezierPath setLineWidth:1.5];
+ [bezierPath stroke];
}
- //NSRectFill(fillFrame);
+}
- // Now drawing tick
- if ([self intValue]) {
- if([self isEnabled]) {
- NSBezierPath* bezierPath = [NSBezierPath bezierPath];
- [bezierPath moveToPoint: NSMakePoint(NSMinX(frame) + 3.0, NSMidY(frame) - 2.0)];
- [bezierPath lineToPoint: NSMakePoint(NSMidX(frame), NSMidY(frame) + 2.0)];
- [bezierPath lineToPoint: NSMakePoint((NSMinX(frame) + NSWidth(frame) - 1), NSMinY(frame) - 2.0)];
- [bezierPath setLineWidth: 1.5];
- [bezierPath stroke];
- } else {
- //[[NSColor blackColor] setFill];
- }
- //NSRectFill(NSInsetRect(frame, 6, 6));
+- (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView
+{
+ NSMutableAttributedString *coloredTitle = [[NSMutableAttributedString alloc]
+ initWithAttributedString:title];
+ if (self.isEnabled) {
+ [coloredTitle addAttribute:NSForegroundColorAttributeName
+ value:[NSColor whiteColor]
+ range:NSMakeRange(0, coloredTitle.length)];
+ } else {
+ [coloredTitle addAttribute:NSForegroundColorAttributeName
+ value:[NSColor darkGrayColor]
+ range:NSMakeRange(0, coloredTitle.length)];
}
+
+ return [super drawTitle:coloredTitle withFrame:frame inView:controlView];
}
@end
--
2.7.4 (Apple Git-66)
More information about the vlc-devel
mailing list