Skip to content

Commit 3289b69

Browse files
committed
Bug Fix: Resize album art for info button
Fixes #451 Seems that image resizing doesn't work how we should expect, and it grows the button size permanently to the largest image last assigned to it. Whoops. Signed-off-by: Christopher Snowhill <[email protected]>
1 parent b720328 commit 3289b69

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Application/AppController.m

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,34 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
395395
}
396396

397397
if(entry.albumArt) {
398+
// currently 16x16
399+
//NSSize frameSize = [NSImage imageNamed:@"infoTemplate"].size;
400+
//const CGFloat sizeX = frameSize.width;
401+
//const CGFloat sizeY = frameSize.height;
402+
const CGFloat sizeX = 16.0;
403+
const CGFloat sizeY = 16.0;
404+
405+
NSImage *newButtonImage = [[NSImage alloc] initWithSize:NSMakeSize(sizeX, sizeY)];
406+
NSSize artSize = entry.albumArt.size;
407+
CGFloat maxDim = MAX(artSize.width, artSize.height);
408+
CGFloat ratioX = artSize.width / maxDim;
409+
CGFloat ratioY = artSize.height / maxDim;
410+
CGFloat posX = (maxDim - artSize.width) / 2.0;
411+
CGFloat posY = (maxDim - artSize.height) / 2.0;
412+
posX = posX * sizeX / maxDim;
413+
posY = posY * sizeY / maxDim;
414+
415+
[newButtonImage lockFocus];
416+
[entry.albumArt drawInRect:NSMakeRect(posX, posY, sizeX * ratioX, sizeY * ratioY)
417+
fromRect:NSMakeRect(0, 0, artSize.width, artSize.height)
418+
operation:NSCompositingOperationSourceOver
419+
fraction:1.0];
420+
[newButtonImage unlockFocus];
421+
398422
self.infoButton.imageScaling = NSImageScaleProportionallyUpOrDown;
399-
self.infoButton.image = playlistController.currentEntry.albumArt;
423+
self.infoButton.image = newButtonImage;
400424
self.infoButtonMini.imageScaling = NSImageScaleProportionallyUpOrDown;
401-
self.infoButtonMini.image = playlistController.currentEntry.albumArt;
425+
self.infoButtonMini.image = newButtonImage;
402426
} else {
403427
self.infoButton.imageScaling = NSImageScaleNone;
404428
self.infoButton.image = [NSImage imageNamed:@"infoTemplate"];

0 commit comments

Comments
 (0)