mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Added DVD logo type easter egg
This commit is contained in:
parent
efc67df1e3
commit
1d4ac87748
3 changed files with 39 additions and 17 deletions
|
@ -66,6 +66,11 @@ public static int Random(int min, int max)
|
|||
}
|
||||
}
|
||||
|
||||
public static int RandomPick(params int[] nums)
|
||||
{
|
||||
return nums[Random(nums.Length - 1)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random number between 0 and <c>max</c> (inclusive) generated with a cryptographic PRNG.
|
||||
/// </summary>
|
||||
|
|
|
@ -35,22 +35,21 @@ public class EasterEggBounce : IDisposable
|
|||
public Form Form { get; private set; }
|
||||
public bool IsWorking { get; private set; }
|
||||
public int Speed { get; set; } = 20;
|
||||
public bool ApplyGravity { get; set; } = true;
|
||||
public int GravityPower { get; set; } = 3;
|
||||
public int BouncePower { get; set; } = 50;
|
||||
|
||||
private Rectangle screenRectangle;
|
||||
private Timer bounceTimer;
|
||||
private Timer timer;
|
||||
private Point velocity;
|
||||
|
||||
public EasterEggBounce(Form form)
|
||||
{
|
||||
Form = form;
|
||||
|
||||
bounceTimer = new Timer();
|
||||
bounceTimer.Interval = 20;
|
||||
bounceTimer.Tick += bounceTimer_Tick;
|
||||
|
||||
velocity = new Point(Speed, GravityPower);
|
||||
timer = new Timer();
|
||||
timer.Interval = 20;
|
||||
timer.Tick += bounceTimer_Tick;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
|
@ -60,7 +59,8 @@ public void Start()
|
|||
IsWorking = true;
|
||||
|
||||
screenRectangle = CaptureHelpers.GetScreenWorkingArea();
|
||||
bounceTimer.Start();
|
||||
velocity = new Point(MathHelpers.RandomPick(-Speed, Speed), ApplyGravity ? GravityPower : MathHelpers.RandomPick(-Speed, Speed));
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,9 @@ public void Stop()
|
|||
{
|
||||
if (IsWorking)
|
||||
{
|
||||
if (bounceTimer != null)
|
||||
if (timer != null)
|
||||
{
|
||||
bounceTimer.Stop();
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
IsWorking = false;
|
||||
|
@ -82,7 +82,7 @@ private void bounceTimer_Tick(object sender, EventArgs e)
|
|||
if (Form != null && !Form.IsDisposed)
|
||||
{
|
||||
int x = Form.Left + velocity.X;
|
||||
int windowRight = screenRectangle.X + screenRectangle.Width - 1 - Form.Width;
|
||||
int windowRight = screenRectangle.X + screenRectangle.Width - Form.Width - 1;
|
||||
|
||||
if (x <= screenRectangle.X)
|
||||
{
|
||||
|
@ -96,16 +96,32 @@ private void bounceTimer_Tick(object sender, EventArgs e)
|
|||
}
|
||||
|
||||
int y = Form.Top + velocity.Y;
|
||||
int windowBottom = screenRectangle.Y + screenRectangle.Height - 1 - Form.Height;
|
||||
int windowBottom = screenRectangle.Y + screenRectangle.Height - Form.Height - 1;
|
||||
|
||||
if (y >= windowBottom)
|
||||
if (ApplyGravity)
|
||||
{
|
||||
y = windowBottom;
|
||||
velocity.Y = -BouncePower.RandomAdd(-10, 10);
|
||||
if (y >= windowBottom)
|
||||
{
|
||||
y = windowBottom;
|
||||
velocity.Y = -BouncePower.RandomAdd(-10, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.Y += GravityPower;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.Y += GravityPower;
|
||||
if (y <= screenRectangle.Y)
|
||||
{
|
||||
y = screenRectangle.Y;
|
||||
velocity.Y = Speed;
|
||||
}
|
||||
else if (y >= windowBottom)
|
||||
{
|
||||
y = windowBottom;
|
||||
velocity.Y = -Speed;
|
||||
}
|
||||
}
|
||||
|
||||
Form.Location = new Point(x, y);
|
||||
|
@ -116,9 +132,9 @@ public void Dispose()
|
|||
{
|
||||
Stop();
|
||||
|
||||
if (bounceTimer != null)
|
||||
if (timer != null)
|
||||
{
|
||||
bounceTimer.Dispose();
|
||||
timer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,6 +258,7 @@ private void cLogo_MouseDown(object sender, MouseEventArgs e)
|
|||
|
||||
if (clickCount >= 10)
|
||||
{
|
||||
easterEggBounce.ApplyGravity = e.Button == MouseButtons.Left;
|
||||
easterEggBounce.Start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue