Skip to content

Commit

Permalink
iTunesCantComplain: Improved drawing of "progress" bar and added fall…
Browse files Browse the repository at this point in the history
…back cover art.
  • Loading branch information
uliwitness committed Oct 24, 2010
1 parent c7cfff9 commit 229a20d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Binary file added NoAlbumArt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions iTunesCantComplain.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
554494590DC1237F00733A74 /* iTunes.h in Headers */ = {isa = PBXBuildFile; fileRef = 554494580DC1237F00733A74 /* iTunes.h */; };
5544945D0DC124C000733A74 /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5544945C0DC124C000733A74 /* ScriptingBridge.framework */; };
5572ADE7126B0275004B782C /* NoAlbumArt.png in Resources */ = {isa = PBXBuildFile; fileRef = 5572ADE6126B0275004B782C /* NoAlbumArt.png */; };
8D255AC70486D3F9007BF209 /* iTunesCantComplain_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 32DBCFA80370C50100C91783 /* iTunesCantComplain_Prefix.pch */; };
8D255AC80486D3F9007BF209 /* iTunesCantComplainView.h in Headers */ = {isa = PBXBuildFile; fileRef = F50079790118B23001CA0E54 /* iTunesCantComplainView.h */; };
8D255ACA0486D3F9007BF209 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
Expand All @@ -26,6 +27,7 @@
32DBCFA80370C50100C91783 /* iTunesCantComplain_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTunesCantComplain_Prefix.pch; sourceTree = "<group>"; };
554494580DC1237F00733A74 /* iTunes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTunes.h; sourceTree = "<group>"; };
5544945C0DC124C000733A74 /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = /System/Library/Frameworks/ScriptingBridge.framework; sourceTree = "<absolute>"; };
5572ADE6126B0275004B782C /* NoAlbumArt.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = NoAlbumArt.png; sourceTree = "<group>"; };
8D255AD20486D3F9007BF209 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D255AD30486D3F9007BF209 /* iTunesCantComplain.saver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iTunesCantComplain.saver; sourceTree = BUILT_PRODUCTS_DIR; };
F50079790118B23001CA0E54 /* iTunesCantComplainView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTunesCantComplainView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -72,6 +74,7 @@
children = (
8D255AD20486D3F9007BF209 /* Info.plist */,
089C167DFE841241C02AAC07 /* InfoPlist.strings */,
5572ADE6126B0275004B782C /* NoAlbumArt.png */,
);
name = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -187,6 +190,7 @@
buildActionMask = 2147483647;
files = (
8D255ACA0486D3F9007BF209 /* InfoPlist.strings in Resources */,
5572ADE7126B0275004B782C /* NoAlbumArt.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
30 changes: 23 additions & 7 deletions iTunesCantComplainView.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,25 @@ - (void)drawRect: (NSRect)rect
[[self currTrackArt] drawInRect: desiredBox fromRect: NSZeroRect operation: NSCompositeSourceAtop fraction: 1.0];
}

// if( desiredBox.size.width <= 100.0 )
// {
// desiredBox.size.height = 300.0f * scaleFactor;
// desiredBox.size.width = 300.0f * scaleFactor;
// [[NSColor colorWithCalibratedWhite: 1.0 alpha: 0.5] set];
// NSRectFill(desiredBox);
// }

NSLog( @"iTunesCantComplain: %s coverArtSize = %@", __PRETTY_FUNCTION__, NSStringFromSize( desiredBox.size ) );

[currTrackName drawAtPoint: NSMakePoint(desiredBox.origin.x,desiredBox.origin.y + (390.0f * scaleFactor)) withAttributes: bigAttrs];
[currTrackArtist drawAtPoint: NSMakePoint(desiredBox.origin.x,desiredBox.origin.y + (370.0f * scaleFactor)) withAttributes: smAttrs];
[currTrackAlbum drawAtPoint: NSMakePoint(desiredBox.origin.x,desiredBox.origin.y + (340.0f * scaleFactor)) withAttributes: tinyAttrs];

// Indicate playback progress:
NSRect progressBox = NSMakeRect(NSMinX(desiredBox), NSMinY(desiredBox) -(24.0 * scaleFactor), desiredBox.size.width, (12.0 *scaleFactor));
[[NSColor colorWithCalibratedWhite: 1.0 alpha: 0.3] set];
[NSBezierPath fillRect: progressBox];
[[NSColor whiteColor] set];
[NSBezierPath strokeRect: progressBox];
progressBox.size.width *= [self currTrackPercentage];
[NSBezierPath fillRect: progressBox];

Expand All @@ -118,7 +129,7 @@ - (void)drawRect: (NSRect)rect
[currTrackLyrics drawAtPoint: lyricsPos withAttributes: paleAttrs];
}
NS_HANDLER
NSLog( @"iTunesCantComplain: Error %@", [localException reason] );
NSLog( @"iTunesCantComplain: %s Error %@", __PRETTY_FUNCTION__, [localException reason] );
NS_ENDHANDLER
}

Expand All @@ -144,12 +155,17 @@ -(void) iTunesTrackChanged: (NSNotification*)notif
iTunesApplication* itunes = [SBApplication applicationWithBundleIdentifier: @"com.apple.iTunes"];
iTunesTrack* currTrack = [itunes currentTrack];
NSArray* theImages = [[currTrack artworks] get];
NSString* imgPath = [[NSBundle bundleForClass: [self class]] pathForImageResource: @"NoAlbumArt"];
NSImage* noAlbumArt = [[[NSImage alloc] initWithContentsOfFile: imgPath] autorelease];

NS_DURING
[self setCurrTrackArt: [(iTunesArtwork*)[theImages objectAtIndex: 0] data]];
if( [theImages count] > 0 )
[self setCurrTrackArt: [(iTunesArtwork*)[theImages objectAtIndex: 0] data]];
else
[self setCurrTrackArt: noAlbumArt];
NS_HANDLER
[self setCurrTrackArt: nil];
NSLog( @"iTunesCantComplain: Error %@", [localException reason] );
[self setCurrTrackArt: noAlbumArt];
NSLog( @"iTunesCantComplain: %s(1) Error %@", __PRETTY_FUNCTION__, [localException reason] );
NS_ENDHANDLER
[self setCurrTrackArtist: [currTrack artist]];
[self setCurrTrackAlbum: [currTrack album]];
Expand All @@ -162,7 +178,7 @@ -(void) iTunesTrackChanged: (NSNotification*)notif
[self setCurrTrackLyrics: [currTrack lyrics]];
NS_HANDLER
[self setCurrTrackLyrics: nil];
NSLog( @"iTunesCantComplain: Error %@", [localException reason] );
NSLog( @"iTunesCantComplain: %s(2) Error %@", __PRETTY_FUNCTION__, [localException reason] );
NS_ENDHANDLER
[self setNeedsDisplay: YES];

Expand All @@ -178,7 +194,7 @@ -(void) iTunesTrackChanged: (NSNotification*)notif
imagePos = NSMakePoint( leftMin +(rand() % availWidth),
10 +(rand() % ((int)([self bounds].size.height -(420.0 * scaleFactor)))) );
NS_HANDLER
NSLog( @"iTunesCantComplain: Error %@", [localException reason] );
NSLog( @"iTunesCantComplain: %s(3) Error %@", __PRETTY_FUNCTION__, [localException reason] );
NS_ENDHANDLER
}

Expand Down

0 comments on commit 229a20d

Please sign in to comment.