From fd32646995d4cf6386a6569a05282fa1dc1f80f0 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 7 Apr 2016 11:12:49 +0200 Subject: MacGui: do not update the preview window layer if the image is nil or the size is 0. --- macosx/HBPreviewView.m | 97 ++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 47 deletions(-) (limited to 'macosx/HBPreviewView.m') diff --git a/macosx/HBPreviewView.m b/macosx/HBPreviewView.m index 5a8140d5a..3da874889 100644 --- a/macosx/HBPreviewView.m +++ b/macosx/HBPreviewView.m @@ -158,66 +158,69 @@ { // Set the picture size display fields below the Preview Picture NSSize imageSize = NSMakeSize(CGImageGetWidth(self.image), CGImageGetHeight(self.image)); - NSSize imageScaledSize = imageSize; - if (self.window.backingScaleFactor != 1.0) - { - // HiDPI mode usually display everything - // with douple pixel count, but we don't - // want to double the size of the video - imageScaledSize.height /= self.window.backingScaleFactor; - imageScaledSize.width /= self.window.backingScaleFactor; - } + if (imageSize.width > 0 && imageSize.height > 0) { + NSSize imageScaledSize = imageSize; - NSSize frameSize = self.frame.size; + if (self.window.backingScaleFactor != 1.0) + { + // HiDPI mode usually display everything + // with douple pixel count, but we don't + // want to double the size of the video + imageScaledSize.height /= self.window.backingScaleFactor; + imageScaledSize.width /= self.window.backingScaleFactor; + } - if (self.showBorder == YES) - { - frameSize.width -= BORDER_SIZE * 2; - frameSize.height -= BORDER_SIZE * 2; - } + NSSize frameSize = self.frame.size; - if (self.fitToView == YES) - { - // We are in Fit to View mode so, we have to get the ratio for height and width against the window - // size so we can scale from there. - imageScaledSize = [self scaledSize:imageScaledSize toFit:frameSize]; - } - else - { - // If the image is larger then the view, scale the image - if (imageScaledSize.width > frameSize.width || imageScaledSize.height > frameSize.height) + if (self.showBorder == YES) { - imageScaledSize = [self scaledSize:imageScaledSize toFit:frameSize]; + frameSize.width -= BORDER_SIZE * 2; + frameSize.height -= BORDER_SIZE * 2; } - } - - [NSAnimationContext beginGrouping]; - [[NSAnimationContext currentContext] setDuration:0]; - // Resize the CALayers - CGRect backRect = CGRectMake(0, 0, imageScaledSize.width + (BORDER_SIZE * 2), imageScaledSize.height + (BORDER_SIZE * 2)); - CGRect pictureRect = CGRectMake(0, 0, imageScaledSize.width, imageScaledSize.height); + if (self.fitToView == YES) + { + // We are in Fit to View mode so, we have to get the ratio for height and width against the window + // size so we can scale from there. + imageScaledSize = [self scaledSize:imageScaledSize toFit:frameSize]; + } + else + { + // If the image is larger then the view, scale the image + if (imageScaledSize.width > frameSize.width || imageScaledSize.height > frameSize.height) + { + imageScaledSize = [self scaledSize:imageScaledSize toFit:frameSize]; + } + } - backRect = CGRectIntegral(backRect); - pictureRect = CGRectIntegral(pictureRect); + [NSAnimationContext beginGrouping]; + [[NSAnimationContext currentContext] setDuration:0]; - self.backLayer.bounds = backRect; - self.pictureLayer.bounds = pictureRect; + // Resize the CALayers + CGRect backRect = CGRectMake(0, 0, imageScaledSize.width + (BORDER_SIZE * 2), imageScaledSize.height + (BORDER_SIZE * 2)); + CGRect pictureRect = CGRectMake(0, 0, imageScaledSize.width, imageScaledSize.height); - // Position the CALayers - CGPoint anchor = CGPointMake(floor((self.frame.size.width - pictureRect.size.width) / 2), - floor((self.frame.size.height - pictureRect.size.height) / 2)); - [self.pictureLayer setPosition:anchor]; + backRect = CGRectIntegral(backRect); + pictureRect = CGRectIntegral(pictureRect); - CGPoint backAchor = CGPointMake(anchor.x - BORDER_SIZE, anchor.y - BORDER_SIZE); - [self.backLayer setPosition:backAchor]; + self.backLayer.bounds = backRect; + self.pictureLayer.bounds = pictureRect; - [NSAnimationContext endGrouping]; + // Position the CALayers + CGPoint anchor = CGPointMake(floor((self.frame.size.width - pictureRect.size.width) / 2), + floor((self.frame.size.height - pictureRect.size.height) / 2)); + [self.pictureLayer setPosition:anchor]; - // Update the proprierties - self.scale = self.pictureLayer.frame.size.width / imageSize.width; - self.pictureFrame = self.pictureLayer.frame; + CGPoint backAchor = CGPointMake(anchor.x - BORDER_SIZE, anchor.y - BORDER_SIZE); + [self.backLayer setPosition:backAchor]; + + [NSAnimationContext endGrouping]; + + // Update the proprierties + self.scale = self.pictureLayer.frame.size.width / imageSize.width; + self.pictureFrame = self.pictureLayer.frame; + } } /** -- cgit v1.2.3