mirror of
https://github.com/transmission/transmission
synced 2025-03-10 06:02:57 +00:00
clean up icon memory management for the window drag overlay - pointed out by Stick Men on the forum
This commit is contained in:
parent
fa7a76bbf6
commit
06743cb430
3 changed files with 10 additions and 30 deletions
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
@interface DragOverlayView : NSView
|
@interface DragOverlayView : NSView
|
||||||
{
|
{
|
||||||
NSImage * fBadge, * fBackBadge, * fAppIcon;
|
NSImage * fBadge, * fBackBadge;
|
||||||
|
|
||||||
NSDictionary * fMainLineAttributes, * fSubLineAttributes;
|
NSDictionary * fMainLineAttributes, * fSubLineAttributes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#import "NSBezierPathAdditions.h"
|
#import "NSBezierPathAdditions.h"
|
||||||
|
|
||||||
#define PADDING 10.0
|
#define PADDING 10.0
|
||||||
|
#define ICON_WIDTH 64.0
|
||||||
|
|
||||||
@implementation DragOverlayView
|
@implementation DragOverlayView
|
||||||
|
|
||||||
|
@ -76,9 +77,7 @@
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[fBackBadge release];
|
[fBackBadge release];
|
||||||
|
|
||||||
[fBadge release];
|
[fBadge release];
|
||||||
[fAppIcon release];
|
|
||||||
|
|
||||||
[fMainLineAttributes release];
|
[fMainLineAttributes release];
|
||||||
[fSubLineAttributes release];
|
[fSubLineAttributes release];
|
||||||
|
@ -92,39 +91,19 @@
|
||||||
fBadge = [fBackBadge copy];
|
fBadge = [fBackBadge copy];
|
||||||
NSSize badgeSize = [fBadge size];
|
NSSize badgeSize = [fBadge size];
|
||||||
|
|
||||||
//get icon
|
|
||||||
NSSize iconSize = NSMakeSize(64.0, 64.0);
|
|
||||||
if (!icon)
|
|
||||||
{
|
|
||||||
if (!fAppIcon)
|
|
||||||
{
|
|
||||||
fAppIcon = [[NSImage imageNamed: @"TransmissionDocument.icns"] copy];
|
|
||||||
[fAppIcon setScalesWhenResized: YES];
|
|
||||||
[fAppIcon setSize: iconSize];
|
|
||||||
}
|
|
||||||
icon = [fAppIcon retain];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
icon = [icon copy];
|
|
||||||
[icon setScalesWhenResized: YES];
|
|
||||||
[icon setSize: iconSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
[fBadge lockFocus];
|
|
||||||
|
|
||||||
//place icon
|
//place icon
|
||||||
[icon compositeToPoint: NSMakePoint(PADDING, (badgeSize.height - iconSize.height) * 0.5)
|
[fBadge lockFocus];
|
||||||
operation: NSCompositeSourceOver];
|
const float WIDTH = 64.0;
|
||||||
[icon release];
|
[icon drawInRect: NSMakeRect(PADDING, (badgeSize.height - ICON_WIDTH) * 0.5, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect
|
||||||
|
operation: NSCompositeSourceOver fraction: 1.0];
|
||||||
|
|
||||||
//place main text
|
//place main text
|
||||||
NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
|
NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
|
||||||
NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
|
NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
|
||||||
|
|
||||||
NSRect lineRect = NSMakeRect(PADDING + iconSize.width + 5.0,
|
NSRect lineRect = NSMakeRect(PADDING + ICON_WIDTH + 5.0,
|
||||||
(badgeSize.height + (subLineSize.height + 2.0 - mainLineSize.height)) * 0.5,
|
(badgeSize.height + (subLineSize.height + 2.0 - mainLineSize.height)) * 0.5,
|
||||||
badgeSize.width - (PADDING + iconSize.width + 2.0) - PADDING, mainLineSize.height);
|
badgeSize.width - (PADDING + ICON_WIDTH + 2.0) - PADDING, mainLineSize.height);
|
||||||
[mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
|
[mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
|
||||||
|
|
||||||
//place sub text
|
//place sub text
|
||||||
|
|
|
@ -106,7 +106,6 @@
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//set strings and icon
|
//set strings and icon
|
||||||
NSImage * icon = nil;
|
|
||||||
NSString * secondString = [NSString stringForFileSize: size];
|
NSString * secondString = [NSString stringForFileSize: size];
|
||||||
if (count > 1 || folder)
|
if (count > 1 || folder)
|
||||||
{
|
{
|
||||||
|
@ -118,12 +117,14 @@
|
||||||
secondString = [fileString stringByAppendingString: secondString];
|
secondString = [fileString stringByAppendingString: secondString];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSImage * icon;
|
||||||
if (count == 1)
|
if (count == 1)
|
||||||
icon = [[NSWorkspace sharedWorkspace] iconForFileType: folder ? NSFileTypeForHFSTypeCode('fldr') : [name pathExtension]];
|
icon = [[NSWorkspace sharedWorkspace] iconForFileType: folder ? NSFileTypeForHFSTypeCode('fldr') : [name pathExtension]];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
name = [NSString stringWithFormat: NSLocalizedString(@"%d Torrent Files", "Drag overlay -> torrents"), count];
|
name = [NSString stringWithFormat: NSLocalizedString(@"%d Torrent Files", "Drag overlay -> torrents"), count];
|
||||||
secondString = [secondString stringByAppendingString: @" Total"];
|
secondString = [secondString stringByAppendingString: @" Total"];
|
||||||
|
icon = [NSImage imageNamed: @"TransmissionDocument.icns"];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[self contentView] setOverlay: icon mainLine: name subLine: secondString];
|
[[self contentView] setOverlay: icon mainLine: name subLine: secondString];
|
||||||
|
|
Loading…
Add table
Reference in a new issue