From 94610f3bc5cfe9d7fec1b8566a10ddb533b99b5c Mon Sep 17 00:00:00 2001 From: Lorenz Cuno Klopfenstein Date: Thu, 1 Jul 2010 13:20:21 +0200 Subject: [PATCH] Fixed thumbnail panel to pad and resize thumbnails with smaller aspect ratio than the form (vertical resize and horizontal padding). --- OnTopReplica/ThumbnailPanel.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/OnTopReplica/ThumbnailPanel.cs b/OnTopReplica/ThumbnailPanel.cs index c25f9a8..875441c 100644 --- a/OnTopReplica/ThumbnailPanel.cs +++ b/OnTopReplica/ThumbnailPanel.cs @@ -198,9 +198,11 @@ namespace OnTopReplica { try { Size sourceSize = ThumbnailOriginalSize; _thumbnailSize = ComputeIdealSize(sourceSize, Size); + + _padWidth = (Size.Width - _thumbnailSize.Width) / 2; _padHeight = (Size.Height - _thumbnailSize.Height) / 2; - var target = new Rectangle(0, _padHeight, _thumbnailSize.Width, _thumbnailSize.Height); + var target = new Rectangle(_padWidth, _padHeight, _thumbnailSize.Width, _thumbnailSize.Height); Rectangle source = (_regionEnabled) ? _regionCurrent : new Rectangle(Point.Empty, _thumbnail.SourceSize); _thumbnail.Update(target, source, ThumbnailOpacity, true, true); @@ -221,9 +223,14 @@ namespace OnTopReplica { private Size ComputeIdealSize(Size sourceSize, Size clientSize) { double sourceRatio = (double)sourceSize.Width / (double)sourceSize.Height; double clientRatio = (double)clientSize.Width / (double)clientSize.Height; - - Size ret = new Size(clientSize.Width, (int)((double)clientSize.Width / sourceRatio)); - //TODO: enable width padding if width > height + + Size ret; + if (sourceRatio >= clientRatio) { + ret = new Size(clientSize.Width, (int)((double)clientSize.Width / sourceRatio)); + } + else { + ret = new Size((int)((double)clientSize.Height * sourceRatio), clientSize.Height); + } return ret; }