From b7ab0132e7ad621a6f55a2dad8cdec159209e585 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 10 Jun 2008 05:09:30 +0000 Subject: [PATCH] the pieces bar "slides" using NSAnimation instead of a timer --- macosx/TorrentTableView.h | 2 +- macosx/TorrentTableView.m | 75 ++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/macosx/TorrentTableView.h b/macosx/TorrentTableView.h index 42a75c287..a709067d0 100644 --- a/macosx/TorrentTableView.h +++ b/macosx/TorrentTableView.h @@ -49,7 +49,7 @@ Torrent * fMenuTorrent; float fPiecesBarPercent; - NSTimer * fPiecesBarTimer; + NSAnimation * fPiecesBarAnimation; } - (BOOL) isGroupCollapsed: (int) value; diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 360ccabef..8667b4312 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -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