-
Notifications
You must be signed in to change notification settings - Fork 10
/
Animated.cs
113 lines (105 loc) · 3.65 KB
/
Animated.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
using System;
using System.Collections.Generic;
using System.Text;
namespace gep
{
abstract class Animated
{
protected abstract bool IsSelected();
protected abstract void Redraw();
protected abstract bool IsHovered();
DateTime animation_start_time = DateTime.MinValue;
AnimationDirection animation_dir = AnimationDirection.None;
protected int animation_state = 0;
public bool OnMouseOver(DateTime t) //true if must be added to animations list
{
if (IsSelected()) return false;
switch (animation_dir)
{
case AnimationDirection.None:
animation_dir = AnimationDirection.Up;
animation_state = 0;
animation_start_time = t;
break;
case AnimationDirection.Up:
break;
case AnimationDirection.Stay:
break;
case AnimationDirection.Down:
animation_dir = AnimationDirection.Up;
animation_start_time = t;
break;
}
return true;
}
public bool Animate(DateTime t) // true if keep in animations list
{
if (IsSelected())
{
animation_state = 0;
animation_dir = AnimationDirection.None;
return false;
}
double anim_dur = 0.2; //seconds
bool redraw = false;
bool keep_anim = false;
double dt = Math.Max((t - animation_start_time).TotalSeconds, 0.0);
switch (animation_dir)
{
case AnimationDirection.None:
keep_anim = false;
break;
case AnimationDirection.Up:
if (dt <= anim_dur)
{
animation_state = (int)(dt / anim_dur * 100);
keep_anim = true;
redraw = true;
}
else
{
animation_state = 100;
animation_dir = AnimationDirection.Stay;
keep_anim = true;
redraw = true;
}
break;
case AnimationDirection.Stay:
if (IsHovered())
{
animation_state = 100;
keep_anim = true;
}
else
{
animation_dir = AnimationDirection.Down;
animation_start_time = t;
keep_anim = true;
}
break;
case AnimationDirection.Down:
if (dt <= anim_dur)
{
animation_state = 100 - (int)(dt / anim_dur * 100);
keep_anim = true;
redraw = true;
}
else
{
animation_state = 0;
animation_dir = AnimationDirection.None;
keep_anim = false;
redraw = true;
}
break;
}
if (redraw)
Redraw();
return keep_anim;
}
}
enum AnimationDirection
{
None, Up, Stay, Down
}
}