Changeset 985 for trunk/macosx
- Timestamp:
- Oct 5, 2006, 9:21:30 PM (16 years ago)
- Location:
- trunk/macosx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Torrent.h
r961 r985 53 53 54 54 int fOrderValue; 55 56 NSBitmapImageRep * fBitmap; 57 int8_t * fPieces; 55 58 } 56 59 -
trunk/macosx/Torrent.m
r980 r985 28 28 #define BAR_HEIGHT 12.0 29 29 30 #define MAX_PIECES 324 31 #define BLANK_PIECE -99 32 30 33 @interface Torrent (Private) 31 34 … … 139 142 [fShortStatusString release]; 140 143 [fRemainingTimeString release]; 144 145 146 [fBitmap release]; 147 free(fPieces); 141 148 } 142 149 [super dealloc]; … … 821 828 fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30]; 822 829 fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30]; 830 831 //set up advanced bar 832 fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil 833 pixelsWide: MAX_PIECES pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES 834 isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0]; 835 836 fPieces = malloc(MAX_PIECES); 837 int i; 838 for (i = 0; i < MAX_PIECES; i++) 839 fPieces[i] = BLANK_PIECE; 823 840 824 841 [self update]; … … 828 845 - (NSImage *) advancedBar 829 846 { 830 int width = 225; //amount of pixels/"pieces"831 832 NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil833 pixelsWide: width pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES834 isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];835 836 847 int h, w; 837 848 uint32_t * p; 838 uint8_t * bitmapData = [ bitmap bitmapData];839 int bytesPerRow = [ bitmap bytesPerRow];840 841 int8_t * pieces = malloc( width);842 [self getAvailability: pieces size: width];849 uint8_t * bitmapData = [fBitmap bitmapData]; 850 int bytesPerRow = [fBitmap bytesPerRow]; 851 852 int8_t * pieces = malloc(MAX_PIECES); 853 [self getAvailability: pieces size: MAX_PIECES]; 843 854 int avail = 0; 844 for (w = 0; w < width; w++)855 for (w = 0; w < MAX_PIECES; w++) 845 856 if (pieces[w] != 0) 846 857 avail++; 847 858 848 859 //first two lines: dark blue to show progression, green to show available 849 int end = lrintf(floor([self progress] * width));860 int end = [self progress] * MAX_PIECES; 850 861 p = (uint32_t *) bitmapData; 851 862 … … 860 871 p[w + bytesPerRow / 4] = kGreen; 861 872 } 862 for (; w < width; w++)873 for (; w < MAX_PIECES; w++) 863 874 { 864 875 p[w] = kWhite; … … 868 879 //lines 2 to 14: blue or grey depending on whether we have the piece or not 869 880 uint32_t color; 870 for( w = 0; w < width; w++ ) 871 { 881 BOOL change; 882 for (w = 0; w < MAX_PIECES; w++) 883 { 884 change = NO; 872 885 if (pieces[w] < 0) 873 color = kGreen; 886 { 887 if (fPieces[w] != -1) 888 { 889 color = kGreen; 890 fPieces[w] = -1; 891 change = YES; 892 } 893 } 874 894 else if (pieces[w] == 0) 875 color = kGray; 895 { 896 if (fPieces[w] != 0) 897 { 898 color = kGray; 899 fPieces[w] = 0; 900 change = YES; 901 } 902 } 876 903 else if (pieces[w] == 1) 877 color = kBlue1; 904 { 905 if (fPieces[w] != 1) 906 { 907 color = kBlue1; 908 fPieces[w] = 1; 909 change = YES; 910 } 911 } 878 912 else if (pieces[w] == 2) 879 color = kBlue2; 913 { 914 if (fPieces[w] != 2) 915 { 916 color = kBlue2; 917 fPieces[w] = 2; 918 change = YES; 919 } 920 } 880 921 else 881 color = kBlue3;882 883 //point to pixel (w, 2) and draw "vertically"884 p = (uint32_t *) ( bitmapData + 2 * bytesPerRow ) + w;885 for( h = 2; h < BAR_HEIGHT; h++ )886 922 { 887 p[0] = color; 888 p = (uint32_t *) ( (uint8_t *) p + bytesPerRow ); 923 if (fPieces[w] != 3) 924 { 925 color = kBlue3; 926 fPieces[w] = 3; 927 change = YES; 928 } 889 929 } 930 931 if (change) 932 { 933 //point to pixel (w, 2) and draw "vertically" 934 p = (uint32_t *)(bitmapData + 2 * bytesPerRow) + w; 935 for (h = 2; h < BAR_HEIGHT; h++) 936 { 937 p[0] = color; 938 p = (uint32_t *)((uint8_t *)p + bytesPerRow); 939 } 940 } 890 941 } 891 942 … … 893 944 894 945 //actually draw image 895 NSImage * bar = [[NSImage alloc] initWithSize: [bitmap size]]; 896 [bar addRepresentation: bitmap]; 897 [bitmap release]; 898 946 NSImage * bar = [[NSImage alloc] initWithSize: [fBitmap size]]; 947 [bar addRepresentation: fBitmap]; 899 948 [bar setScalesWhenResized: YES]; 900 949
Note: See TracChangeset
for help on using the changeset viewer.