Move easter egg codes outside of about form

This commit is contained in:
Jaex 2018-12-24 22:06:39 +03:00
parent 1d4ac87748
commit 5aefb5cf4d
5 changed files with 174 additions and 113 deletions

View file

@ -0,0 +1,160 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2018 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace ShareX
{
public class EasterEggAboutAnimation : IDisposable
{
private const int w = 200;
private const int h = w;
private const int mX = w / 2;
private const int mY = h / 2;
private const int minStep = 3;
private const int maxStep = 35;
private const int speed = 1;
public Canvas Canvas { get; private set; }
public bool IsPaused { get; set; }
public int Step { get; set; } = 10;
public int Direction { get; set; } = speed;
public Color Color { get; set; } = new HSB(0d, 1d, 0.9d);
public int ClickCount { get; private set; }
private EasterEggBounce easterEggBounce;
public EasterEggAboutAnimation(Canvas canvas, Form form)
{
Canvas = canvas;
Canvas.MouseDown += Canvas_MouseDown;
Canvas.Draw += Canvas_Draw;
easterEggBounce = new EasterEggBounce(form);
}
public void Start()
{
Canvas.Start(50);
}
private void Canvas_MouseDown(object sender, MouseEventArgs e)
{
IsPaused = !IsPaused;
if (!easterEggBounce.IsWorking)
{
ClickCount++;
if (ClickCount >= 10)
{
easterEggBounce.ApplyGravity = e.Button == MouseButtons.Left;
easterEggBounce.Start();
}
}
else
{
easterEggBounce.Stop();
}
}
private void Canvas_Draw(Graphics g)
{
g.SetHighQuality();
using (Matrix m = new Matrix())
{
m.RotateAt(45, new PointF(mX, mY));
g.Transform = m;
}
using (Pen pen = new Pen(Color, 2))
{
for (int i = 0; i <= mX; i += Step)
{
g.DrawLine(pen, i, mY, mX, mY - i); // Left top
g.DrawLine(pen, mX, i, mX + i, mY); // Right top
g.DrawLine(pen, w - i, mY, mX, mY + i); // Right bottom
g.DrawLine(pen, mX, h - i, mX - i, mY); // Left bottom
/*
g.DrawLine(pen, i, mY, mX, mY - i); // Left top
g.DrawLine(pen, w - i, mY, mX, mY - i); // Right top
g.DrawLine(pen, w - i, mY, mX, mY + i); // Right bottom
g.DrawLine(pen, i, mY, mX, mY + i); // Left bottom
*/
/*
g.DrawLine(pen, mX, i, i, mY); // Left top
g.DrawLine(pen, mX, i, w - i, mY); // Right top
g.DrawLine(pen, mX, h - i, w - i, mY); // Right bottom
g.DrawLine(pen, mX, h - i, i, mY); // Left bottom
*/
}
//g.DrawLine(pen, mX, 0, mX, h);
}
if (!IsPaused)
{
if (Step + speed > maxStep)
{
Direction = -speed;
}
else if (Step - speed < minStep)
{
Direction = speed;
}
Step += Direction;
HSB hsb = Color;
if (hsb.Hue >= 1)
{
hsb.Hue = 0;
}
else
{
hsb.Hue += 0.01;
}
Color = hsb;
}
}
public void Dispose()
{
if (easterEggBounce != null)
{
easterEggBounce.Dispose();
}
}
}
}

View file

@ -18,7 +18,7 @@ protected override void Dispose(bool disposing)
components.Dispose();
}
if (easterEggBounce != null) easterEggBounce.Dispose();
if (easterEgg != null) easterEgg.Dispose();
base.Dispose(disposing);
}
@ -173,8 +173,6 @@ private void InitializeComponent()
resources.ApplyResources(this.cLogo, "cLogo");
this.cLogo.Interval = 100;
this.cLogo.Name = "cLogo";
this.cLogo.Draw += new ShareX.HelpersLib.Canvas.DrawEventHandler(this.cLogo_Draw);
this.cLogo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cLogo_MouseDown);
//
// lblBuild
//

View file

