Changeset 6119


Ignore:
Timestamp:
Jun 10, 2008, 5:09:30 AM (13 years ago)
Author:
livings124
Message:

the pieces bar "slides" using NSAnimation instead of a timer

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TorrentTableView.h

    r5898 r6119  
    5050   
    5151    float fPiecesBarPercent;
    52     NSTimer * fPiecesBarTimer;
     52    NSAnimation * fPiecesBarAnimation;
    5353}
    5454
  • trunk/macosx/TorrentTableView.m

    r6044 r6119  
    3636#define ACTION_MENU_LIMIT_TAG 103
    3737
    38 #define PIECE_CHANGE 0.1
    39 #define PIECE_TIME 0.005
    40 
    4138#define GROUP_SPEED_IMAGE_COLUMN_WIDTH 8.0
    4239#define GROUP_RATIO_IMAGE_COLUMN_WIDTH 10.0
     
    5350
    5451- (void) createFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
    55 
    56 - (void) resizePiecesBarIncrement;
    5752
    5853@end
     
    110105    [fCollapsedGroups release];
    111106   
    112     [fPiecesBarTimer invalidate];
     107    [fPiecesBarAnimation release];
    113108    [fMenuTorrent release];
    114109   
     
    847842- (void) togglePiecesBar
    848843{
    849     [self resizePiecesBarIncrement];
    850    
    851     if (!fPiecesBarTimer)
    852     {
    853         fPiecesBarTimer = [NSTimer scheduledTimerWithTimeInterval: PIECE_TIME target: self
    854                             selector: @selector(resizePiecesBarIncrement) userInfo: nil repeats: YES];
    855         [[NSRunLoop currentRunLoop] addTimer: fPiecesBarTimer forMode: NSModalPanelRunLoopMode];
    856         [[NSRunLoop currentRunLoop] addTimer: fPiecesBarTimer forMode: NSEventTrackingRunLoopMode];
     844    //stop previous animation
     845    if (fPiecesBarAnimation)
     846    {
     847        [fPiecesBarAnimation stopAnimation];
     848        [fPiecesBarAnimation release];
     849    }
     850   
     851    NSMutableArray * progressMarks = [NSMutableArray arrayWithCapacity: 20];
     852    NSAnimationProgress i;
     853    for (i = 0.0625; i <= 1.0; i += 0.0625)
     854        [progressMarks addObject: [NSNumber numberWithFloat: i]];
     855   
     856    fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration: 0.25 animationCurve: NSAnimationEaseIn];
     857    [fPiecesBarAnimation setAnimationBlockingMode: NSAnimationNonblocking];
     858    [fPiecesBarAnimation setProgressMarks: progressMarks];
     859    [fPiecesBarAnimation setDelegate: self];
     860   
     861    [fPiecesBarAnimation startAnimation];
     862}
     863
     864- (void) animationDidEnd: (NSAnimation *) animation
     865{
     866    if (animation == fPiecesBarAnimation)
     867    {
     868        [fPiecesBarAnimation release];
     869        fPiecesBarAnimation = nil;
     870    }
     871}
     872
     873- (void) animation: (NSAnimation *) animation didReachProgressMark: (NSAnimationProgress) progress
     874{
     875    if (animation == fPiecesBarAnimation)
     876    {
     877        if ([fDefaults boolForKey: @"PiecesBar"])
     878            fPiecesBarPercent = progress;
     879        else
     880            fPiecesBarPercent = 1.0 - progress;
     881       
     882        [self reloadData];
    857883    }
    858884}
     
    963989}
    964990
    965 - (void) resizePiecesBarIncrement
    966 {
    967     BOOL done;
    968     if ([fDefaults boolForKey: @"PiecesBar"])
    969     {
    970         fPiecesBarPercent = MIN(fPiecesBarPercent + PIECE_CHANGE, 1.0);
    971         done = fPiecesBarPercent == 1.0;
    972     }
    973     else
    974     {
    975         fPiecesBarPercent = MAX(fPiecesBarPercent - PIECE_CHANGE, 0.0);
    976         done = fPiecesBarPercent == 0.0;
    977     }
    978    
    979     if (done)
    980     {
    981         [fPiecesBarTimer invalidate];
    982         fPiecesBarTimer = nil;
    983     }
    984    
    985     [self reloadData];
    986 }
    987 
    988991@end
Note: See TracChangeset for help on using the changeset viewer.