Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix group icon border #3094

Merged
merged 6 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion macosx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ set(${PROJECT_NAME}_HIDPI_IMAGES
Globe
GreenDotFlat
Groups
GroupsNoneTemplate
InfoActivity
InfoFiles
InfoGeneral
Expand Down
71 changes: 52 additions & 19 deletions macosx/GroupsController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#import "GroupsController.h"
#import "NSMutableArrayAdditions.h"
#import "NSApplicationAdditions.h"

#define ICON_WIDTH 16.0
#define BORDER_WIDTH 1.25
#define ICON_WIDTH_SMALL 12.0

@interface GroupsController ()
Expand Down Expand Up @@ -138,7 +140,7 @@ - (void)setName:(NSString*)name forIndex:(NSInteger)index
- (NSImage*)imageForIndex:(NSInteger)index
{
NSInteger orderIndex = [self rowValueForIndex:index];
return orderIndex != -1 ? [self imageForGroup:self.fGroups[orderIndex]] : [NSImage imageNamed:@"GroupsNoneTemplate"];
return orderIndex != -1 ? [self imageForGroup:self.fGroups[orderIndex]] : [self imageForGroupNone];
}

- (NSColor*)colorForIndex:(NSInteger)index
Expand Down Expand Up @@ -299,7 +301,7 @@ - (NSMenu*)groupMenuWithTarget:(id)target action:(SEL)action isSmall:(BOOL)small
item.target = target;
item.tag = -1;

NSImage* icon = [NSImage imageNamed:@"GroupsNoneTemplate"];
NSImage* icon = [self imageForGroupNone];
if (small)
{
icon = [icon copy];
Expand Down Expand Up @@ -369,33 +371,64 @@ - (void)saveGroups
[NSUserDefaults.standardUserDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:groups] forKey:@"GroupDicts"];
}

- (NSImage*)imageForGroup:(NSMutableDictionary*)dict
- (NSImage*)imageForGroupNone
{
NSImage* image;
if ((image = dict[@"Icon"]))
static NSImage* icon;
if (icon)
{
return image;
return icon;
}

NSColor* color = dict[@"Color"];
icon = [NSImage imageWithSize:NSMakeSize(ICON_WIDTH, ICON_WIDTH) flipped:NO drawingHandler:^BOOL(NSRect rect) {
//shape
rect = NSInsetRect(rect, BORDER_WIDTH / 2, BORDER_WIDTH / 2);
NSBezierPath* bp = [NSBezierPath bezierPathWithOvalInRect:rect];
bp.lineWidth = BORDER_WIDTH;

//border
// code reference for dashed style
//CGFloat dashAndGapLength = M_PI * rect.size.width / 8;
//CGFloat pattern[2] = { dashAndGapLength * .5, dashAndGapLength * .5 };
//[bp setLineDash:pattern count:2 phase:0];

[NSColor.controlTextColor setStroke];
[bp stroke];

NSRect rect = NSMakeRect(0.0, 0.0, ICON_WIDTH, ICON_WIDTH);
return YES;
}];
[icon setTemplate:YES];

return icon;
}

NSImage* icon = [[NSImage alloc] initWithSize:rect.size];
- (NSImage*)imageForGroup:(NSMutableDictionary*)dict
{
NSImage* icon;
if ((icon = dict[@"Icon"]))
{
return icon;
}

NSColor* color = dict[@"Color"];

[icon lockFocus];
icon = [NSImage imageWithSize:NSMakeSize(ICON_WIDTH, ICON_WIDTH) flipped:NO drawingHandler:^BOOL(NSRect rect) {
//shape
rect = NSInsetRect(rect, BORDER_WIDTH / 2, BORDER_WIDTH / 2);
NSBezierPath* bp = [NSBezierPath bezierPathWithOvalInRect:rect];
bp.lineWidth = BORDER_WIDTH;

//border
NSBezierPath* bp = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:rect.size.width / 2 yRadius:rect.size.width / 2];
NSGradient* gradient = [[NSGradient alloc] initWithStartingColor:[color blendedColorWithFraction:0.45 ofColor:NSColor.whiteColor]
endingColor:color];
[gradient drawInBezierPath:bp angle:0.0];
//border
CGFloat fractionOfBlendedColor = [NSApp isDarkMode] ? 0.15 : 0.3;
NSColor* borderColor = [color blendedColorWithFraction:fractionOfBlendedColor ofColor:NSColor.controlTextColor];
[borderColor setStroke];
[bp stroke];

//inside
[color setFill];
[bp fill];
//inside
[color setFill];
[bp fill];

[icon unlockFocus];
return YES;
}];

dict[@"Icon"] = icon;

Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion macosx/da.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Ingen" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Ingen" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/de.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Keine" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Keine" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/en.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="None" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="None" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/es.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Ninguno" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Ninguno" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/fr.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Aucun" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Aucun" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/it.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Nessuno" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Nessuno" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/nl.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Geen" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Geen" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/pt_PT.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Nenhum" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Nenhum" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/ru.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="None" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="None" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down
2 changes: 1 addition & 1 deletion macosx/tr.lproj/AddMagnetWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Gw
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="35">
<items>
<menuItem title="Hiçbiri" state="on" image="GroupsNoneTemplate" id="2zq-5y-smI">
<menuItem title="Hiçbiri" state="on" image="circle.dashed" catalog="system" id="2zq-5y-smI">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down