Skip to content

Commit

Permalink
Merge pull request #1967 from Krypton-Suite/560-alpha-CheckBox-Image-…
Browse files Browse the repository at this point in the history
…Scaling

 - Add DPI Scaling to the Checkbox images
  • Loading branch information
PWagner1 authored Dec 17, 2024
2 parents 6ffbb41 + e956462 commit 164ae6a
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 101 deletions.
3 changes: 3 additions & 0 deletions Documents/Changelog/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
=======

## 2025-11-xx - Build 2511 - November 2025
* Resolved [#560](https://github.com/Krypton-Suite/Standard-Toolkit/issues/560), CheckBox Images are not scaled with dpi Awareness
* Resolved [#565](https://github.com/Krypton-Suite/Standard-Toolkit/issues/565), GroupBox icons are not scaled for dpi awareness
* Resolved [#559](https://github.com/Krypton-Suite/Standard-Toolkit/issues/559), Header group icon is not scaled for dpi awareness
* Resolved [#1946](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1946), ButtonSpecs do not scale anymore!
Expand Down Expand Up @@ -40,6 +41,7 @@
=======

## 2025-02-01 - Build 2502 (Version 95 - Patch 1) - February 2025
* Resolved [#560](https://github.com/Krypton-Suite/Standard-Toolkit/issues/560), CheckBox Images are not scaled with dpi Awareness
* Resolved [#565](https://github.com/Krypton-Suite/Standard-Toolkit/issues/565), GroupBox icons are not scaled for dpi awareness
* Resolved [#559](https://github.com/Krypton-Suite/Standard-Toolkit/issues/559), Header group icon is not scaled for dpi awareness
* Resolved [#1946](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1946), ButtonSpecs do not scale anymore!
Expand Down Expand Up @@ -225,6 +227,7 @@
=======

# 2025-02-01 - Build 2502 (Patch 5) - February 2025
* Resolved [#560](https://github.com/Krypton-Suite/Standard-Toolkit/issues/560), CheckBox Images are not scaled with dpi Awareness
* Resolved [#565](https://github.com/Krypton-Suite/Standard-Toolkit/issues/565), GroupBox icons are not scaled for dpi awareness
* Resolved [#559](https://github.com/Krypton-Suite/Standard-Toolkit/issues/559), Header group icon is not scaled for dpi awareness
* Resolved [#1946](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1946), ButtonSpecs do not scale anymore!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public override void RenderBefore([DisallowNull] RenderContext context)
{
// We always draw the image a 24x24 image (if dpi = 1!)
localImage = CommonHelper.ScaleImageForSizedDisplay(localImage, localImage.Width * FactorDpiX,
localImage.Height * FactorDpiY);
localImage.Height * FactorDpiY, false);

if (localImage != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void OnClick(object? sender, MouseEventArgs e)
}
*/

_cachedImage = CommonHelper.ScaleImageForSizedDisplay(sourceImage, currentWidth, currentHeight);
_cachedImage = CommonHelper.ScaleImageForSizedDisplay(sourceImage, currentWidth, currentHeight, false);
}

return _cachedImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ protected virtual void OnFinishDelegate(object? sender, EventArgs? e) =>
float dpiFactor = _controller?.Target.FactorDpiX ?? 1f;
return (baseImage != null)
? CommonHelper.ScaleImageForSizedDisplay(baseImage, baseImage.Width * dpiFactor,
baseImage.Height * dpiFactor)
baseImage.Height * dpiFactor, true)
: null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ public KryptonFormTitleStyle TitleStyle
// Cache for future access
if (resizedBitmap != null)
{
_cacheBitmap = CommonHelper.ScaleImageForSizedDisplay(resizedBitmap, currentWidth, currentHeight);
_cacheBitmap = CommonHelper.ScaleImageForSizedDisplay(resizedBitmap, currentWidth, currentHeight, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1732,9 +1732,10 @@ public static void Deflate(this Rectangle rect, Padding margins)
/// <param name="src"></param>
/// <param name="trgtWidth"></param>
/// <param name="trgtHeight"></param>
/// <param name="avoidPurple"></param>
/// <returns></returns>
/// <exception >thrown if targets are negative</exception>
public static Bitmap? ScaleImageForSizedDisplay(Image? src, float trgtWidth, float trgtHeight)
public static Bitmap? ScaleImageForSizedDisplay(Image? src, float trgtWidth, float trgtHeight, bool avoidPurple)
{
if (trgtWidth <= 1.0 || trgtHeight <= 1.0)
{
Expand All @@ -1748,9 +1749,9 @@ public static void Deflate(this Rectangle rect, Padding margins)
var newImage = new Bitmap((int)trgtWidth, (int)trgtHeight);
using Graphics gr = Graphics.FromImage(newImage);
gr.Clear(Color.Transparent);
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.SmoothingMode = SmoothingMode.AntiAlias;
// Got to be careful with this setting, otherwise "Purple" artifacts will be introduced !
gr.InterpolationMode = InterpolationMode.NearestNeighbor;
gr.InterpolationMode = avoidPurple ? InterpolationMode.NearestNeighbor : InterpolationMode.High;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
//var srcRect = new RectangleF(0.0f, 0.0f, src.Width, src.Height);
//var destRect = new RectangleF(0.0f, 0.0f, trgtWidth, trgtHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,9 @@ public override Size GetCheckBoxPreferredSize([DisallowNull] ViewLayoutContext c
}
else
{
return drawImage.Size;
Size drawImageSize = drawImage.Size;
float dpiFactor = context.Graphics.DpiY / 96f;
return new Size((int)(drawImageSize.Width * dpiFactor), (int)(drawImageSize.Height * dpiFactor));
}
}

Expand Down Expand Up @@ -2397,6 +2399,9 @@ public override void DrawCheckBox([DisallowNull] RenderContext context,
}
else
{
float dpiFactor = context.Graphics.DpiY / 96f;
drawImage = CommonHelper.ScaleImageForSizedDisplay(drawImage, drawImage.Width * dpiFactor,
drawImage.Height * dpiFactor, false)!;
// Find the offset to center the image
var xOffset = (displayRect.Width - drawImage.Width) / 2;
var yOffset = (displayRect.Height - drawImage.Height) / 2;
Expand Down Expand Up @@ -2437,7 +2442,9 @@ public override Size GetRadioButtonPreferredSize(ViewLayoutContext context,
}
else
{
return drawImage.Size;
Size drawImageSize = drawImage.Size;
float dpiFactor = context.Graphics.DpiY / 96f;
return new Size((int)(drawImageSize.Width * dpiFactor), (int)(drawImageSize.Height * dpiFactor));
}
}

Expand Down Expand Up @@ -2488,6 +2495,9 @@ public override void DrawRadioButton([DisallowNull] RenderContext context,
}
else
{
float dpiFactor = context.Graphics.DpiY / 96f;
drawImage = CommonHelper.ScaleImageForSizedDisplay(drawImage, drawImage.Width * dpiFactor,
drawImage.Height * dpiFactor, false)!;
// Find the offset to center the image
var xOffset = (displayRect.Width - drawImage.Width) / 2;
var yOffset = (displayRect.Height - drawImage.Height) / 2;
Expand Down Expand Up @@ -5771,7 +5781,7 @@ private static void AllocateImageSpace([DisallowNull] StandardContentMemento mem

// Resize image to fit display area
memento.Image = CommonHelper.ScaleImageForSizedDisplay(memento.Image, displayRect.Width * ratio,
displayRect.Height * ratio);
displayRect.Height * ratio, false);
}

if (memento.Image != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private static void ScaleButtonSpecImageType(KryptonPaletteButtonSpecTyped bst,
}
using var tmpBmp = new Bitmap(img);
tmpBmp.MakeTransparent(GlobalStaticValues.TRANSPARENCY_KEY_COLOR);
return CommonHelper.ScaleImageForSizedDisplay(tmpBmp, img.Width * scaleFactor.Width, img.Height * scaleFactor.Height);
return CommonHelper.ScaleImageForSizedDisplay(tmpBmp, img.Width * scaleFactor.Width, img.Height * scaleFactor.Height, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Image? Image
float dpiFactor = _getDpiFactor();
return (_image != null)
? CommonHelper.ScaleImageForSizedDisplay(_image, _image.Width * dpiFactor,
_image.Height * dpiFactor)
_image.Height * dpiFactor, false)
: null;
}
#endregion
Expand Down
9 changes: 8 additions & 1 deletion Source/Krypton Components/TestForm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ internal static class Program
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() =>
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
#if NET6_0_OR_GREATER
Application.SetHighDpiMode(HighDpiMode.SystemAware);
#endif
Application.Run(new StartScreen());
}
}
}
Loading

0 comments on commit 164ae6a

Please sign in to comment.