refactor: autogenerate the macOS client's Message Log dots (#3224)

* Replaces DotFlat png with generated icons

* code review: udating popup item icons

* code review: increasing inset
This commit is contained in:
A Cœur
2022-06-09 05:35:51 +08:00
committed by GitHub
parent 7056765468
commit af5db6e6f2
42 changed files with 99 additions and 210 deletions

View File

@@ -240,7 +240,6 @@ set(${PROJECT_NAME}_HIDPI_IMAGES
ActionHover
ActionOn
Bandwidth
BlueDotFlat
CleanupTemplate
CompleteCheck
CreateLarge
@@ -249,7 +248,6 @@ set(${PROJECT_NAME}_HIDPI_IMAGES
FavIcon
GearshapeTemplate
Globe
GreenDotFlat
Groups
InfoActivity
InfoFiles
@@ -259,7 +257,6 @@ set(${PROJECT_NAME}_HIDPI_IMAGES
InfoTracker
Lock
Magnet
OrangeDotFlat
PauseHover
PauseOff
PauseOn
@@ -270,8 +267,6 @@ set(${PROJECT_NAME}_HIDPI_IMAGES
PriorityHighTemplate
PriorityLowTemplate
PriorityNormalTemplate
PurpleDotFlat
RedDotFlat
Remote
ResumeHover
ResumeNoWaitHover
@@ -296,7 +291,6 @@ set(${PROJECT_NAME}_HIDPI_IMAGES
Transfers
UpArrowGroupTemplate
UpArrowTemplate
YellowDotFlat
YingYangGroupTemplate
YingYangTemplate
)

View File

@@ -48,7 +48,6 @@
#import "BonjourController.h"
#import "Badger.h"
#import "DragOverlayWindow.h"
#import "NSApplicationAdditions.h"
#import "NSImageAdditions.h"
#import "NSMutableArrayAdditions.h"
#import "NSStringAdditions.h"

View File

@@ -10,7 +10,6 @@
#import "CreatorWindowController.h"
#import "Controller.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#define TRACKER_ADD_TAG 0

View File

@@ -10,7 +10,6 @@
#import "FileOutlineView.h"
#import "FilePriorityCell.h"
#import "FileRenameSheetController.h"
#import "NSApplicationAdditions.h"
#import "NSMutableArrayAdditions.h"
#import "NSStringAdditions.h"

View File

@@ -3,7 +3,6 @@
// License text can be found in the licenses/ folder.
#import "FilterBarView.h"
#import "NSApplicationAdditions.h"
@implementation FilterBarView

View File

@@ -3,8 +3,8 @@
// License text can be found in the licenses/ folder.
#import "GroupsController.h"
#import "NSImageAdditions.h"
#import "NSMutableArrayAdditions.h"
#import "NSApplicationAdditions.h"
#define ICON_WIDTH 16.0
#define BORDER_WIDTH 1.25
@@ -409,26 +409,7 @@ GroupsController* fGroupsInstance = nil;
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
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];
return YES;
}];
icon = [NSImage discIconWithColor:dict[@"Color"] insetFactor:0];
dict[@"Icon"] = icon;

View File

@@ -6,7 +6,6 @@
#import "GroupsController.h"
#import "ExpandedPathToPathTransformer.h"
#import "ExpandedPathToIconTransformer.h"
#import "NSApplicationAdditions.h"
#define GROUP_TABLE_VIEW_DATA_TYPE @"GroupTableViewDataType"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 B

View File

@@ -1,21 +0,0 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "BlueDotFlat.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "BlueDotFlat@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "original"
}
}

View File

@@ -1,21 +0,0 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "GreenDotFlat.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "GreenDotFlat@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 611 B

View File

@@ -1,21 +0,0 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "OrangeDotFlat.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "OrangeDotFlat@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 532 B

View File

@@ -1,21 +0,0 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "PurpleDotFlat.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "PurpleDotFlat@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 543 B

View File

@@ -1,21 +0,0 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "RedDotFlat.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "RedDotFlat@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 542 B

View File

@@ -1,21 +0,0 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "YellowDotFlat.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "YellowDotFlat@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 575 B

View File

@@ -6,7 +6,6 @@
#include <libtransmission/utils.h> //tr_getRatio()
#import "InfoActivityViewController.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#import "PiecesView.h"
#import "Torrent.h"

View File

@@ -6,7 +6,6 @@
#include <libtransmission/utils.h>
#import "InfoPeersViewController.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#import "PeerProgressIndicatorCell.h"
#import "Torrent.h"

View File

