efficiency is advanced bar drawing

This commit is contained in:
Mitchell Livingston 2007-02-09 14:33:57 +00:00
parent 727e167705
commit 131fa9011d
2 changed files with 28 additions and 16 deletions

View File

@ -485,7 +485,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
enumerator = [fTorrents objectEnumerator];
Torrent * torrent;
while (!timeUp && ((torrent = [enumerator nextObject]) || tr_handleStatus(fLib)->natTraversalStatus != TR_NAT_TRAVERSAL_DISABLED))
while (!timeUp && ((torrent = [enumerator nextObject])
|| tr_handleStatus(fLib)->natTraversalStatus != TR_NAT_TRAVERSAL_DISABLED))
while (![torrent isPaused] && !(timeUp = [start timeIntervalSinceNow] < -5.0))
{
usleep(100000);

View File

@ -1342,22 +1342,36 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
index = (int)indexValue;
}
free(piecesAvailablity);
//determine percentage finished and available
float * piecesFinished = malloc(pieceCount * sizeof(float));
[self getAmountFinished: piecesFinished size: pieceCount];
float finished = 0, available = 0;
for (i = 0; i < pieceCount; i++)
int have, avail;
if ([self progress] >= 1.0)
{
finished += piecesFinished[i];
if (piecesAvailablity[i] > 0)
available += 1.0 - piecesFinished[i];
have = MAX_PIECES;
avail = 0;
}
int have = rintf((float)MAX_PIECES * finished / (float)pieceCount),
else if (![self isActive])
{
have = rintf((float)MAX_PIECES * [self progress]);
avail = 0;
}
else
{
float * piecesFinished = malloc(pieceCount * sizeof(float));
[self getAmountFinished: piecesFinished size: pieceCount];
float available = 0;
for (i = 0; i < pieceCount; i++)
available += 1.0 - piecesFinished[i];
have = rintf((float)MAX_PIECES * [self progress]);
avail = rintf((float)MAX_PIECES * available / (float)pieceCount);
if (have + avail > MAX_PIECES) //case if both end in .5 and all pieces are available
avail--;
if (have + avail > MAX_PIECES) //case if both end in .5 and all pieces are available
avail--;
free(piecesFinished);
}
//first two lines: dark blue to show progression, green to show available
p = (uint32_t *)bitmapData;
@ -1377,9 +1391,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
p[i + bytesPerRow / 4] = kWhite;
}
free(piecesAvailablity);
free(piecesFinished);
//actually draw image
NSImage * bar = [[NSImage alloc] initWithSize: [fBitmap size]];
[bar addRepresentation: fBitmap];