Revision: 15021
          http://sourceforge.net/p/skim-app/code/15021
Author:   hofman
Date:     2025-03-25 18:28:16 +0000 (Tue, 25 Mar 2025)
Log Message:
-----------
Derive swatch drawing radius from controlSize

Modified Paths:
--------------
    trunk/SKColorSwatch.m

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2025-03-25 18:12:07 UTC (rev 15020)
+++ trunk/SKColorSwatch.m       2025-03-25 18:28:16 UTC (rev 15021)
@@ -74,6 +74,25 @@
 
 #define SKControlSizeLarge 3
 
+static inline CGFloat swatchRadius(NSControlSize controlSize) {
+    if (@available(macOS 11.0, *)) {
+        switch (controlSize) {
+            case NSControlSizeRegular:  return 3.0;
+            case NSControlSizeSmall:    return 2.0;
+            case NSControlSizeMini:     return 1.0;
+            case NSControlSizeLarge:    return 4.0;
+            default:                    return 3.0;
+        }
+    } else {
+        switch (controlSize) {
+            case NSControlSizeRegular:  return 2.0;
+            case NSControlSizeSmall:    return 1.0;
+            case NSControlSizeMini:     return 0.5;
+            default:                    return 2.0;
+        }
+    }
+}
+
 @interface SKColorSwatchBackgroundView : NSControl
 @property (nonatomic) CGFloat bezelWidth;
 @end
@@ -312,12 +331,7 @@
 - (void)drawFocusRingMask {
     NSRect rect = [self focusRingMaskBounds];
     if (NSIsEmptyRect(rect) == NO) {
-        CGFloat r = 3.0;
-        if (@available(macOS 11.0, *))
-            r = ceil(0.25 * bezelHeight) - 3.0;
-        else
-            r = floor(0.25 * bezelHeight) - 3.0;
-        r = fmax(0.5, r);
+        CGFloat r = swatchRadius([self controlSize]);
         [[NSBezierPath bezierPathWithRoundedRect:rect xRadius:r yRadius:r] 
fill];
     }
 }
@@ -386,9 +400,7 @@
                     
                     NSColor *color = [colors objectAtIndex:i];
                     
-                    CGFloat r = 1.5;
-                    if (@available(macOS 11.0, *))
-                        r = 2.5;
+                    CGFloat r = swatchRadius(NSControlSizeRegular) - 0.5;
                     
                     NSImage *image = [NSImage 
bitmapImageWithSize:NSMakeSize(12.0, 12.0) forView:self drawingHandler:^(NSRect 
rect){
                         [color drawSwatchInRect:NSInsetRect(rect, 1.0, 1.0)];
@@ -985,12 +997,7 @@
     if (NSWidth(rect) < 5.0)
         return;
     rect = NSInsetRect(rect, 2.0, 2.0);
-    CGFloat r = 3.0;
-    if (@available(macOS 11.0, *))
-        r = ceil(0.25 * NSHeight(rect)) - 2.0;
-    else
-        r = floor(0.25 * NSHeight(rect) - 2.0);
-    r = fmax(0.5, r);
+    CGFloat r = swatchRadius([(SKColorSwatch *)[self superview] controlSize]);
     BOOL disabled = NO;
     if (@available(macOS 10.14, *))
         disabled = [[self window] isMainWindow] == NO && [[self window] 
isKeyWindow] == NO && ([self isDescendantOf:[[self window] contentView]] == NO 
|| [[self window] isKindOfClass:NSClassFromString(@"NSToolbarSnapshotWindow")]);

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to