Skip to content

Commit

Permalink
Merge pull request #1951 from Krypton-Suite/565-V85-GroupBox-Scaling
Browse files Browse the repository at this point in the history
- Use `DeviceDpi` to scale images
  • Loading branch information
PWagner1 authored Dec 16, 2024
2 parents f605484 + dc37ad4 commit 0baaca0
Show file tree
Hide file tree
Showing 29 changed files with 200 additions and 49 deletions.
2 changes: 2 additions & 0 deletions Documents/Help/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
=======

# 2025-02-01 - Build 2502 (Patch 5) - February 2025
* 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!
* Resolved [#1890](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1890), V85 codebase: Exception thrown for colouring a ribbon
* Resolved [#1905](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1905), `Sparkle` Themes have an issue with the Background
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected ButtonSpecNavFixed([DisallowNull] KryptonNavigator navigator,
Debug.Assert(navigator != null);

// Remember back reference to owning navigator.
Navigator = navigator;
Navigator = navigator!;

// Fix the type
ProtectedType = fixedStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public ButtonSpecNavRemap(PaletteBase? target,
{
Debug.Assert(buttonSpec != null);

_buttonSpec = buttonSpec;
_buttonSpec = buttonSpec!;
_remapTarget = remapTarget;
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public DragViewController([DisallowNull] ViewBase target)
MousePoint = CommonHelper.NullPoint;
AllowDragging = true;
_dragging = false;
Target = target;
Target = target!;
_lastClick = DateTime.Now.AddDays(-1);
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public virtual void Start([DisallowNull] IPaletteDragDrop paletteDragDrop,
Debug.Assert(pageDragEndData != null);
Debug.Assert(dragTargets != null);

PaletteDragDrop = paletteDragDrop;
PaletteDragDrop = paletteDragDrop!;
Renderer = renderer;
PageDragEndData = pageDragEndData;
DragTargets = dragTargets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PageToToolTipMapping([DisallowNull] KryptonPage page,
{
Debug.Assert(page != null);

_page = page;
_page = page!;
_mapImage = mapImage;
_mapText = mapText;
_mapExtraText = mapExtraText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ public abstract class HeaderGroupMappingBase : HeaderValuesBase
#endregion

#region Identity

/// <summary>
/// Initialize a new instance of the HeaderGroupMappingBase class.
/// </summary>
/// <param name="navigator">Reference to owning navigator instance.</param>
/// <param name="needPaint">Delegate for notifying paint requests.</param>
/// <param name="getDpiFactor"></param>
protected HeaderGroupMappingBase([DisallowNull] KryptonNavigator navigator,
NeedPaintHandler needPaint)
: base(needPaint)
NeedPaintHandler needPaint, GetDpiFactor getDpiFactor)
: base(needPaint, getDpiFactor)
{
Debug.Assert(navigator != null);

// Remember back reference to owning control
_navigator = navigator;

Expand All @@ -45,6 +46,7 @@ protected HeaderGroupMappingBase([DisallowNull] KryptonNavigator navigator,
_mapHeading = GetMapHeadingDefault();
_mapDescription = GetMapDescriptionDefault();
}

#endregion

#region Default Values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ public class HeaderGroupMappingPrimary : HeaderGroupMappingBase
#endregion

#region Identity

/// <summary>
/// Initialize a new instance of the HeaderGroupMappingPrimary class.
/// </summary>
/// <param name="navigator">Reference to owning navigator instance.</param>
/// <param name="needPaint">Delegate for notifying paint requests.</param>
/// <param name="getDpiFactor"></param>
public HeaderGroupMappingPrimary(KryptonNavigator navigator,
NeedPaintHandler needPaint)
: base(navigator, needPaint)
NeedPaintHandler needPaint,
GetDpiFactor getDpiFactor)
: base(navigator, needPaint, getDpiFactor)
{
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ public class HeaderGroupMappingSecondary : HeaderGroupMappingBase
#endregion

#region Identity

/// <summary>
/// Initialize a new instance of the HeaderGroupMappingSecondary class.
/// </summary>
/// <param name="navigator">Reference to owning navigator instance.</param>
/// <param name="needPaint">Delegate for notifying paint requests.</param>
/// <param name="getDpiFactor"></param>
public HeaderGroupMappingSecondary(KryptonNavigator navigator,
NeedPaintHandler needPaint)
: base(navigator, needPaint)
NeedPaintHandler needPaint,
GetDpiFactor getDpiFactor)
: base(navigator, needPaint, getDpiFactor)
{
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public NavigatorBar([DisallowNull] KryptonNavigator navigator,
Debug.Assert(navigator != null);

// Remember back reference
_navigator = navigator;
_navigator = navigator!;

// Store the provided paint notification delegate
NeedPaint = needPaint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#endregion

// ReSharper disable VirtualMemberCallInConstructor
using static Krypton.Toolkit.HeaderValuesBase;

namespace Krypton.Navigator
{
/// <summary>
Expand Down Expand Up @@ -59,9 +61,19 @@ public NavigatorHeader([DisallowNull] KryptonNavigator navigator,
_headerVisiblePrimary = true;
_headerVisibleSecondary = true;
_headerVisibleBar = true;
HeaderValuesPrimary = new HeaderGroupMappingPrimary(_navigator, needPaint);
HeaderValuesSecondary = new HeaderGroupMappingSecondary(_navigator, needPaint);
HeaderValuesPrimary = new HeaderGroupMappingPrimary(_navigator, needPaint, GetDpiFactor);
HeaderValuesSecondary = new HeaderGroupMappingSecondary(_navigator, needPaint, GetDpiFactor);
}

private float GetDpiFactor()
{
#if NET462
return PI.GetDpiForWindow(_navigator.Handle) / 96F;
#else
return _navigator.DeviceDpi / 96F;
#endif
}

#endregion

#region IsDefault
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
#endregion

using static Krypton.Toolkit.HeaderValuesBase;

namespace Krypton.Ribbon
{
/// <summary>
Expand Down Expand Up @@ -40,8 +42,19 @@ public abstract class KryptonRibbonGroupItem : Component,
/// Initialise a new instance of the KryptonRibbonGroupItem class.
/// </summary>
protected KryptonRibbonGroupItem() =>
// Do the Tooltip Magic
_toolTipValues = new ToolTipValues(null/*NeedPaintDelegate*/); // Must be replaced by appropriate call
// Do the Tooltip Magic
_toolTipValues = new ToolTipValues(null/*NeedPaintDelegate*/, GetDpiFactor); // Must be replaced by appropriate call

private float GetDpiFactor()
{
return (Ribbon != null)
#if NET462
? PI.GetDpiForWindow(Ribbon.Handle) / 96F
#else
? Ribbon.DeviceDpi / 96F
#endif
: 1.0f;
}

#endregion Identity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
#endregion

using static Krypton.Toolkit.HeaderValuesBase;

namespace Krypton.Ribbon
{
/// <summary>
Expand Down Expand Up @@ -537,12 +539,23 @@ private void CreateViewElements(PaletteRedirect? redirect)
NeedPaintDelegate);

// Create the manager for handling tooltips
ToolTipManager = new ToolTipManager(new ToolTipValues(null)); // use default, as each button "could" have different values ??!!??
ToolTipManager = new ToolTipManager(new ToolTipValues(null, GetDpiFactor)); // use default, as each button "could" have different values ??!!??
ToolTipManager.ShowToolTip += OnShowToolTip;
ToolTipManager.CancelToolTip += OnCancelToolTip;
ButtonSpecManager.ToolTipManager = ToolTipManager;
}

private float GetDpiFactor()
{
return (_visualPopupToolTip != null)
#if NET462
? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F
#else
? _visualPopupToolTip.DeviceDpi / 96F
#endif
: 1F;
}

private void SetupParentMonitoring()
{
// We have to know when the parent of the ribbon changes so we can then hook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected ButtonSpecRemapByContentBase(PaletteBase? target,
: base(target)
{
Debug.Assert(buttonSpec != null);
_buttonSpec = buttonSpec;
_buttonSpec = buttonSpec!;
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class KryptonContextMenuItemBase : Component, INotifyPropertyCha
#region Instance Fields

private bool _visible;
private ToolTipValues _toolTipValues = new ToolTipValues(null);
private ToolTipValues _toolTipValues;
private VisualPopupToolTip? _visualPopupToolTip;
private IContextMenuProvider _provider;
#endregion
Expand Down Expand Up @@ -49,11 +49,23 @@ public abstract class KryptonContextMenuItemBase : Component, INotifyPropertyCha
protected KryptonContextMenuItemBase()
{
_visible = true;
_toolTipValues = new ToolTipValues(null, GetDpiFactor);
ToolTipManager = new ToolTipManager(_toolTipValues);
ToolTipManager.ShowToolTip += OnShowToolTip;
ToolTipManager.CancelToolTip += OnCancelToolTip;
}

private float GetDpiFactor()
{
return (_visualPopupToolTip != null)
#if NET462
? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F
#else
? _visualPopupToolTip.DeviceDpi / 96F
#endif
: 1F;
}

#endregion

#region Public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public KryptonForm()
OnButtonManagerNeedPaint!);

// Create the manager for handling tooltips
ToolTipManager = new ToolTipManager(new ToolTipValues(null)); // use default, as each button "could" have different values ??!!??
ToolTipManager = new ToolTipManager(new ToolTipValues(null, GetDpiFactor)); // use default, as each button "could" have different values ??!!??
ToolTipManager.ShowToolTip += OnShowToolTip;
ToolTipManager.CancelToolTip += OnCancelToolTip;
_buttonManager.ToolTipManager = ToolTipManager;
Expand All @@ -201,6 +201,17 @@ public KryptonForm()
#pragma warning restore CS0618
}

private float GetDpiFactor()
{
return (_visualPopupToolTip != null)
#if NET462
? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F
#else
? _visualPopupToolTip.DeviceDpi / 96F
#endif
: 1F;
}

/// <summary>
/// Releases all resources used by the Control.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public KryptonGroupBox()
_captionVisible = true;

// Create storage objects
Values = new CaptionValues(NeedPaintDelegate);
Values = new CaptionValues(NeedPaintDelegate, GetDpiFactor);
Values.TextChanged += OnValuesTextChanged;

// Create the palette storage
Expand All @@ -67,11 +67,9 @@ public KryptonGroupBox()
// Create the internal panel used for containing content
Panel = new KryptonGroupBoxPanel(this, StateCommon, StateDisabled, StateNormal, OnGroupPanelPaint!)
{

// Make sure the panel back style always mimics our back style
PanelBackStyle = PaletteBackStyle.ControlGroupBox
};

_drawContent = new ViewDrawContent(StateNormal.Content, Values, VisualOrientation.Top);

// Create view for the control border and background
Expand Down Expand Up @@ -108,6 +106,17 @@ public KryptonGroupBox()
_cornerRoundingRadius = GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE;
}

private float GetDpiFactor()
{
return (Panel != null)
#if NET462
? PI.GetDpiForWindow(Panel.Handle) / 96F
#else
? Panel.DeviceDpi / 96F
#endif
: 1f;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public KryptonHeader()
AllowButtonSpecToolTipPriority = false;

// Create storage objects
Values = new HeaderValues(NeedPaintDelegate);
Values = new HeaderValues(NeedPaintDelegate, GetDpiFactor);
Values.TextChanged += OnHeaderTextChanged;
ButtonSpecs = new HeaderButtonSpecCollection(this);

Expand Down Expand Up @@ -110,6 +110,15 @@ public KryptonHeader()
_cornerRoundingRadius = GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE;
}

private float GetDpiFactor()
{
#if NET462
return PI.GetDpiForWindow(Handle) / 96F;
#else
return DeviceDpi / 96F;
#endif
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public KryptonHeaderGroup()
_visibleSecondary = true;

// Create storage objects
ValuesPrimary = new HeaderGroupValuesPrimary(NeedPaintDelegate);
ValuesPrimary = new HeaderGroupValuesPrimary(NeedPaintDelegate, GetDpiFactor);
ValuesPrimary.TextChanged += OnHeaderGroupTextChanged;
ValuesSecondary = new HeaderGroupValuesSecondary(NeedPaintDelegate);
ValuesSecondary = new HeaderGroupValuesSecondary(NeedPaintDelegate, GetDpiFactor);
ButtonSpecs = new HeaderGroupButtonSpecCollection(this);

// We need to monitor button spec click events
Expand Down Expand Up @@ -208,6 +208,17 @@ public KryptonHeaderGroup()
_headerSecondaryCornerRoundingRadius = GlobalStaticValues.SECONDARY_CORNER_ROUNDING_VALUE;
}

private float GetDpiFactor()
{
return (Panel != null)
#if NET462
? PI.GetDpiForWindow(Panel.Handle) / 96F
#else
? Panel.DeviceDpi / 96F
#endif
: 1f;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
Expand Down
Loading

0 comments on commit 0baaca0

Please sign in to comment.