-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasterEggAboutAnimation.cs
160 lines (132 loc) · 4.94 KB
/
EasterEggAboutAnimation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2019 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
{
public Canvas Canvas { get; private set; }
public bool IsPaused { get; set; }
public Size Size { get; set; } = new Size(200, 200);
public int Step { get; set; } = 10;
public int MinStep { get; set; } = 3;
public int MaxStep { get; set; } = 35;
public int Speed { get; set; } = 1;
public Color Color { get; set; } = new HSB(0.0, 1.0, 0.9);
public int ClickCount { get; private set; }
private EasterEggBounce easterEggBounce;
private int direction;
public EasterEggAboutAnimation(Canvas canvas, Form form)
{
Canvas = canvas;
Canvas.MouseDown += Canvas_MouseDown;
Canvas.Draw += Canvas_Draw;
easterEggBounce = new EasterEggBounce(form);
}
public void Start()
{
direction = Speed;
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();
int halfWidth = Size.Width / 2;
int halfHeight = Size.Height / 2;
using (Matrix m = new Matrix())
{
m.RotateAt(45, new PointF(halfWidth, halfHeight));
g.Transform = m;
}
using (Pen pen = new Pen(Color, 2))
{
for (int i = 0; i <= halfWidth; i += Step)
{
g.DrawLine(pen, i, halfHeight, halfWidth, halfHeight - i); // Left top
g.DrawLine(pen, halfWidth, i, halfWidth + i, halfHeight); // Right top
g.DrawLine(pen, Size.Width - i, halfHeight, halfWidth, halfHeight + i); // Right bottom
g.DrawLine(pen, halfWidth, Size.Height - i, halfWidth - i, halfHeight); // 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();
}
}
}
}