Revision: 23907
          http://sourceforge.net/p/bibdesk/svn/23907
Author:   hofman
Date:     2019-06-30 22:24:42 +0000 (Sun, 30 Jun 2019)
Log Message:
-----------
draw progress indicator more like NSProgressIndicator

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.h 
2019-06-30 06:31:01 UTC (rev 23906)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.h 
2019-06-30 22:24:42 UTC (rev 23907)
@@ -56,7 +56,7 @@
 {
 @private
     CGFloat                  _currentProgress;
-    CGFloat                  _currentRotation;
+    NSInteger                _currentStep;
     FVProgressIndicatorStyle _style;
 }
 

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.m 
2019-06-30 06:31:01 UTC (rev 23906)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicatorCell.m 
2019-06-30 22:24:42 UTC (rev 23907)
@@ -41,38 +41,12 @@
 
 @implementation FVProgressIndicatorCell
 
-+ (CGColorRef)_newFillColor
-{
-    // @@ Dark mode
-    CGColorSpaceRef cspace = 
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
-    CGFloat components[4];
-    NSColor *nsColor = [[NSColor selectedControlColor] 
colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
-    [nsColor getComponents:components];
-    // make it slightly transparent
-    components[3] = 0.8;
-    CGColorRef fillColor = CGColorCreate(cspace, components);
-    CGColorSpaceRelease(cspace);
-    return fillColor;
-}
-
-+ (CGColorRef)_newStrokeColor
-{
-    // @@ Dark mode
-    CGColorSpaceRef cspace = 
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
-    CGFloat components[4];
-    NSColor *nsColor = [[NSColor alternateSelectedControlColor] 
colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
-    [nsColor getComponents:components];
-    CGColorRef strokeColor = CGColorCreate(cspace, components);
-    CGColorSpaceRelease(cspace);
-    return strokeColor;
-}
-
 - (id)init
 {
     self = [super init];
     if (self) {
         _currentProgress = 0;
-        _currentRotation = 0;
+        _currentStep = 0;
         _style = FVProgressIndicatorDeterminate;
     }
     return self;
@@ -89,33 +63,48 @@
     CGRect progressRect = NSRectToCGRect(aRect);    
     CGPoint ctr = CGPointMake(CGRectGetMidX(progressRect), 
CGRectGetMidY(progressRect));
     
-    // indeterminate download length
     if (_style == FVProgressIndicatorIndeterminate) {
-        // fixed value of 1/3
-        _currentProgress = 0.333;
-        _currentRotation += M_PI / (CGFloat)10;
-        // rotate the 1/3 sector until the download is complete (see 
_updateProgressIndicators:)
+        // indeterminate download length
+        CGFloat angle = M_PI / 6.0;
         CGContextTranslateCTM(context, ctr.x, ctr.y);
-        CGContextRotateCTM(context, _currentRotation);
+        CGContextRotateCTM(context, _currentStep * angle);
         CGContextTranslateCTM(context, -ctr.x, -ctr.y);
-    }
-    
-    if (0 < _currentProgress && _currentProgress < 1) {
-        CGColorRef fillColor = [[self class] _newFillColor];
-        CGColorRef strokeColor = [[self class] _newStrokeColor];
+        NSInteger i;
+        for (i = 0; i < 12; i++) {
+            CGColorRef strokeColor = CGColorCreateGenericGray(0, 1.0 - i / 
12.0);
+            CGContextSetStrokeColorWithColor(context, strokeColor);
+            CGColorRelease(strokeColor);
+            CGFloat h = CGRectGetHeight(progressRect) / 64;
+            CGContextSetLineWidth(context, 6 * h);
+            CGContextSetLineCap(context, kCGLineCapRound);
+            CGContextBeginPath(context);
+            CGContextMoveToPoint(context, ctr.x, ctr.y - 17 * h);
+            CGContextAddLineToPoint(context, ctr.x, ctr.y - 29 * h);
+            CGContextStrokePath(context);
+            CGContextTranslateCTM(context, ctr.x, ctr.y);
+            CGContextRotateCTM(context, -angle);
+            CGContextTranslateCTM(context, -ctr.x, -ctr.y);
+        }
+        _currentStep = (_currentStep + 1) % 12;
+    } else {
+        // determinate download length
+        CGContextTranslateCTM(context, ctr.x, ctr.y);
+        CGContextTranslateCTM(context, -ctr.x, -ctr.y);
+        CGColorRef fillColor = CGColorCreateGenericGray(0, 0.5);
+        CGColorRef strokeColor = CGColorCreateGenericGray(0, 0.4);
         CGContextSetFillColorWithColor(context, fillColor);
         CGContextSetStrokeColorWithColor(context, strokeColor);
         CGColorRelease(fillColor);
         CGColorRelease(strokeColor);
         CGContextBeginPath(context);
+        CGContextAddEllipseInRect(context, CGRectInset(progressRect, 0.5, 
0.5));
+        CGContextStrokePath(context);
         CGFloat radius = CGRectGetWidth(progressRect) / 2;
         CGContextMoveToPoint(context, ctr.x, ctr.y);
-        CGPoint arcStart = CGPointMake(CGRectGetMaxX(progressRect), 
CGRectGetMidY(progressRect));
-        CGContextAddLineToPoint(context, arcStart.x, arcStart.y);
-        CGFloat angle = 2 * M_PI * _currentProgress;
-        CGContextAddArc(context, ctr.x, ctr.y, radius, 0, angle, false);    
+        CGFloat angle = 2 * M_PI * fmax(fmin(_currentProgress, 1.0), 0.0) - 
M_PI_2;
+        CGContextAddArc(context, ctr.x, ctr.y, radius, -M_PI_2, angle, false);
         CGContextClosePath(context);
-        CGContextDrawPath(context, kCGPathFillStroke);
+        CGContextFillPath(context);
     }
     CGContextRestoreGState(context);
 }

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