@@ -3,7 +3,6 @@
// License text can be found in the licenses/ folder.
#import "InfoTrackersViewController.h"
#import "NSApplicationAdditions.h"
#import "Torrent.h"
#import "TrackerCell.h"
#import "TrackerNode.h"

View File

@@ -11,7 +11,6 @@
#import "InfoFileViewController.h"
#import "InfoOptionsViewController.h"
#import "NSImageAdditions.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#import "Torrent.h"

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -42,16 +42,16 @@
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="15">
<rect key="frame" x="20" y="5" width="101" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<popUpButtonCell key="cell" type="roundTextured" title="Error" bezelStyle="texturedRounded" imagePosition="left" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" inset="2" preferredEdge="maxY" selectedItem="17" id="60">
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" imagePosition="left" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" inset="2" preferredEdge="maxY" id="60">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="16">
<menu key="menu" id="16">
<items>
<menuItem title="Error" state="on" image="RedDotFlat"/>
<menuItem title="Warn" image="OrangeDotFlat"/>
<menuItem title="Info" image="GreenDotFlat"/>
<menuItem title="Debug" image="BlueDotFlat"/>
<menuItem title="Trace" image="PurpleDotFlat"/>
<menuItem title="Error" image="NSStatusUnavailable" id="menuItemError"/>
<menuItem title="Warn" image="NSStatusPartiallyAvailable" id="menuItemWarn"/>
<menuItem title="Info" image="NSStatusAvailable" id="menuItemInfo"/>
<menuItem title="Debug" image="NSStatusNone" id="menuItemDebug"/>
<menuItem title="Trace" image="NSStatusNone" id="menuItemTracer"/>
</items>
</menu>
</popUpButtonCell>
@@ -174,9 +174,10 @@
</window>
</objects>
<resources>
<image name="PurpleDotFlat" width="16" height="16"/>
<image name="RedDotFlat" width="16" height="16"/>
<image name="YellowDotFlat" width="16" height="16"/>
<image name="NSStatusAvailable" width="16" height="16"/>
<image name="NSStatusNone" width="16" height="16"/>
<image name="NSStatusPartiallyAvailable" width="16" height="16"/>
<image name="NSStatusUnavailable" width="16" height="16"/>
<image name="imageCell:63:image" width="14" height="14">
<mutableData key="keyedArchiveRepresentation">
YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05T

View File

