Skip to content

Commit 52e58de

Browse files
authored
Merge pull request #40 from Aurora-RGB/master
master -> dev
2 parents 9570373 + c642e9a commit 52e58de

19 files changed

Lines changed: 285 additions & 396 deletions

Project-Aurora/Project-Aurora/EffectsEngine/Animations/AnimationCircle.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class AnimationCircle : AnimationFrame
99
[Newtonsoft.Json.JsonProperty]
1010
internal float _radius = 0.0f;
1111

12-
public float Radius { get { return _radius; } }
13-
public PointF Center { get { return _center; } }
12+
public float Radius => _radius;
13+
public PointF Center => _center;
1414

1515
public AnimationFrame SetRadius(float radius)
1616
{
@@ -87,21 +87,22 @@ public AnimationCircle(float x, float y, float radius, Color color, int width =
8787

8888
public override void Draw(Graphics g)
8989
{
90-
if (_pen == null || _invalidated)
90+
if (_invalidated)
9191
{
9292
_pen = new Pen(_color);
9393
_pen.Width = _width;
94-
_pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center;
95-
_pen.ScaleTransform(Scale, Scale);
94+
//_pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center;
95+
//_pen.ScaleTransform(Scale, Scale);
9696

9797
virtUpdate();
9898
_invalidated = false;
9999
}
100100

101-
if(_scaledDimension.Width > 1 && _scaledDimension.Height > 1)
101+
if(_dimension.Width > 1 && _dimension.Height > 1)
102102
{
103103
g.ResetTransform();
104-
g.DrawEllipse(_pen, _scaledDimension);
104+
g.Transform = _transformationMatrix;
105+
g.DrawEllipse(_pen, _dimension);
105106
}
106107
}
107108

Project-Aurora/Project-Aurora/EffectsEngine/Animations/AnimationEllipse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public override void Draw(Graphics g)
127127
}
128128

129129
g.ResetTransform();
130-
g.DrawEllipse(_pen, _scaledDimension);
130+
g.DrawEllipse(_pen, _dimension);
131131
}
132132

133133
public override AnimationFrame BlendWith(AnimationFrame otherAnim, double amount)

Project-Aurora/Project-Aurora/EffectsEngine/Animations/AnimationFilledCircle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override void Draw(Graphics g)
3737
}
3838

3939
g.ResetTransform();
40-
g.FillEllipse(_brush, _scaledDimension);
40+
g.FillEllipse(_brush, _dimension);
4141
}
4242

4343
public override AnimationFrame BlendWith(AnimationFrame otherAnim, double amount)

Project-Aurora/Project-Aurora/EffectsEngine/Animations/AnimationFilledGradientRectangle.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class AnimationFilledGradientRectangle : AnimationFilledRectangle
99
[Newtonsoft.Json.JsonProperty]
1010
internal EffectBrush _gradientBrush;
1111

12-
public EffectBrush GradientBrush { get { return _gradientBrush; } }
12+
public EffectBrush GradientBrush => _gradientBrush;
1313

14-
public AnimationFilledGradientRectangle() : base()
14+
public AnimationFilledGradientRectangle()
1515
{
1616
}
1717

@@ -37,10 +37,16 @@ public AnimationFilledGradientRectangle(float x, float y, float rect_width, floa
3737

3838
public override void Draw(Graphics g)
3939
{
40-
Matrix originalMatrix = g.Transform;
40+
if (_invalidated)
41+
{
42+
virtUpdate();
43+
_invalidated = false;
44+
}
45+
46+
g.ResetTransform();
4147
g.Transform = _transformationMatrix;
42-
g.FillRectangle(_gradientBrush.GetDrawingBrush(), _scaledDimension);
43-
g.Transform = originalMatrix;
48+
//g.FillRectangle(_gradientBrush.GetDrawingBrush(), _scaledDimension);
49+
g.FillRectangle(_gradientBrush.GetDrawingBrush(), _dimension);
4450
}
4551

4652
public override AnimationFrame BlendWith(AnimationFrame otherAnim, double amount)

Project-Aurora/Project-Aurora/EffectsEngine/Animations/AnimationFilledRectangle.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Aurora.EffectsEngine.Animations
66
{
77
public class AnimationFilledRectangle : AnimationRectangle
88
{
9-
public AnimationFilledRectangle() : base()
9+
public AnimationFilledRectangle()
1010
{
1111
}
1212

@@ -24,16 +24,19 @@ public AnimationFilledRectangle(float x, float y, float rect_width, float rect_h
2424

2525
public override void Draw(Graphics g)
2626
{
27-
if (_brush == null || _invalidated)
27+
if (_invalidated)
2828
{
29-
_brush = new SolidBrush(_color);
29+
_pen = new Pen(_color);
30+
_pen.Width = _width;
31+
_pen.Alignment = PenAlignment.Center;
32+
3033
virtUpdate();
3134
_invalidated = false;
3235
}
3336

3437
g.ResetTransform();
3538
g.Transform = _transformationMatrix;
36-
g.FillRectangle(_brush, _scaledDimension);
39+
g.FillRectangle(_brush, _dimension);
3740
}
3841

3942
public override AnimationFrame BlendWith(AnimationFrame otherAnim, double amount)

Project-Aurora/Project-Aurora/EffectsEngine/Animations/AnimationFrame.cs

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.ComponentModel;
33
using System.Drawing;
44
using System.Drawing.Drawing2D;
5-
using System.Threading;
6-
using System.Windows;
75

86
namespace 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

Comments
 (0)