summaryrefslogtreecommitdiffstats
path: root/macosx/HBPreviewView.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2016-04-07 11:12:49 +0200
committerDamiano Galassi <[email protected]>2016-04-07 11:12:49 +0200
commitfd32646995d4cf6386a6569a05282fa1dc1f80f0 (patch)
tree5e44a9bc5f1123f74df5171f6a6e19a7802fd091 /macosx/HBPreviewView.m
parente190b46dc6cf35514229b5ff15e48b18981c4f69 (diff)
MacGui: do not update the preview window layer if the image is nil or the size is 0.
Diffstat (limited to 'macosx/HBPreviewView.m')
-rw-r--r--macosx/HBPreviewView.m97
1 files changed, 50 insertions, 47 deletions
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;
+ }
}
/**