@@ -7,7 +7,7 @@
#import "MessageWindowController.h"
#import "Controller.h"
#import "NSApplicationAdditions.h"
#import "NSImageAdditions.h"
#import "NSMutableArrayAdditions.h"
#import "NSStringAdditions.h"
@@ -75,6 +75,11 @@
[self.fLevelButton itemAtIndex:LEVEL_INFO].title = NSLocalizedString(@"Info", "Message window -> level string");
[self.fLevelButton itemAtIndex:LEVEL_DEBUG].title = NSLocalizedString(@"Debug", "Message window -> level string");
[self.fLevelButton itemAtIndex:LEVEL_TRACE].title = NSLocalizedString(@"Trace", "Message window -> level string");
[self.fLevelButton itemAtIndex:LEVEL_ERROR].image = [self.class iconForLevel:TR_LOG_ERROR];
[self.fLevelButton itemAtIndex:LEVEL_WARN].image = [self.class iconForLevel:TR_LOG_WARN];
[self.fLevelButton itemAtIndex:LEVEL_INFO].image = [self.class iconForLevel:TR_LOG_INFO];
[self.fLevelButton itemAtIndex:LEVEL_DEBUG].image = [self.class iconForLevel:TR_LOG_DEBUG];
[self.fLevelButton itemAtIndex:LEVEL_TRACE].image = [self.class iconForLevel:TR_LOG_TRACE];
CGFloat const levelButtonOldWidth = NSWidth(self.fLevelButton.frame);
[self.fLevelButton sizeToFit];
@@ -182,6 +187,56 @@
[self updateLog:nil];
}
+ (NSImage*)iconForLevel:(NSInteger)level
{
NSColor* color;
switch (level)
{
case TR_LOG_CRITICAL:
case TR_LOG_ERROR:
color = NSColor.systemRedColor;
break;
case TR_LOG_WARN:
color = NSColor.systemOrangeColor;
break;
case TR_LOG_INFO:
color = NSColor.systemGreenColor;
break;
case TR_LOG_DEBUG:
if (@available(macOS 10.12, *))
{
color = NSColor.systemTealColor;
}
else
{
color = NSColor.cyanColor;
}
break;
case TR_LOG_TRACE:
color = NSColor.systemPurpleColor;
break;
default:
NSAssert1(NO, @"Unknown message log level: %ld", level);
return nil;
}
// cache dictionary
static NSMutableDictionary<NSColor*, NSImage*>* icons = [NSMutableDictionary dictionary];
NSImage* icon;
if ((icon = icons[color]))
{
return icon;
}
icon = [NSImage discIconWithColor:color insetFactor:0.5];
icons[color] = icon;
return icon;
}
- (void)updateLog:(NSTimer*)timer
{
tr_log_message* messages;
@@ -269,28 +324,7 @@
else if ([ident isEqualToString:@"Level"])
{
NSInteger const level = [message[@"Level"] integerValue];
switch (level)
{
case TR_LOG_CRITICAL:
case TR_LOG_ERROR:
return [NSImage imageNamed:@"RedDotFlat"];
case TR_LOG_WARN:
return [NSImage imageNamed:@"OrangeDotFlat"];
case TR_LOG_INFO:
return [NSImage imageNamed:@"GreenDotFlat"];
case TR_LOG_DEBUG:
return [NSImage imageNamed:@"BlueDotFlat"];
case TR_LOG_TRACE:
return [NSImage imageNamed:@"PurpleDotFlat"];
default:
NSAssert1(NO, @"Unknown message log level: %ld", level);
return nil;
}
return [self.class iconForLevel:level];
}
else if ([ident isEqualToString:@"Name"])
{

View File

@@ -6,7 +6,6 @@
@interface NSApplication (NSApplicationAdditions)
@property(nonatomic, getter=isOnMojaveOrBetter, readonly) BOOL onMojaveOrBetter;
@property(nonatomic, getter=isDarkMode, readonly) BOOL darkMode;
@end

View File

@@ -6,11 +6,6 @@
@implementation NSApplication (NSApplicationAdditions)
- (BOOL)isOnMojaveOrBetter
{
return floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_13;
}
- (BOOL)isDarkMode
{
if (@available(macOS 10.14, *))

View File

@@ -6,6 +6,7 @@
@interface NSImage (NSImageAdditions)
+ (NSImage*)discIconWithColor:(NSColor*)color insetFactor:(CGFloat)insetFactor;
- (NSImage*)imageWithColor:(NSColor*)color;
/* macOS < 11 compatibility */

View File

@@ -5,9 +5,35 @@
#import "CocoaCompatibility.h"
#import "NSImageAdditions.h"
#import "NSApplicationAdditions.h"
@implementation NSImage (NSImageAdditions)
#define ICON_WIDTH 16.0
#define BORDER_WIDTH 1.25
+ (NSImage*)discIconWithColor:(NSColor*)color insetFactor:(CGFloat)insetFactor
{
return [NSImage imageWithSize:NSMakeSize(ICON_WIDTH, ICON_WIDTH) flipped:NO drawingHandler:^BOOL(NSRect rect) {
//shape
rect = NSInsetRect(rect, BORDER_WIDTH / 2 + rect.size.width * insetFactor / 2, BORDER_WIDTH / 2 + rect.size.height * insetFactor / 2);
NSBezierPath* bp = [NSBezierPath bezierPathWithOvalInRect:rect];
bp.lineWidth = BORDER_WIDTH;
//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];
return YES;
}];
}
- (NSImage*)imageWithColor:(NSColor*)color
{
NSImage* coloredImage = [self copy];

View File

@@ -17,7 +17,6 @@
#import "Controller.h"
#import "PortChecker.h"
#import "BonjourController.h"
#import "NSApplicationAdditions.h"
#import "NSImageAdditions.h"
#import "NSStringAdditions.h"

View File

@@ -5,7 +5,6 @@
#import "ShareToolbarItem.h"
#import "ShareTorrentFileHelper.h"
#import "NSApplicationAdditions.h"
@implementation ShareToolbarItem

View File

@@ -4,7 +4,6 @@
#import "StatsWindowController.h"
#import "Controller.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#define UPDATE_SECONDS 1.0

View File

@@ -3,7 +3,6 @@
// License text can be found in the licenses/ folder.
#import "StatusBarView.h"
#import "NSApplicationAdditions.h"
@interface StatusBarView ()

View File

@@ -15,7 +15,6 @@
#import "Torrent.h"
#import "GroupsController.h"
#import "FileListNode.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#import "TrackerNode.h"

View File

@@ -8,7 +8,6 @@
#import "Controller.h"
#import "FileListNode.h"
#import "InfoOptionsViewController.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#import "Torrent.h"
#import "TorrentCell.h"

View File

@@ -3,7 +3,6 @@
// License text can be found in the licenses/ folder.
#import "TrackerNode.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
@interface TrackerNode ()