transmission/macosx/PeerProgressIndicatorCell.mm

70 lines
2.1 KiB
Plaintext
Raw Normal View History

// This file Copyright © 2007-2023 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
2007-09-16 01:02:06 +00:00
#import "PeerProgressIndicatorCell.h"
#import "NSStringAdditions.h"
@interface PeerProgressIndicatorCell ()
@property(nonatomic, copy) NSDictionary* fAttributes;
@end
2007-09-16 01:02:06 +00:00
@implementation PeerProgressIndicatorCell
- (id)copyWithZone:(NSZone*)zone
{
PeerProgressIndicatorCell* copy = [super copyWithZone:zone];
copy->_fAttributes = _fAttributes;
return copy;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
2007-09-16 01:02:06 +00:00
{
if ([NSUserDefaults.standardUserDefaults boolForKey:@"DisplayPeerProgressBarNumber"])
2008-03-24 02:38:00 +00:00
{
if (!self.fAttributes)
{
NSMutableParagraphStyle* paragraphStyle = [NSParagraphStyle.defaultParagraphStyle mutableCopy];
paragraphStyle.alignment = NSTextAlignmentRight;
self.fAttributes = @{
NSFontAttributeName : [NSFont systemFontOfSize:11.0],
NSForegroundColorAttributeName : NSColor.labelColor,
NSParagraphStyleAttributeName : paragraphStyle
};
}
[[NSString percentString:self.floatValue longDecimals:NO] drawInRect:cellFrame withAttributes:self.fAttributes];
2008-03-24 02:38:00 +00:00
}
else
{
2008-03-24 02:38:00 +00:00
//attributes not needed anymore
if (self.fAttributes)
{
self.fAttributes = nil;
}
[super drawWithFrame:cellFrame inView:controlView];
if (self.seed)
{
NSImage* checkImage = [NSImage imageNamed:@"CompleteCheck"];
NSSize const imageSize = checkImage.size;
NSRect const rect = NSMakeRect(
floor(NSMidX(cellFrame) - imageSize.width * 0.5),
floor(NSMidY(cellFrame) - imageSize.height * 0.5),
imageSize.width,
imageSize.height);
[checkImage drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0
respectFlipped:YES
hints:nil];
}
}
2007-09-16 01:02:06 +00:00
}
@end