mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Added NoOverlap option
This commit is contained in:
parent
b5fc7103e4
commit
31bc399444
1 changed files with 24 additions and 2 deletions
|
@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
|
@ -83,6 +84,11 @@ public int ImageCount
|
|||
[DefaultValue(100)]
|
||||
public int RandomOpacityMax { get; set; }
|
||||
|
||||
[DefaultValue(false)]
|
||||
public bool NoOverlap { get; set; }
|
||||
|
||||
private List<Rectangle> imageRectangles = new List<Rectangle>();
|
||||
|
||||
public DrawRandomImages()
|
||||
{
|
||||
this.ApplyDefaultPropertyValues();
|
||||
|
@ -98,6 +104,8 @@ public override Image Apply(Image img)
|
|||
|
||||
if (files.Length > 0)
|
||||
{
|
||||
imageRectangles.Clear();
|
||||
|
||||
using (Graphics g = Graphics.FromImage(img))
|
||||
using (ImageFilesCache imageCache = new ImageFilesCache())
|
||||
{
|
||||
|
@ -143,8 +151,22 @@ private void DrawImage(Image img, Image img2, Graphics g)
|
|||
int xOffset = img.Width - width - 1;
|
||||
int yOffset = img.Height - height - 1;
|
||||
|
||||
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);
|
||||
Rectangle rect;
|
||||
int attemptCount = 0;
|
||||
|
||||
do
|
||||
{
|
||||
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);
|
||||
|
||||
attemptCount++;
|
||||
if (attemptCount >= 1000)
|
||||
{
|
||||
return;
|
||||
}
|
||||
} while (NoOverlap && imageRectangles.Any(x => x.IntersectsWith(rect)));
|
||||
|
||||
imageRectangles.Add(rect);
|
||||
|
||||
if (RandomAngle)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue