Browse Source

refine animation

tags/3.2
clowwindy 10 years ago
parent
commit
a231cba73b
1 changed files with 12 additions and 10 deletions
  1. +12
    -10
      shadowsocks-csharp/View/QRCodeSplashForm.cs

+ 12
- 10
shadowsocks-csharp/View/QRCodeSplashForm.cs View File

@@ -7,6 +7,7 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Shadowsocks.View namespace Shadowsocks.View
@@ -20,7 +21,7 @@ namespace Shadowsocks.View
this.Load += QRCodeSplashForm_Load; this.Load += QRCodeSplashForm_Load;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(284, 262);
this.ClientSize = new System.Drawing.Size(1, 1);
this.ControlBox = false; this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false; this.MaximizeBox = false;
@@ -31,14 +32,14 @@ namespace Shadowsocks.View
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.TopMost = true; this.TopMost = true;
} }
private Timer timer; private Timer timer;
private int animationStep;
private int flashStep; private int flashStep;
private static int ANIMATION_STEPS = 30;
private static double ANIMATION_TIME = 0.3;
private static double FPS = 1.0 / 15 * 1000; // System.Windows.Forms.Timer resolution is 15ms
private static double ANIMATION_TIME = 0.5;
private static int ANIMATION_STEPS = (int)(ANIMATION_TIME * FPS);
Stopwatch sw;
int x; int x;
int y; int y;
int w; int w;
@@ -52,12 +53,12 @@ namespace Shadowsocks.View
{ {
SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent; this.BackColor = Color.Transparent;
animationStep = 0;
flashStep = 0; flashStep = 0;
x = 0; x = 0;
y = 0; y = 0;
w = Width; w = Width;
h = Height; h = Height;
sw = Stopwatch.StartNew();
timer = new Timer(); timer = new Timer();
timer.Interval = (int)(ANIMATION_TIME * 1000 / ANIMATION_STEPS); timer.Interval = (int)(ANIMATION_TIME * 1000 / ANIMATION_STEPS);
timer.Tick += timer_Tick; timer.Tick += timer_Tick;
@@ -80,10 +81,9 @@ namespace Shadowsocks.View
void timer_Tick(object sender, EventArgs e) void timer_Tick(object sender, EventArgs e)
{ {
if (animationStep < ANIMATION_STEPS)
double percent = (double)sw.ElapsedMilliseconds / 1000.0 / (double)ANIMATION_TIME;
if (percent < 1)
{ {
animationStep++;
double percent = (double)animationStep / (double)ANIMATION_STEPS;
// ease out // ease out
percent = 1 - Math.Pow((1 - percent), 4); percent = 1 - Math.Pow((1 - percent), 4);
x = (int)(TargetRect.X * percent); x = (int)(TargetRect.X * percent);
@@ -101,14 +101,15 @@ namespace Shadowsocks.View
} }
else else
{ {
timer.Interval = 50;
if (flashStep == 0) if (flashStep == 0)
{ {
timer.Interval = 100;
g.Clear(Color.Transparent); g.Clear(Color.Transparent);
SetBitmap(bitmap); SetBitmap(bitmap);
} }
else if (flashStep == 1) else if (flashStep == 1)
{ {
timer.Interval = 50;
g.FillRectangle(brush, x, y, w, h); g.FillRectangle(brush, x, y, w, h);
g.DrawRectangle(pen, x, y, w, h); g.DrawRectangle(pen, x, y, w, h);
SetBitmap(bitmap); SetBitmap(bitmap);
@@ -137,6 +138,7 @@ namespace Shadowsocks.View
} }
else else
{ {
sw.Stop();
timer.Stop(); timer.Stop();
pen.Dispose(); pen.Dispose();
brush.Dispose(); brush.Dispose();


Loading…
Cancel
Save