22using System . ComponentModel ;
33using System . Drawing ;
44using System . Drawing . Drawing2D ;
5- using System . Threading ;
6- using System . Windows ;
75
86namespace Aurora . EffectsEngine . Animations
97{
@@ -66,20 +64,20 @@ public class AnimationFrame
6664 [ Newtonsoft . Json . JsonProperty ]
6765 internal float _duration ;
6866 internal Pen _pen = null ;
69- internal Brush _brush = null ;
67+ internal Brush _brush ;
7068 internal bool _invalidated = true ;
7169 [ Newtonsoft . Json . JsonProperty ]
7270 internal AnimationFrameTransitionType _transitionType = AnimationFrameTransitionType . Linear ;
7371 [ Newtonsoft . Json . JsonProperty ]
74- internal float _angle = 0.0f ;
72+ internal float _angle ;
7573 [ Newtonsoft . Json . JsonProperty ]
76- protected PointF _center ;
74+ protected PointF _center = PointF . Empty ;
7775
7876
7977 protected float _scale = 1.0f ;
80- protected PointF _offset = default ( PointF ) ;
78+ protected PointF _offset ;
8179
82- protected RectangleF _scaledDimension ;
80+ // protected RectangleF _scaledDimension;
8381 internal Matrix _transformationMatrix ;
8482
8583 public float Scale
@@ -94,39 +92,16 @@ public float Scale
9492 }
9593 }
9694 }
97- public PointF Offset
98- {
99- get { return _offset ; }
100- set
101- {
102- if ( _offset != value )
103- {
104- _offset = value ;
105- _invalidated = true ;
106- }
107- }
108- }
109- public PointF RotatePoint
110- {
111- get { return _center ; }
112- set
113- {
114- if ( _center != value )
115- {
116- _center = value ;
117- _invalidated = true ;
118- }
119- }
120- }
121- public Matrix TransformationMatrix { get { return _transformationMatrix ; } }
122- public RectangleF ScaledDimension { get { return _scaledDimension ; } }
95+ public PointF Offset => _offset ;
96+
97+ public PointF RotatePoint => _center ;
12398
124- public Color Color { get { return _color ; } }
125- public RectangleF Dimension { get { return _dimension ; } }
126- public int Width { get { return _width ; } }
127- public float Duration { get { return _duration ; } }
128- public AnimationFrameTransitionType TransitionType { get { return _transitionType ; } }
129- public float Angle { get { return _angle ; } }
99+ public Color Color => _color ;
100+ public RectangleF Dimension => _dimension ;
101+ public int Width => _width ;
102+ public float Duration => _duration ;
103+ public AnimationFrameTransitionType TransitionType => _transitionType ;
104+ public float Angle => _angle ;
130105
131106 public AnimationFrame ( )
132107 {
@@ -175,14 +150,18 @@ void updateMatrices()
175150 {
176151 _transformationMatrix = new Matrix ( ) ;
177152
178- _scaledDimension = new RectangleF ( _dimension . X * _scale , _dimension . Y * _scale , _dimension . Width * _scale , _dimension . Height * _scale ) ;
179- _scaledDimension . Offset ( _offset ) ;
180-
181- if ( _center == null )
182- _center = new PointF ( _scaledDimension . X + _dimension . Width / 2 , _scaledDimension . Y + _scaledDimension . Height / 2 ) ;
153+ //_scaledDimension = new RectangleF(_dimension.X * _scale, _dimension.Y * _scale, _dimension.Width * _scale, _dimension.Height * _scale);
154+ //_scaledDimension.Offset(_offset.X * _scale, _offset.Y * _scale);
183155
156+ if ( _center . Equals ( PointF . Empty ) || float . IsNaN ( _center . X ) )
157+ {
158+ _center = new PointF ( _dimension . Width / 2 , _dimension . Height / 2 ) ;
159+ }
160+
184161 _transformationMatrix . RotateAt ( - _angle , _center , MatrixOrder . Append ) ;
185- _transformationMatrix . Translate ( - _scaledDimension . Width / 2f , - _scaledDimension . Height / 2f ) ;
162+ _transformationMatrix . Scale ( _scale , _scale ) ;
163+
164+ _transformationMatrix . Translate ( - _offset . X , - _offset . Y , MatrixOrder . Append ) ;
186165
187166 _invalidated = false ;
188167 }
@@ -196,15 +175,6 @@ public void SetOffset(PointF offset)
196175 }
197176 }
198177
199- public void SetScale ( float scale )
200- {
201- if ( _scale != scale )
202- {
203- _scale = scale ;
204- _invalidated = true ;
205- }
206- }
207-
208178 public AnimationFrame SetColor ( Color color )
209179 {
210180 _color = color ;
@@ -267,21 +237,30 @@ public virtual AnimationFrame BlendWith(AnimationFrame otherAnim, double amount)
267237 CalculateNewValue ( _dimension . Height , otherAnim . _dimension . Height , amount )
268238 ) ;
269239
270- PointF newRotatingPoint = new PointF ( CalculateNewValue ( _center . X , otherAnim . _center . X , amount ) ,
240+ PointF newRotatingPoint = new PointF (
241+ CalculateNewValue ( _center . X , otherAnim . _center . X , amount ) ,
271242 CalculateNewValue ( _center . Y , otherAnim . _center . Y , amount )
272243 ) ;
273244
245+ PointF newOffset = new PointF (
246+ CalculateNewValue ( _offset . X , otherAnim . _offset . X , amount ) ,
247+ CalculateNewValue ( _offset . Y , otherAnim . _offset . Y , amount )
248+ ) ;
249+
274250 float newAngle = CalculateNewValue ( _angle , otherAnim . _angle , amount ) ;
275251 float newScale = CalculateNewValue ( _scale , otherAnim . _scale , amount ) ;
276252 int newWidth = CalculateNewValue ( _width , otherAnim . _width , amount ) ;
277253
278254 AnimationFrame newframe = new AnimationFrame ( ) ;
279255 newframe . _dimension = newrect ;
256+ newframe . _center = newRotatingPoint ;
257+ newframe . _offset = newOffset ;
280258
281259 newframe . _angle = newAngle ;
282260 newframe . _scale = newScale ;
283261 newframe . _width = newWidth ;
284262 newframe . _color = Utils . ColorUtils . BlendColors ( _color , otherAnim . _color , amount ) ;
263+
285264
286265 return newframe ;
287266 }
@@ -333,16 +312,14 @@ internal float CalculateNewValue(float first, float second, double amount)
333312 {
334313 if ( first == second )
335314 return first ;
336- else
337- return ( float ) ( first * ( 1.0 - amount ) + second * ( amount ) ) ;
315+ return ( float ) ( first * ( 1.0 - amount ) + second * ( amount ) ) ;
338316 }
339317
340318 internal double CalculateNewValue ( double first , double second , double amount )
341319 {
342320 if ( first == second )
343321 return first ;
344- else
345- return ( double ) ( first * ( 1.0 - amount ) + second * ( amount ) ) ;
322+ return first * ( 1.0 - amount ) + second * ( amount ) ;
346323 }
347324
348325 internal int CalculateNewValue ( int first , int second , double amount )
0 commit comments