Skip to content

Commit

Permalink
- Make sure that the ration applied to the image, actually modifies t…
Browse files Browse the repository at this point in the history
…he image.

Ensure that the ratio is applied in the correct direction

#739
  • Loading branch information
Smurf-IV committed Jun 12, 2022
1 parent e81ed2f commit a9ef0f7
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 108 deletions.
1 change: 1 addition & 0 deletions Documents/Help/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## 2022-11-xx - Build 2211 - November 2022 <!--Possible August or September release?-->
* Implemented [#728](https://github.com/Krypton-Suite/Standard-Toolkit/issues/728), Bring MessageBox `States` inline with latest .Net 6
* Made enumeration `SchemeOfficeColors` public, so they can be used to make external themes
* Resolved [#739](https://github.com/Krypton-Suite/Standard-Toolkit/issues/739), KryptonButton - Image stretches with increased border rounding
* Resolved [#688](https://github.com/Krypton-Suite/Standard-Toolkit/issues/688), KryptonComboBox / KryptonNumericUpDown / KryptonDomainUpDown Anchor Sizing no as expected when anchored Top & Bottom
* Resolved [#722](https://github.com/Krypton-Suite/Standard-Toolkit/issues/722), KryptonRichTextBox disabled colour cannot be set
* Resolved [#662](https://github.com/Krypton-Suite/Standard-Toolkit/issues/662), Can not "Control / Set Disabled" Background Colour Of Comboboxes, in DropDown mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ public override IDisposable DrawBack(RenderContext context,
Debug.Assert(!context.Control.IsDisposed);

// Is there anything to actually draw?
if ((rect.Width <= 0)
if ((rect.Width <= 0)
|| (rect.Height <= 0)
)
{
Expand All @@ -869,7 +869,7 @@ public override IDisposable DrawBack(RenderContext context,

// The `RenderBefore` does not know about tracking - so check again
if ((state == PaletteState.Tracking)
&& (palette.GetBackDraw(state) != InheritBool.True)
&& (palette.GetBackDraw(state) != InheritBool.True)
)
{
state = PaletteState.Normal;
Expand Down Expand Up @@ -1108,7 +1108,7 @@ public override Size GetContentPreferredSize(ViewLayoutContext context,

// For the form level buttons we have to calculate the correct padding based on caption area
PaletteContentStyle contentStyle = palette.GetContentStyle();
if (contentStyle is PaletteContentStyle.ButtonForm
if (contentStyle is PaletteContentStyle.ButtonForm
or PaletteContentStyle.ButtonFormClose)
{
borderPadding = ContentPaddingForButtonForm(borderPadding, context, allocatedHeight);
Expand Down Expand Up @@ -2931,10 +2931,10 @@ public override void DrawRibbonContextArrow(PaletteRibbonShape shape,
}

context.Graphics.DrawLine(darkPen, displayRect.Left, displayRect.Top + 3, displayRect.Right, displayRect.Top + 3);
context.Graphics.DrawLine(darkPen, displayRect.Right-1, displayRect.Top + 4, displayRect.Left+displayRect.Width/2, displayRect.Bottom - 4);
context.Graphics.DrawLine(darkPen, displayRect.Left+displayRect.Width/2, displayRect.Bottom - 4, displayRect.Left, displayRect.Top + 3);
context.Graphics.DrawLine(lightPen, displayRect.Left+1, displayRect.Top + 5, displayRect.Left+displayRect.Width/2-1, displayRect.Bottom - 5);
context.Graphics.DrawLine(lightPen, displayRect.Left+displayRect.Width/2+1, displayRect.Bottom - 5, displayRect.Right-1, displayRect.Top + 5);
context.Graphics.DrawLine(darkPen, displayRect.Right - 1, displayRect.Top + 4, displayRect.Left + displayRect.Width / 2, displayRect.Bottom - 4);
context.Graphics.DrawLine(darkPen, displayRect.Left + displayRect.Width / 2, displayRect.Bottom - 4, displayRect.Left, displayRect.Top + 3);
context.Graphics.DrawLine(lightPen, displayRect.Left + 1, displayRect.Top + 5, displayRect.Left + displayRect.Width / 2 - 1, displayRect.Bottom - 5);
context.Graphics.DrawLine(lightPen, displayRect.Left + displayRect.Width / 2 + 1, displayRect.Bottom - 5, displayRect.Right - 1, displayRect.Top + 5);
}
}

Expand Down Expand Up @@ -5771,15 +5771,31 @@ 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)
|| (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);
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 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
136 changes: 41 additions & 95 deletions Source/Krypton Components/TestForm/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a9ef0f7

Please sign in to comment.