replace a loop with math

This commit is contained in:
Mitchell Livingston 2008-03-27 03:32:40 +00:00
parent 456adc3558
commit fab1ffb8a2
2 changed files with 22 additions and 46 deletions

View File

@ -3864,46 +3864,25 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
searchFrame.origin.x += searchFrame.size.width - SEARCH_FILTER_MIN_WIDTH;
searchFrame.size.width = SEARCH_FILTER_MIN_WIDTH;
//resize each button until they don't overlap search
int download = 0;
BOOL seeding = NO, paused = NO;
do
{
if (download < 8)
{
download++;
downloadRect.size.width--;
seedRect.origin.x--;
pauseRect.origin.x--;
}
else if (!seeding)
{
seeding = YES;
seedRect.size.width--;
pauseRect.origin.x--;
}
else if (!paused)
{
paused = YES;
pauseRect.size.width--;
}
else
{
activeRect.size.width--;
downloadRect.origin.x--;
seedRect.origin.x--;
pauseRect.origin.x--;
//reset
download = 0;
seeding = NO;
paused = NO;
}
}
while (NSMaxX(pauseRect) + 5.0 > searchFrame.origin.x);
//resize the buttons so they don't overlay
int difference = (NSMaxX(pauseRect) + 5.0) - searchFrame.origin.x;
//decrease downloading by 8, seeding by 1, paused by 1, active by 1, repeat
int download = (difference / 11 * 8) + MIN(difference % 11 + 1, 8); //8 for every 11
int seed = (difference / 11) + (difference % 11 >= 8 ? 1 : 0);
int paused = (difference / 11) + (difference % 11 >= 9 ? 1 : 0);
int active = (difference / 11) + (difference % 11 >= 10 ? 1 : 0);
activeRect.size.width -= active;
downloadRect.size.width -= download;
downloadRect.origin.x -= active;
seedRect.size.width -= seed;
seedRect.origin.x -= active + download;
pauseRect.size.width -= paused;
pauseRect.origin.x -= active + download + seed;
}
else;

View File

@ -1651,17 +1651,14 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
- (void) createFileList
{
int count = [self fileCount], i;
tr_file * file;
NSMutableArray * pathComponents;
NSString * path;
NSMutableArray * fileList = [[NSMutableArray alloc] initWithCapacity: count];
for (i = 0; i < count; i++)
{
file = &fInfo->files[i];
tr_file * file = &fInfo->files[i];
pathComponents = [[[NSString stringWithUTF8String: file->name] pathComponents] mutableCopy];
NSMutableArray * pathComponents = [[[NSString stringWithUTF8String: file->name] pathComponents] mutableCopy];
NSString * path;
if ([self folder])
{
path = [pathComponents objectAtIndex: 0];