|
1 | 1 | using System; |
2 | 2 | using System.Drawing; |
3 | 3 | using System.Drawing.Drawing2D; |
| 4 | +using Aurora.Utils; |
4 | 5 |
|
5 | 6 | namespace Aurora.EffectsEngine.Animations |
6 | 7 | { |
7 | | - public class AnimationEllipse : AnimationFrame |
| 8 | + public class AnimationEllipse : AnimationCircle |
8 | 9 | { |
9 | 10 | [Newtonsoft.Json.JsonProperty] |
10 | | - private float _radius_x = 0.0f; |
| 11 | + private float _radius_x; |
11 | 12 | [Newtonsoft.Json.JsonProperty] |
12 | | - private float _radius_y = 0.0f; |
13 | | - [Newtonsoft.Json.JsonProperty] |
14 | | - private PointF _center = new PointF(); |
15 | | - |
16 | | - public float RadiusHorizontal { get { return _radius_x; } } |
17 | | - public float RadiusVertical { get { return _radius_y; } } |
18 | | - public PointF Center { get { return _center; } } |
19 | | - |
20 | | - |
21 | | - public AnimationFrame SetRadiusHorizontal(float radius) |
22 | | - { |
23 | | - _radius_x = radius; |
24 | | - _dimension = new RectangleF(_center.X - _radius_x, _center.Y - _radius_y, 2.0f * _radius_x, 2.0f * _radius_y); |
25 | | - _invalidated = true; |
26 | | - |
27 | | - return this; |
28 | | - } |
29 | | - |
30 | | - public AnimationFrame SetRadiusVertical(float radius) |
31 | | - { |
32 | | - _radius_y = radius; |
33 | | - _dimension = new RectangleF(_center.X - _radius_x, _center.Y - _radius_y, 2.0f * _radius_x, 2.0f * _radius_y); |
34 | | - _invalidated = true; |
35 | | - |
36 | | - return this; |
37 | | - } |
38 | | - |
39 | | - public AnimationFrame SetCenter(PointF center) |
40 | | - { |
41 | | - _center = center; |
42 | | - _dimension = new RectangleF(_center.X - _radius_x, _center.Y - _radius_y, 2.0f * _radius_x, 2.0f * _radius_y); |
43 | | - _invalidated = true; |
44 | | - |
45 | | - return this; |
46 | | - } |
| 13 | + private float _radius_y; |
47 | 14 |
|
48 | 15 | public AnimationEllipse() |
49 | 16 | { |
50 | 17 | _radius_x = 0; |
51 | 18 | _radius_y = 0; |
52 | | - _center = new PointF(0, 0); |
53 | | - _dimension = new RectangleF(_center.X - _radius_x, _center.Y - _radius_y, 2.0f * _radius_x, 2.0f * _radius_y); |
54 | | - _color = Utils.ColorUtils.GenerateRandomColor(); |
| 19 | + _dimension = new RectangleF(- _radius_x, - _radius_y, 2.0f * _radius_x, 2.0f * _radius_y); |
| 20 | + _color = ColorUtils.GenerateRandomColor(); |
55 | 21 | _width = 1; |
56 | 22 | _duration = 0.0f; |
57 | 23 | } |
58 | 24 |
|
59 | | - public AnimationEllipse(AnimationFrame frame, float radiusX, float radiusY) : base(frame) |
| 25 | + public AnimationEllipse(AnimationFrame frame, float radiusX, float radiusY) : base(frame, radiusX) |
60 | 26 | { |
61 | 27 | _radius_x = radiusX; |
62 | 28 | _radius_y = radiusY; |
63 | | - _center = new PointF(_dimension.X + _radius_x, _dimension.Y + _radius_y); |
64 | 29 | } |
65 | 30 |
|
66 | 31 | public AnimationEllipse(AnimationEllipse animationEllipse) : base(animationEllipse) |
67 | 32 | { |
68 | 33 | _radius_x = animationEllipse._radius_x; |
69 | 34 | _radius_y = animationEllipse._radius_y; |
70 | | - _center = animationEllipse._center; |
71 | 35 | } |
72 | 36 |
|
73 | 37 | public AnimationEllipse(Rectangle dimension, Color color, int width = 1, float duration = 0.0f) : base(dimension, color, width, duration) |
74 | 38 | { |
75 | 39 | _radius_x = dimension.Width / 2.0f; |
76 | 40 | _radius_y = dimension.Height / 2.0f; |
77 | | - _center = new PointF(dimension.X + _radius_x, dimension.Y + _radius_y); |
78 | 41 | } |
79 | 42 |
|
80 | 43 | public AnimationEllipse(RectangleF dimension, Color color, int width = 1, float duration = 0.0f) : base(dimension, color, width, duration) |
81 | 44 | { |
82 | 45 | _radius_x = dimension.Width / 2.0f; |
83 | 46 | _radius_y = dimension.Height / 2.0f; |
84 | | - _center = new PointF(dimension.X + _radius_x, dimension.Y + _radius_y); |
85 | 47 | } |
86 | 48 |
|
87 | | - public AnimationEllipse(PointF center, float x_axis, float y_axis, Color color, int width = 1, float duration = 0.0f) |
| 49 | + public AnimationEllipse(PointF center, float xAxis, float yAxis, Color color, int width = 1, float duration = 0.0f) |
88 | 50 | { |
89 | | - _radius_x = x_axis; |
90 | | - _radius_y = y_axis; |
91 | | - _center = new PointF(center.X + _radius_x, center.Y + _radius_y); |
92 | | - _dimension = new RectangleF(_center.X - _radius_x, _center.Y - _radius_y, 2.0f * _radius_x, 2.0f * _radius_y); |
| 51 | + _radius_x = xAxis; |
| 52 | + _radius_y = yAxis; |
| 53 | + _dimension = new RectangleF(center.X , center.Y, 2.0f * _radius_x, 2.0f * _radius_y); |
93 | 54 | _color = color; |
94 | 55 | _width = width; |
95 | 56 | _duration = duration; |
96 | 57 | } |
97 | 58 |
|
98 | | - public AnimationEllipse(float x, float y, float x_axis, float y_axis, Color color, int width = 1, float duration = 0.0f) |
| 59 | + public AnimationEllipse(float x, float y, float xAxis, float yAxis, Color color, int width = 1, float duration = 0.0f) |
99 | 60 | { |
100 | | - _radius_x = x_axis; |
101 | | - _radius_y = y_axis; |
102 | | - _center = new PointF(x + _radius_x, y + _radius_y); |
103 | | - _dimension = new RectangleF(_center.X - _radius_x, _center.Y - _radius_y, 2.0f * _radius_x, 2.0f * _radius_y); |
| 61 | + _radius_x = xAxis; |
| 62 | + _radius_y = yAxis; |
| 63 | + _dimension = new RectangleF(x , y, 2.0f * _radius_x, 2.0f * _radius_y); |
104 | 64 | _color = color; |
105 | 65 | _width = width; |
106 | 66 | _duration = duration; |
107 | 67 | } |
108 | 68 |
|
109 | | - protected override void virtUpdate() |
110 | | - { |
111 | | - base._center = new PointF(_center.X * Scale, _center.Y * Scale); |
112 | | - |
113 | | - base.virtUpdate(); |
114 | | - } |
115 | | - |
116 | | - public override void Draw(Graphics g) |
117 | | - { |
118 | | - if (_pen == null || _invalidated) |
119 | | - { |
120 | | - _pen = new Pen(_color); |
121 | | - _pen.Width = _width; |
122 | | - _pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; |
123 | | - _pen.ScaleTransform(Scale, Scale); |
124 | | - |
125 | | - virtUpdate(); |
126 | | - _invalidated = false; |
127 | | - } |
128 | | - |
129 | | - g.ResetTransform(); |
130 | | - g.DrawEllipse(_pen, _dimension); |
131 | | - } |
132 | | - |
133 | | - public override AnimationFrame BlendWith(AnimationFrame otherAnim, double amount) |
134 | | - { |
135 | | - if (!(otherAnim is AnimationEllipse)) |
136 | | - { |
137 | | - throw new FormatException("Cannot blend with another type"); |
138 | | - } |
139 | | - |
140 | | - amount = GetTransitionValue(amount); |
141 | | - |
142 | | - RectangleF newrect = new RectangleF((float)CalculateNewValue(_dimension.X, otherAnim._dimension.X, amount), |
143 | | - (float)CalculateNewValue(_dimension.Y, otherAnim._dimension.Y, amount), |
144 | | - (float)CalculateNewValue(_dimension.Width, otherAnim._dimension.Width, amount), |
145 | | - (float)CalculateNewValue(_dimension.Height, otherAnim._dimension.Height, amount) |
146 | | - ); |
147 | | - |
148 | | - int newwidth = (int)CalculateNewValue(_width, otherAnim._width, amount); |
149 | | - float newAngle = (float)CalculateNewValue(_angle, otherAnim._angle, amount); |
150 | | - |
151 | | - return new AnimationEllipse(newrect, Utils.ColorUtils.BlendColors(_color, otherAnim._color, amount), newwidth).SetAngle(newAngle); |
152 | | - } |
153 | | - |
154 | 69 | public override AnimationFrame GetCopy() |
155 | 70 | { |
156 | 71 | return new AnimationEllipse(this); |
157 | 72 | } |
158 | 73 |
|
159 | | - public override bool Equals(object obj) |
160 | | - { |
161 | | - if (ReferenceEquals(null, obj)) return false; |
162 | | - if (ReferenceEquals(this, obj)) return true; |
163 | | - if (obj.GetType() != this.GetType()) return false; |
164 | | - return Equals((AnimationEllipse)obj); |
165 | | - } |
166 | | - |
167 | | - public bool Equals(AnimationEllipse p) |
168 | | - { |
169 | | - return _color.Equals(p._color) && |
170 | | - _dimension.Equals(p._dimension) && |
171 | | - _width.Equals(p._width) && |
172 | | - _duration.Equals(p._duration) && |
173 | | - _angle.Equals(p._angle); |
174 | | - } |
175 | | - |
176 | 74 | public override int GetHashCode() |
177 | 75 | { |
178 | 76 | unchecked |
|
0 commit comments