@ -26,15 +26,13 @@ You should have received a copy of the GNU General Public License
using ShareX.HelpersLib;
using ShareX.Properties;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace ShareX
{
public partial class AboutForm : Form
{
private EasterEggBounce easterEggBounce;
private EasterEggAboutAnimation easterEgg;
public AboutForm()
{
@ -119,7 +117,7 @@ public AboutForm()
Copyright (c) 2007-2018 ShareX Team";
easterEggBounce = new EasterEggBounce(this);
easterEgg = new EasterEggAboutAnimation(cLogo, this);
}
private void AboutForm_Shown(object sender, EventArgs e)
@ -129,7 +127,7 @@ private void AboutForm_Shown(object sender, EventArgs e)
private void pbLogo_MouseDown(object sender, MouseEventArgs e)
{
cLogo.Start(50);
easterEgg.Start();
pbLogo.Visible = false;
}
@ -167,107 +165,5 @@ private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
#region Animation
private const int w = 200;
private const int h = w;
private const int mX = w / 2;
private const int mY = h / 2;
private const int minStep = 3;
private const int maxStep = 35;
private const int speed = 1;
private int step = 10;
private int direction = speed;
private Color lineColor = new HSB(0d, 1d, 0.9d);
private bool isPaused;
private int clickCount;
private void cLogo_Draw(Graphics g)
{
g.SetHighQuality();
using (Matrix m = new Matrix())
{
m.RotateAt(45, new PointF(mX, mY));
g.Transform = m;
}
using (Pen pen = new Pen(lineColor, 2))
{
for (int i = 0; i <= mX; i += step)
{
g.DrawLine(pen, i, mY, mX, mY - i); // Left top
g.DrawLine(pen, mX, i, mX + i, mY); // Right top
g.DrawLine(pen, w - i, mY, mX, mY + i); // Right bottom
g.DrawLine(pen, mX, h - i, mX - i, mY); // Left bottom
/*
g.DrawLine(pen, i, mY, mX, mY - i); // Left top
g.DrawLine(pen, w - i, mY, mX, mY - i); // Right top
g.DrawLine(pen, w - i, mY, mX, mY + i); // Right bottom
g.DrawLine(pen, i, mY, mX, mY + i); // Left bottom
*/
/*
g.DrawLine(pen, mX, i, i, mY); // Left top
g.DrawLine(pen, mX, i, w - i, mY); // Right top
g.DrawLine(pen, mX, h - i, w - i, mY); // Right bottom
g.DrawLine(pen, mX, h - i, i, mY); // Left bottom
*/
}
//g.DrawLine(pen, mX, 0, mX, h);
}
if (!isPaused)
{
if (step + speed > maxStep)
{
direction = -speed;
}
else if (step - speed < minStep)
{
direction = speed;
}
step += direction;
HSB hsb = lineColor;
if (hsb.Hue >= 1)
{
hsb.Hue = 0;
}
else
{
hsb.Hue += 0.01;
}
lineColor = hsb;
}
}
private void cLogo_MouseDown(object sender, MouseEventArgs e)
{
if (!easterEggBounce.IsWorking)
{
isPaused = !isPaused;
clickCount++;
if (clickCount >= 10)
{
easterEggBounce.ApplyGravity = e.Button == MouseButtons.Left;
easterEggBounce.Start();
}
}
else
{
easterEggBounce.Stop();
}
}
#endregion Animation
}
}

View file

@ -219,6 +219,9 @@
<data name="rtbCredits.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
</data>
<data name="rtbCredits.Text" xml:space="preserve">
<value />
</data>
<data name="rtbCredits.WordWrap" type="System.Boolean, mscorlib">
<value>False</value>
</data>
@ -243,6 +246,9 @@
<data name="rtbShareXInfo.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
</data>
<data name="rtbShareXInfo.Text" xml:space="preserve">
<value />
</data>
<data name="&gt;&gt;rtbShareXInfo.Name" xml:space="preserve">
<value>rtbShareXInfo</value>
</data>
@ -523,7 +529,7 @@
<value>uclUpdate</value>
</data>
<data name="&gt;&gt;uclUpdate.Type" xml:space="preserve">
<value>ShareX.HelpersLib.UpdateCheckerLabel, ShareX.HelpersLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</value>
<value>ShareX.HelpersLib.UpdateCheckerLabel, ShareX.HelpersLib, Version=12.4.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;uclUpdate.Parent" xml:space="preserve">
<value>$this</value>
@ -547,7 +553,7 @@
<value>cLogo</value>
</data>
<data name="&gt;&gt;cLogo.Type" xml:space="preserve">
<value>ShareX.HelpersLib.Canvas, ShareX.HelpersLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</value>
<value>ShareX.HelpersLib.Canvas, ShareX.HelpersLib, Version=12.4.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;cLogo.Parent" xml:space="preserve">
<value>$this</value>
@ -572,7 +578,7 @@
</data>
<data name="lblBuild.Text" xml:space="preserve">
<value>Build</value>
<comment>@Invariant</comment></data>
</data>
<data name="lblBuild.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>

View file

@ -164,6 +164,7 @@
<Compile Include="Controls\NewsListControl.Designer.cs">
<DependentUpon>NewsListControl.cs</DependentUpon>
</Compile>
<Compile Include="EasterEggAboutAnimation.cs" />
<Compile Include="EasterEggBounce.cs" />
<Compile Include="Forms\TextUploadForm.cs">
<SubType>Form</SubType>