From fba824e6349a834b3598320ed6d1486c397878da Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 8 Dec 2019 15:31:23 +0300 Subject: [PATCH] Added random size option --- .../Drawings/DrawRandomImages.cs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/ShareX.ImageEffectsLib/Drawings/DrawRandomImages.cs b/ShareX.ImageEffectsLib/Drawings/DrawRandomImages.cs index cab10ee2c..4244f9529 100644 --- a/ShareX.ImageEffectsLib/Drawings/DrawRandomImages.cs +++ b/ShareX.ImageEffectsLib/Drawings/DrawRandomImages.cs @@ -54,6 +54,15 @@ public int ImageCount } } + [DefaultValue(false)] + public bool RandomSize { get; set; } + + [DefaultValue(64)] + public int RandomSizeMin { get; set; } + + [DefaultValue(128)] + public int RandomSizeMax { get; set; } + [DefaultValue(false)] public bool RandomRotate { get; set; } @@ -85,10 +94,22 @@ public override Image Apply(Image img) if (img2 != null) { - int widthOffset = img.Width - img2.Width - 1; - int heightOffset = img.Height - img2.Height - 1; - Rectangle rect = new Rectangle(MathHelpers.Random(Math.Min(0, widthOffset), Math.Max(0, widthOffset)), - MathHelpers.Random(Math.Min(0, heightOffset), Math.Max(0, heightOffset)), img2.Width, img2.Height); + int xOffset = img.Width - img2.Width - 1; + int yOffset = img.Height - img2.Height - 1; + int width, height; + + if (RandomSize) + { + width = height = MathHelpers.Random(Math.Min(RandomSizeMin, RandomSizeMax), Math.Max(RandomSizeMin, RandomSizeMax)); + } + else + { + width = img2.Width; + height = img2.Height; + } + + Rectangle rect = new Rectangle(MathHelpers.Random(Math.Min(0, xOffset), Math.Max(0, xOffset)), + MathHelpers.Random(Math.Min(0, yOffset), Math.Max(0, yOffset)), width, height); if (RandomRotate) {