Changeset 915


Ignore:
Timestamp:
Sep 25, 2006, 2:35:32 AM (15 years ago)
Author:
livings124
Message:

compute values even less: only when torrent is first selected

Location:
branches/nat-traversal
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/nat-traversal/PiecesWindowController.h

    r907 r915  
    1212@interface PiecesWindowController : NSWindowController
    1313{
    14     int8_t * fPieces;
     14    int8_t  * fPieces;
    1515   
    1616    NSImage * fExistingImage, * fBack, * fWhitePiece, * fGreenPiece,
     
    1818   
    1919    Torrent * fTorrent;
     20    int     fNumPieces, fAcross;
     21    float   fWidth;
    2022   
    2123    IBOutlet NSImageView * fImageView;
  • branches/nat-traversal/PiecesWindowController.m

    r914 r915  
    9393    {
    9494        fTorrent = [torrent retain];
     95       
     96        //determine relevant values
     97        fNumPieces = MAX_ACROSS * MAX_ACROSS;
     98        if ([fTorrent pieceCount] < fNumPieces)
     99        {
     100            fNumPieces = [fTorrent pieceCount];
     101           
     102            fAcross = sqrt(fNumPieces);
     103            if (fAcross * fAcross < fNumPieces)
     104                fAcross++;
     105        }
     106        else
     107            fAcross = MAX_ACROSS;
     108       
     109        fWidth = ([fExistingImage size].width - (float)(fAcross + 1) * BETWEEN) / (float)fAcross;
     110       
    95111        [self updateView: YES];
    96112    }
     
    108124    }
    109125   
    110     int numPieces = MAX_ACROSS * MAX_ACROSS;
    111     if ([fTorrent pieceCount] < numPieces)
    112         numPieces = [fTorrent pieceCount];
    113    
    114     int8_t * pieces = malloc(numPieces);
    115     [fTorrent getAvailability: pieces size: numPieces];
    116    
    117     int i, j, piece, across;
    118     float width;
     126    int8_t * pieces = malloc(fNumPieces);
     127    [fTorrent getAvailability: pieces size: fNumPieces];
     128   
     129    int i, j, piece;
    119130    NSPoint point;
    120     NSRect rect;
     131    NSRect rect = NSMakeRect(0, 0, fWidth, fWidth);
    121132    NSImage * pieceImage;
    122133    BOOL change = NO;
    123134       
    124     for (i = 0; i < numPieces; i++)
     135    for (i = 0; i < fNumPieces; i++)
    125136    {
    126137        pieceImage = nil;
    127    
    128         if (i >= numPieces)
    129             break;
    130138       
    131139        piece = pieces[i];
     
    176184            if (!change)
    177185            {
    178                 //determine how many boxes and sizes
    179                 if (numPieces < MAX_ACROSS * MAX_ACROSS)
    180                 {
    181                     across = sqrt(numPieces);
    182                     if (across * across < numPieces)
    183                         across++;
    184                 }
    185                 else
    186                     across = MAX_ACROSS;
    187                
    188                 width = ([fExistingImage size].width - (float)(across + 1) * BETWEEN) / (float)across;
    189                 rect = NSMakeRect(0, 0, width, width);
    190                
    191186                [fExistingImage lockFocus];
    192187                change = YES;
    193188            }
    194189           
    195             int numAcross = i % across, numDown = i / across;
    196             point = NSMakePoint((float)numAcross * (width + BETWEEN) + BETWEEN,
    197                                 (float)(across - numDown) * (width + BETWEEN) - width);
     190            int numAcross = i % fAcross, numDown = i / fAcross;
     191            point = NSMakePoint((float)numAcross * (fWidth + BETWEEN) + BETWEEN,
     192                                (float)(fAcross - numDown) * (fWidth + BETWEEN) - fWidth);
     193           
    198194            [pieceImage compositeToPoint: point fromRect: rect operation: NSCompositeSourceOver];
    199195        }
Note: See TracChangeset for help on using the changeset viewer.