Revision: 24166
          http://sourceforge.net/p/bibdesk/svn/24166
Author:   hofman
Date:     2019-08-28 09:34:22 +0000 (Wed, 28 Aug 2019)
Log Message:
-----------
draw circles with system colors for finder labels on 10.10+

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m 2019-08-28 
06:30:41 UTC (rev 24165)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m 2019-08-28 
09:34:22 UTC (rev 24166)
@@ -269,9 +269,10 @@
 - (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView
 {
     frame = __FVSquareRectCenteredInRect(frame);
-    CGFloat inset = NSWidth(frame) / 5;
+    CGFloat inset = floor(NSWidth(frame) / 5);
     NSRect interiorFrame = NSInsetRect(frame, inset, inset);
     NSInteger tag = [self tag];
+    BOOL isLegacy = floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_10;
     
     [NSGraphicsContext saveGraphicsState];
 
@@ -281,19 +282,29 @@
     if ([self state] == NSOnState && 0 != tag) {
         [[NSColor lightGrayColor] setStroke];
         NSRect boxRect = [controlView centerScanRect:NSInsetRect(frame, 1.0, 
1.0)];
-        NSBezierPath *boxPath = [NSBezierPath 
fv_bezierPathWithRoundRect:boxRect xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
+        NSBezierPath *boxPath = nil;
+        if (isLegacy)
+            boxPath = [NSBezierPath fv_bezierPathWithRoundRect:boxRect 
xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
+        else
+            boxPath = [NSBezierPath bezierPathWithOvalInRect:boxRect];
         [boxPath setLineWidth:BOX_WIDTH];
         [boxPath stroke];
     }
     // draw a box around the moused-over cell (unless it's selected); the X 
cell always gets highlighted, since it's never drawn as selected
     else if ([self isHovered]) {
-        [[NSColor lightGrayColor] setStroke];
-        NSRect boxRect = [controlView centerScanRect:NSInsetRect(frame, 1.0, 
1.0)];
-        NSBezierPath *boxPath = [NSBezierPath 
fv_bezierPathWithRoundRect:boxRect xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
-        [[NSColor colorWithCalibratedWhite:0.5 alpha:0.3] setFill];
-        [boxPath fill];
-        [boxPath setLineWidth:BOX_WIDTH];
-        [boxPath stroke];
+        if (isLegacy)
+        {
+            [[NSColor lightGrayColor] setStroke];
+            NSRect boxRect = [controlView centerScanRect:NSInsetRect(frame, 
1.0, 1.0)];
+            NSBezierPath *boxPath = [NSBezierPath 
fv_bezierPathWithRoundRect:boxRect xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
+            [[NSColor colorWithCalibratedWhite:0.5 alpha:0.3] setFill];
+            [boxPath fill];
+            [boxPath setLineWidth:BOX_WIDTH];
+            [boxPath stroke];
+        }
+        else {
+            interiorFrame = [controlView centerScanRect:NSInsetRect(frame, 
1.0, 1.0)];
+        }
     }
 
     if (0 == tag) {
@@ -309,13 +320,19 @@
         [p stroke];
     }
     else {
-        NSShadow *labelShadow = [NSShadow new];
-        [labelShadow setShadowOffset:NSMakeSize(0.0, -1.0)];
-        [labelShadow setShadowBlurRadius:2.0];
-        [labelShadow setShadowColor:[[NSColor controlTextColor] 
colorWithAlphaComponent:0.33333]];
-        [labelShadow set];
-        [FVFinderLabel drawFinderLabel:tag inRect:interiorFrame roundEnds:NO];
-        [labelShadow release];
+        if (isLegacy)
+        {
+            NSShadow *labelShadow = [NSShadow new];
+            [labelShadow setShadowOffset:NSMakeSize(0.0, -1.0)];
+            [labelShadow setShadowBlurRadius:2.0];
+            [labelShadow setShadowColor:[[NSColor controlTextColor] 
colorWithAlphaComponent:0.33333]];
+            [labelShadow set];
+            [FVFinderLabel drawFinderLabel:tag inRect:interiorFrame];
+            [labelShadow release];
+        }
+        else {
+            [FVFinderLabel drawFinderLabel:tag inRect:interiorFrame];
+        }
     }
     
     [NSGraphicsContext restoreGraphicsState];

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2019-08-28 
06:30:41 UTC (rev 24165)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2019-08-28 
09:34:22 UTC (rev 24166)
@@ -2425,10 +2425,10 @@
                     
                     [_titleCell setStringValue:name ?: @""];
                     if (label > 0) {
-                        CGRect labelRect = NSRectToCGRect([self 
centerScanRect:NSInsetRect(textRect, 4.0, 0.0)]);
+                        NSRect labelRect = [self 
centerScanRect:NSInsetRect(textRect, 4.0, 0.0)];
                         
                         labelRect.size.height = titleHeight;                   
     
-                        [FVFinderLabel drawFinderLabel:label inRect:labelRect 
ofContext:cgContext flipped:NO roundEnds:YES];
+                        [FVFinderLabel drawFinderLabelHighlight:label 
inRect:labelRect];
                         
                         // labeled title uses black text for greater contrast; 
inset horizontally because of the rounded end caps
                         // @@ Dark mode
@@ -3960,7 +3960,7 @@
         
         // round off the corners of the swatches, but don't draw the full 
rounded ends
         [clipPath addClip];
-        [FVFinderLabel drawFinderLabel:i inRect:iconRect roundEnds:NO];
+        [FVFinderLabel drawFinderLabel:i inRect:iconRect];
         
         // Finder displays an unbordered cross for clearing the label, so 
we'll do something similar
         // @@ Dark mode

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h   2019-08-28 
06:30:41 UTC (rev 24165)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h   2019-08-28 
09:34:22 UTC (rev 24166)
@@ -47,11 +47,11 @@
  @warning Drawing methods are private to the framework.  Methods for getting 
and setting name and label may be useful to clients, and should be relatively 
stable. */
 @interface FVFinderLabel : NSObject
 
-/** @internal Draws a Finder label gradient in the specified context. */
-+ (void)drawFinderLabel:(NSUInteger)label inRect:(CGRect)rect 
ofContext:(CGContextRef)context flipped:(BOOL)isFlipped roundEnds:(BOOL)flag;
+/** @internal Draws a Finder label in the currently focused graphics context. 
*/
++ (void)drawFinderLabel:(NSUInteger)label inRect:(NSRect)rect;
 
-/** @internal Draws a Finder label gradient in the currently focused graphics 
context. */
-+ (void)drawFinderLabel:(NSUInteger)label inRect:(NSRect)rect 
roundEnds:(BOOL)flag;
+/** @internal Draws a Finder label title background in the currently focused 
graphics context. */
++ (void)drawFinderLabelHighlight:(NSUInteger)label inRect:(NSRect)rect;
 
 /** Localized Finder label name.
  

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m   2019-08-28 
06:30:41 UTC (rev 24165)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m   2019-08-28 
09:34:22 UTC (rev 24166)
@@ -42,6 +42,16 @@
 
 NSString *FVFinderLabelDidChangeNotification = 
@"FVFinderLabelDidChangeNotification";
 
+@interface NSColor (FVYosemiteDeclarations3)
+- (NSColor *)systemGrayColor;
+- (NSColor *)systemPurlpeColor;
+- (NSColor *)systemBlueColor;
+- (NSColor *)systemGreenColor;
+- (NSColor *)systemYellowColor;
+- (NSColor *)systemOrangeColor;
+- (NSColor *)systemRedColor;
+@end
+
 @implementation FVFinderLabel
 
 static CFMutableDictionaryRef _layers = NULL;
@@ -210,6 +220,40 @@
     return color;
 }
 
++ (NSColor *)_colorForLabel:(NSInteger)label
+{
+    FVAPIAssert1(label <= 7, @"Invalid Finder label %ld (must be in the range 
0--7)", (long)label);
+    FVAPIAssert([NSColor respondsToSelector:@selector(systemGrayColor)], 
@"System colors not defined");
+    NSColor *color = nil;
+    switch (label) {
+        case 1:
+            color = [NSColor systemGrayColor];
+            break;
+        case 2:
+            color = [NSColor systemGreenColor];
+            break;
+        case 3:
+            color = [NSColor systemPurpleColor];
+            break;
+        case 4:
+            color = [NSColor systemBlueColor];
+            break;
+        case 5:
+            color = [NSColor systemYellowColor];
+            break;
+        case 6:
+            color = [NSColor systemRedColor];
+            break;
+        case 7:
+            color = [NSColor systemOrangeColor];
+            break;
+        default:
+            color = nil; /* unreached */
+            break;
+    }
+    return color;
+}
+
 + (NSString *)_preferenceNameForLabel:(NSInteger)label
 {
     // Apple preference for Finder label names
@@ -362,7 +406,7 @@
     CGPathRelease(path);
 }
 
-+ (void)drawFinderLabel:(NSUInteger)label inRect:(CGRect)rect 
ofContext:(CGContextRef)context flipped:(BOOL)isFlipped roundEnds:(BOOL)flag;
++ (void)_drawFinderLabel:(NSUInteger)label inRect:(CGRect)rect 
ofContext:(CGContextRef)context flipped:(BOOL)isFlipped roundEnds:(BOOL)flag;
 {
     FVAPIAssert1(label <= 7, @"Invalid Finder label %ld (must be in the range 
0--7)", (long)label);
     
@@ -397,12 +441,58 @@
     CGContextRestoreGState(context);
 }
 
-+ (void)drawFinderLabel:(NSUInteger)label inRect:(NSRect)rect 
roundEnds:(BOOL)flag;
++ (void)_drawFinderLabel:(NSUInteger)label inRect:(NSRect)rect;
 {
-    NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
-    [self drawFinderLabel:label inRect:NSRectToCGRect(rect) 
ofContext:[nsContext graphicsPort] flipped:[nsContext isFlipped] 
roundEnds:flag];
+    FVAPIAssert1(label <= 7, @"Invalid Finder label %ld (must be in the range 
0--7)", (long)label);
+    
+    [NSGraphicsContext saveGraphicsState];
+    
+    [[self _colorForLabel:label] setFill];
+    [[NSBezierPath bezierPathWithOvalInRect:rect] fill];
+    
+    [[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setFill];
+    [[NSBezierPath bezierPathWithOvalInRect:NSInsetRect(rect, 1.0, 1.0)] fill];
+    
+    [NSGraphicsContext restoreGraphicsState];
 }
 
++ (void)_drawFinderLabelHighlight:(NSUInteger)label inRect:(NSRect)rect;
+{
+    FVAPIAssert1(label <= 7, @"Invalid Finder label %ld (must be in the range 
0--7)", (long)label);
+    
+    CGFloat radius = NSHeight(rect) / 2.0;
+    
+    [NSGraphicsContext saveGraphicsState];
+    
+    [[self _colorForLabel:label] setFill];
+    [[NSBezierPath fv_bezierPathWithRoundRect:rect xRadius:radius 
yRadius:radius] fill];
+    
+    [[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setFill];
+    [[NSBezierPath fv_bezierPathWithRoundRect:NSInsetRect(rect, 1.0, 1.0) 
xRadius:radius - 1.0 yRadius:radius - 1.0] fill];
+    
+    [NSGraphicsContext restoreGraphicsState];
+}
+
++ (void)drawFinderLabel:(NSUInteger)label inRect:(NSRect)rect;
+{
+    if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_10) {
+        NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
+        [self _drawFinderLabel:label inRect:NSRectToCGRect(rect) 
ofContext:[nsContext graphicsPort] flipped:[nsContext isFlipped] roundEnds:NO];
+    } else {
+        [self _drawFinderLabel:label inRect:rect];
+    }
+}
+
++ (void)drawFinderLabelHighlight:(NSUInteger)label inRect:(NSRect)rect;
+{
+    if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_10) {
+        NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
+        [self _drawFinderLabel:label inRect:NSRectToCGRect(rect) 
ofContext:[nsContext graphicsPort] flipped:[nsContext isFlipped] roundEnds:YES];
+    } else {
+        [self _drawFinderLabelHighlight:label inRect:rect];
+    }
+}
+
 + (NSUInteger)finderLabelForURL:(NSURL *)aURL;
 {
     FSRef fileRef;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to