From 493d0fa474348465308c8728bb624885e2d7a940 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 10 Jun 2008 19:56:53 +0000 Subject: [PATCH] the pieces bar and pieces view now show shades of blue/green based on progress/availability instead of preset "levels" of color - in other words, it mixes white with either blue or green where the amount of color is the exact percentage of the piece that has been downloaded --- macosx/PiecesView.h | 4 +- macosx/PiecesView.m | 148 +++++++-------------------------------- macosx/PrefsController.m | 2 +- macosx/Torrent.m | 7 +- macosx/TorrentCell.h | 2 +- macosx/TorrentCell.m | 30 ++------ 6 files changed, 37 insertions(+), 156 deletions(-) diff --git a/macosx/PiecesView.h b/macosx/PiecesView.h index 9de87efa1..34af6f49e 100644 --- a/macosx/PiecesView.h +++ b/macosx/PiecesView.h @@ -30,9 +30,7 @@ int8_t * fPieces; NSImage * fBack; - NSColor * fWhiteColor, * fBlueColor, * fOrangeColor, - * fGreen1Color, * fGreen2Color, * fGreen3Color, - * fBlue1Color, * fBlue2Color, * fBlue3Color, * fBlue4Color; + NSColor * fGreenAvailabilityColor, * fBluePieceColor; Torrent * fTorrent; int fNumPieces, fAcross, fWidth, fExtraBorder; diff --git a/macosx/PiecesView.m b/macosx/PiecesView.m index dce5ad264..2b3242229 100644 --- a/macosx/PiecesView.m +++ b/macosx/PiecesView.m @@ -29,6 +29,10 @@ #define MAX_ACROSS 18 #define BETWEEN 1.0 +#define HIGH_PEERS 15 + +#define FINISHED 1 + @implementation PiecesView - (void) awakeFromNib @@ -43,17 +47,9 @@ [fBack unlockFocus]; //store box colors - fWhiteColor = [[NSColor whiteColor] retain]; - fOrangeColor = [[NSColor orangeColor] retain]; - fGreen1Color = [[NSColor colorWithCalibratedRed: 0.6 green: 1.0 blue: 0.8 alpha: 1.0] retain]; - fGreen2Color = [[NSColor colorWithCalibratedRed: 0.4 green: 1.0 blue: 0.6 alpha: 1.0] retain]; - fGreen3Color = [[NSColor colorWithCalibratedRed: 0.0 green: 1.0 blue: 0.4 alpha: 1.0] retain]; - fBlue1Color = [[NSColor colorWithCalibratedRed: 0.8 green: 1.0 blue: 1.0 alpha: 1.0] retain]; - fBlue2Color = [[NSColor colorWithCalibratedRed: 0.6 green: 1.0 blue: 1.0 alpha: 1.0] retain]; - fBlue3Color = [[NSColor colorWithCalibratedRed: 0.6 green: 0.8 blue: 1.0 alpha: 1.0] retain]; - fBlue4Color = [[NSColor colorWithCalibratedRed: 0.4 green: 0.6 blue: 1.0 alpha: 1.0] retain]; - fBlueColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain]; - + fGreenAvailabilityColor = [[NSColor colorWithCalibratedRed: 0.0 green: 1.0 blue: 0.4 alpha: 1.0] retain]; + fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain]; + //actually draw the box [self setTorrent: nil]; } @@ -64,16 +60,8 @@ [fBack release]; - [fWhiteColor release]; - [fOrangeColor release]; - [fGreen1Color release]; - [fGreen2Color release]; - [fGreen3Color release]; - [fBlue1Color release]; - [fBlue2Color release]; - [fBlue3Color release]; - [fBlue4Color release]; - [fBlueColor release]; + [fGreenAvailabilityColor release]; + [fBluePieceColor release]; [super dealloc]; } @@ -142,7 +130,7 @@ NSRect rect = NSMakeRect(0, 0, fWidth, fWidth); BOOL change = NO; - + for (i = 0; i < fAcross; i++) for (j = 0; j < fAcross; j++) { @@ -153,115 +141,33 @@ break; } - NSColor * pieceColor = nil; + NSColor * pieceColor; if (showAvailablity) { - int piece = pieces[index]; - if (piece == -1) - { - if (first || fPieces[index] == -2) - { - fPieces[index] = -1; - pieceColor = fBlueColor; - } - else if (fPieces[index] != -1) - { - fPieces[index] = -2; - pieceColor = fOrangeColor; - } - else; - } - else if (piece == 0) - { - if (first || fPieces[index] != 0) - { - fPieces[index] = 0; - pieceColor = fWhiteColor; - } - } - else if (piece <= 4) - { - if (first || fPieces[index] != 1) - { - fPieces[index] = 1; - pieceColor = fGreen1Color; - } - } - else if (piece <= 8) - { - if (first || fPieces[index] != 2) - { - fPieces[index] = 2; - pieceColor = fGreen2Color; - } - } + if (pieces[index] == -1) + pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor; else { - if (first || fPieces[index] != 3) - { - fPieces[index] = 3; - pieceColor = fGreen3Color; - } + float percent; + if (pieces[index] < HIGH_PEERS) + percent = (float)pieces[index]/HIGH_PEERS; + else + percent = 1.0; + + pieceColor = [[NSColor whiteColor] blendedColorWithFraction: percent ofColor: fGreenAvailabilityColor]; } + + fPieces[index] = pieces[index] == -1 ? FINISHED : 0; } else { - float piecePercent = piecesPercent[index]; - if (piecePercent >= 1.0) - { - if (first || fPieces[index] == -2) - { - fPieces[index] = -1; - pieceColor = fBlueColor; - } - else if (fPieces[index] != -1) - { - fPieces[index] = -2; - pieceColor = fOrangeColor; - } - else; - } - else if (piecePercent == 0.0) - { - if (first || fPieces[index] != 0) - { - fPieces[index] = 0; - pieceColor = fWhiteColor; - } - } - else if (piecePercent < 0.25) - { - if (first || fPieces[index] != 1) - { - fPieces[index] = 1; - pieceColor = fBlue1Color; - } - } - else if (piecePercent < 0.5) - { - if (first || fPieces[index] != 2) - { - fPieces[index] = 2; - pieceColor = fBlue2Color; - } - } - else if (piecePercent < 0.75) - { - if (first || fPieces[index] != 3) - { - fPieces[index] = 3; - pieceColor = fBlue3Color; - } - } + if (piecesPercent[index] == 1.0 && !first && fPieces[index] != FINISHED) + pieceColor = [NSColor orangeColor]; else - { - if (first || fPieces[index] != 4) - { - fPieces[index] = 4; - pieceColor = fBlue4Color; - } - } + pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[index] ofColor: fBluePieceColor]; + + fPieces[index] = piecesPercent[index] == 1.0 ? FINISHED : 0; } if (pieceColor) diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index b6c188abe..c6b79b0dd 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -32,7 +32,7 @@ #define DOWNLOAD_TORRENT 2 #define RPC_ACCESS_ALLOW 0 -#define RPC_ACCESS_DENY 1 +#define RPC_ACCESS_DENY 1 #define RPC_IP_ADD_TAG 0 #define RPC_IP_REMOVE_TAG 1 diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 37eb4c199..558887896 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -168,8 +168,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * if (fFileStat) tr_torrentFilesFree(fFileStat, [self fileCount]); - if (fPreviousFinishedPieces != NULL) - free(fPreviousFinishedPieces); + tr_free(fPreviousFinishedPieces); [fFinishedPiecesDate release]; [fNameString release]; @@ -242,6 +241,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * - (float *) getPreviousAmountFinished { + //if the torrent hasn't been seen in a bit, and therefore hasn't been refreshed, return NULL if (fFinishedPiecesDate && [fFinishedPiecesDate timeIntervalSinceNow] > -2.0) return fPreviousFinishedPieces; else @@ -250,8 +250,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * -(void) setPreviousAmountFinished: (float *) tab { - if (fPreviousFinishedPieces != NULL) - free(fPreviousFinishedPieces); + tr_free(fPreviousFinishedPieces); fPreviousFinishedPieces = tab; [fFinishedPiecesDate release]; diff --git a/macosx/TorrentCell.h b/macosx/TorrentCell.h index 232f7487c..f20a10170 100644 --- a/macosx/TorrentCell.h +++ b/macosx/TorrentCell.h @@ -38,7 +38,7 @@ CTGradient * fWhiteGradient, * fGrayGradient, * fLightGrayGradient, * fBlueGradient, * fDarkBlueGradient, * fGreenGradient, * fLightGreenGradient, * fDarkGreenGradient, * fYellowGradient, * fRedGradient; - NSColor * fGrayColor, * fBlueColor, * fBlue1Color, * fBlue2Color, * fBlue3Color, * fBlue4Color, * fOrangeColor; + NSColor * fBluePieceColor; } - (NSRect) iconRectForBounds: (NSRect) bounds; diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index 02feba886..797dbd17c 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -98,15 +98,7 @@ paragraphStyle, NSParagraphStyleAttributeName, nil]; [paragraphStyle release]; - //store box colors - fGrayColor = [[NSColor colorWithCalibratedRed: 0.95 green: 0.95 blue: 0.95 alpha: 1.0] retain]; - fBlue1Color = [[NSColor colorWithCalibratedRed: 0.8 green: 1.0 blue: 1.0 alpha: 1.0] retain]; - fBlue2Color = [[NSColor colorWithCalibratedRed: 0.6 green: 1.0 blue: 1.0 alpha: 1.0] retain]; - fBlue3Color = [[NSColor colorWithCalibratedRed: 0.6 green: 0.8 blue: 1.0 alpha: 1.0] retain]; - fBlue4Color = [[NSColor colorWithCalibratedRed: 0.4 green: 0.6 blue: 1.0 alpha: 1.0] retain]; - fBlueColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain]; - fOrangeColor = [[NSColor orangeColor] retain]; - + fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain]; fBarBorderColor = [[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] retain]; } return self; @@ -755,24 +747,10 @@ for (i = 0; i < pieceCount; i++) { NSColor * pieceColor; - - if (piecePercent[i] >= 1.0) - { - if (previousPiecePercent != NULL && previousPiecePercent[i] < 1.0) - pieceColor = fOrangeColor; - else - pieceColor = fBlueColor; - } - else if (piecePercent[i] <= 0.0) - pieceColor = fGrayColor; - else if (piecePercent[i] <= 0.25) - pieceColor = fBlue1Color; - else if (piecePercent[i] <= 0.5) - pieceColor = fBlue2Color; - else if (piecePercent[i] <= 0.75) - pieceColor = fBlue3Color; + if (piecePercent[i] == 1.0 && previousPiecePercent != NULL && previousPiecePercent[i] < 1.0) + pieceColor = [NSColor orangeColor]; else - pieceColor = fBlue4Color; + pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecePercent[i] ofColor: fBluePieceColor]; //it's faster to just set color instead of checking previous color [bitmap setColor: pieceColor atX: i y: 0];