mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Added min/max range for random rotate
This commit is contained in:
parent
fba824e634
commit
32dd3cc77d
1 changed files with 43 additions and 32 deletions
|
@ -66,6 +66,12 @@ public int ImageCount
|
|||
[DefaultValue(false)]
|
||||
public bool RandomRotate { get; set; }
|
||||
|
||||
[DefaultValue(0)]
|
||||
public int RandomRotateMin { get; set; }
|
||||
|
||||
[DefaultValue(360)]
|
||||
public int RandomRotateMax { get; set; }
|
||||
|
||||
public DrawRandomImages()
|
||||
{
|
||||
this.ApplyDefaultPropertyValues();
|
||||
|
@ -94,38 +100,7 @@ public override Image Apply(Image img)
|
|||
|
||||
if (img2 != null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
float moveX = rect.X + (rect.Width / 2f);
|
||||
float moveY = rect.Y + (rect.Height / 2f);
|
||||
g.TranslateTransform(moveX, moveY);
|
||||
g.RotateTransform(MathHelpers.Random(0, 360));
|
||||
g.TranslateTransform(-moveX, -moveY);
|
||||
}
|
||||
|
||||
g.DrawImage(img2, rect);
|
||||
|
||||
if (RandomRotate)
|
||||
{
|
||||
g.ResetTransform();
|
||||
}
|
||||
DrawImage(img, img2, g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,5 +109,41 @@ public override Image Apply(Image img)
|
|||
|
||||
return img;
|
||||
}
|
||||
|
||||
private void DrawImage(Image img, Image img2, Graphics g)
|
||||
{
|
||||
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)
|
||||
{
|
||||
float moveX = rect.X + (rect.Width / 2f);
|
||||
float moveY = rect.Y + (rect.Height / 2f);
|
||||
g.TranslateTransform(moveX, moveY);
|
||||
g.RotateTransform(MathHelpers.Random(Math.Min(RandomRotateMin, RandomRotateMax), Math.Max(RandomRotateMin, RandomRotateMax)));
|
||||
g.TranslateTransform(-moveX, -moveY);
|
||||
}
|
||||
|
||||
g.DrawImage(img2, rect);
|
||||
|
||||
if (RandomRotate)
|
||||
{
|
||||
g.ResetTransform();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue