mirror of
https://github.com/transmission/transmission
synced 2025-01-31 03:12:44 +00:00
the pieces bar "slides" using NSAnimation instead of a timer
This commit is contained in:
parent
a1c55c7444
commit
b7ab0132e7
2 changed files with 40 additions and 37 deletions
|
@ -49,7 +49,7 @@
|
|||
Torrent * fMenuTorrent;
|
||||
|
||||
float fPiecesBarPercent;
|
||||
NSTimer * fPiecesBarTimer;
|
||||
NSAnimation * fPiecesBarAnimation;
|
||||
}
|
||||
|
||||
- (BOOL) isGroupCollapsed: (int) value;
|
||||
|
|
|
@ -35,9 +35,6 @@
|
|||
#define ACTION_MENU_UNLIMITED_TAG 102
|
||||
#define ACTION_MENU_LIMIT_TAG 103
|
||||
|
||||
#define PIECE_CHANGE 0.1
|
||||
#define PIECE_TIME 0.005
|
||||
|
||||
#define GROUP_SPEED_IMAGE_COLUMN_WIDTH 8.0
|
||||
#define GROUP_RATIO_IMAGE_COLUMN_WIDTH 10.0
|
||||
|
||||
|
@ -53,8 +50,6 @@
|
|||
|
||||
- (void) createFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
|
||||
|
||||
- (void) resizePiecesBarIncrement;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TorrentTableView
|
||||
|
@ -109,7 +104,7 @@
|
|||
{
|
||||
[fCollapsedGroups release];
|
||||
|
||||
[fPiecesBarTimer invalidate];
|
||||
[fPiecesBarAnimation release];
|
||||
[fMenuTorrent release];
|
||||
|
||||
[fSelectedValues release];
|
||||
|
@ -846,14 +841,45 @@
|
|||
|
||||
- (void) togglePiecesBar
|
||||
{
|
||||
[self resizePiecesBarIncrement];
|
||||
|
||||
if (!fPiecesBarTimer)
|
||||
//stop previous animation
|
||||
if (fPiecesBarAnimation)
|
||||
{
|
||||
fPiecesBarTimer = [NSTimer scheduledTimerWithTimeInterval: PIECE_TIME target: self
|
||||
selector: @selector(resizePiecesBarIncrement) userInfo: nil repeats: YES];
|
||||
[[NSRunLoop currentRunLoop] addTimer: fPiecesBarTimer forMode: NSModalPanelRunLoopMode];
|
||||
[[NSRunLoop currentRunLoop] addTimer: fPiecesBarTimer forMode: NSEventTrackingRunLoopMode];
|
||||
[fPiecesBarAnimation stopAnimation];
|
||||
[fPiecesBarAnimation release];
|
||||
}
|
||||
|
||||
NSMutableArray * progressMarks = [NSMutableArray arrayWithCapacity: 20];
|
||||
NSAnimationProgress i;
|
||||
for (i = 0.0625; i <= 1.0; i += 0.0625)
|
||||
[progressMarks addObject: [NSNumber numberWithFloat: i]];
|
||||
|
||||
fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration: 0.25 animationCurve: NSAnimationEaseIn];
|
||||
[fPiecesBarAnimation setAnimationBlockingMode: NSAnimationNonblocking];
|
||||
[fPiecesBarAnimation setProgressMarks: progressMarks];
|
||||
[fPiecesBarAnimation setDelegate: self];
|
||||
|
||||
[fPiecesBarAnimation startAnimation];
|
||||
}
|
||||
|
||||
- (void) animationDidEnd: (NSAnimation *) animation
|
||||
{
|
||||
if (animation == fPiecesBarAnimation)
|
||||
{
|
||||
[fPiecesBarAnimation release];
|
||||
fPiecesBarAnimation = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) animation: (NSAnimation *) animation didReachProgressMark: (NSAnimationProgress) progress
|
||||
{
|
||||
if (animation == fPiecesBarAnimation)
|
||||
{
|
||||
if ([fDefaults boolForKey: @"PiecesBar"])
|
||||
fPiecesBarPercent = progress;
|
||||
else
|
||||
fPiecesBarPercent = 1.0 - progress;
|
||||
|
||||
[self reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -962,27 +988,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void) resizePiecesBarIncrement
|
||||
{
|
||||
BOOL done;
|
||||
if ([fDefaults boolForKey: @"PiecesBar"])
|
||||
{
|
||||
fPiecesBarPercent = MIN(fPiecesBarPercent + PIECE_CHANGE, 1.0);
|
||||
done = fPiecesBarPercent == 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fPiecesBarPercent = MAX(fPiecesBarPercent - PIECE_CHANGE, 0.0);
|
||||
done = fPiecesBarPercent == 0.0;
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
[fPiecesBarTimer invalidate];
|
||||
fPiecesBarTimer = nil;
|
||||
}
|
||||
|
||||
[self reloadData];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue