Skip to content

Commit

Permalink
* From PR #627
Browse files Browse the repository at this point in the history
  • Loading branch information
PWagner1 committed Jul 12, 2022
1 parent 474611d commit 533ca9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,38 +319,11 @@ public Image GetImage(PaletteState state)
{
// Get value from button spec passing inheritance redirector
var baseImage = ButtonSpec.GetImage(_redirector, state);
if (baseImage == null)
{
return null;
}

if (!_cachedImages.ContainsKey(baseImage))
{
// Currently the `ViewButton.FactorDpi#`'s do _NOT_ change whilst the app is running
_lastFactorDpiX = ViewButton.FactorDpiX;
_lastFactorDpiY = ViewButton.FactorDpiY;

var targetWidth = 16 * _lastFactorDpiX * 1.25f;
var targetHeight = 16 * _lastFactorDpiY * 1.25f;

if ((targetWidth > baseImage.Width) && (targetHeight > baseImage.Height))
{
// Image needs to be regenerated as oversized in order to be scaled back later
// $\Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Rendering\RenderStandard.cs
// line 5779: memento.Image = CommonHelper.ScaleImageForSizedDisplay(memento.Image, currentWidth, currentHeight);

// Note: Something's wrong here? https://github.com/Krypton-Suite/Standard-Toolkit/issues/603
var ratio = 1.0f * Math.Min(baseImage.Width, baseImage.Height) / Math.Max(baseImage.Width, baseImage.Height);
_cachedImages[baseImage] =
CommonHelper.ScaleImageForSizedDisplay(baseImage, baseImage.Width * ratio * _lastFactorDpiX, baseImage.Height * ratio * _lastFactorDpiY);
}
else
{
_cachedImages[baseImage] = baseImage;
}
}

return _cachedImages[baseImage];

// No need to perform scaling as it will be done @
// $\Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Rendering\RenderStandard.cs
// line 5779: memento.Image = CommonHelper.ScaleImageForSizedDisplay(memento.Image, currentWidth, currentHeight);
return baseImage;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5771,31 +5771,15 @@ private static void AllocateImageSpace(StandardContentMemento memento,
try
{
// Check for enough space to show all of the image
if ((displayRect.Width < memento.Image.Width)
|| (displayRect.Height < memento.Image.Height)
)
if ((displayRect.Width < memento.Image.Width) ||

This comment has been minimized.

Copy link
@Smurf-IV

Smurf-IV Jul 12, 2022

Member

I think this is the old code, the good code is what was there just before this

This comment has been minimized.

Copy link
@PWagner1

PWagner1 Jul 12, 2022

Author Contributor

So revert?

This comment has been minimized.

Copy link
@Smurf-IV

Smurf-IV Jul 13, 2022

Member

Yes, And restest.

This comment has been minimized.

Copy link
@PWagner1

PWagner1 Jul 13, 2022

Author Contributor

Do we know where the last known good fix is?

This comment has been minimized.

Copy link
@Smurf-IV

Smurf-IV Jul 14, 2022

Member

It'll be with the PR for the Bug, I've not searched

This comment has been minimized.

Copy link
@PWagner1

PWagner1 Jul 14, 2022

Author Contributor

According to the bug, it's this #627

(displayRect.Height < memento.Image.Height))
{
float ratioW = float.MaxValue;
float ratioH = float.MaxValue;
if (displayRect.Width < memento.Image.Width)
{
ratioW = 1.0f * displayRect.Width / memento.Image.Width;
}

if (displayRect.Height < memento.Image.Height)
{
ratioH = 1.0f * displayRect.Height / memento.Image.Height;
}
var ratio = 1.0f * Math.Min(memento.Image.Width, memento.Image.Height) /
Math.Max(memento.Image.Width, memento.Image.Height);
// Resize image to fit display area
memento.Image = CommonHelper.ScaleImageForSizedDisplay(memento.Image, displayRect.Width * ratio, displayRect.Height * ratio);

var useRatio = Math.Min(ratioW, ratioH);
if (useRatio > 0)
{
// Resize image to fit display area
memento.Image = CommonHelper.ScaleImageForSizedDisplay(memento.Image,
memento.Image.Width * useRatio, memento.Image.Height * useRatio);
}
}

// Cache the size of the image
memento.ImageRect.Size = memento.Image.Size;

Expand Down

0 comments on commit 533ca9c

Please sign in to comment.