Skip to content

Commit b146513

Browse files
Adding Fade animation to all shapes
1 parent 64186ef commit b146513

File tree

3 files changed

+128
-131
lines changed

3 files changed

+128
-131
lines changed

PowerPoint/Openize.Slides.Facade/AnimationFacade.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ public class AnimateFacade
1919
{
2020
// Properties for ShapeId, Delay, and Duration
2121
public string ShapeId { get; set; }
22-
public string Delay { get; set; }
23-
public string Duration { get; set; }
22+
public int Duration { get; set; }
23+
public string Type { get; set; }
2424

2525
// Constructor to initialize the properties
26-
public AnimateFacade(string shapeId = "1", string delay = "0", string duration = "indefinite")
26+
public AnimateFacade(string shapeId = "1", int duration = 0, string type = "fade")
2727
{
2828
ShapeId = shapeId;
29-
Delay = delay;
29+
Type = type;
3030
Duration = duration;
3131
}
32-
public Timing animate() {
33-
return GenerateTiming(ShapeId);
32+
public Timing animate()
33+
{
34+
return GenerateTiming(ShapeId, 1000, "fade");
3435
}
35-
public Timing GenerateTiming(String shapeId)
36+
public Timing GenerateTiming(String shapeId, int duration, String type)
3637
{
3738
Timing timing1 = new Timing();
3839

@@ -119,10 +120,10 @@ public Timing GenerateTiming(String shapeId)
119120
setBehavior1.Append(commonBehavior1);
120121
setBehavior1.Append(toVariantValue1);
121122

122-
AnimateEffect animateEffect1 = new AnimateEffect() { Transition = AnimateEffectTransitionValues.In, Filter = "fade" };
123+
AnimateEffect animateEffect1 = new AnimateEffect() { Transition = AnimateEffectTransitionValues.In, Filter = type };
123124

124125
CommonBehavior commonBehavior2 = new CommonBehavior();
125-
CommonTimeNode commonTimeNode7 = new CommonTimeNode() { Id = (UInt32Value)7U, Duration = "1000" };
126+
CommonTimeNode commonTimeNode7 = new CommonTimeNode() { Id = (UInt32Value)7U, Duration = duration.ToString() };
126127

127128
TargetElement targetElement2 = new TargetElement();
128129
ShapeTarget shapeTarget2 = new ShapeTarget() { ShapeId = shapeId };
@@ -137,7 +138,7 @@ public Timing GenerateTiming(String shapeId)
137138
Animate animate1 = new Animate() { CalculationMode = AnimateBehaviorCalculateModeValues.Linear, ValueType = AnimateBehaviorValues.Number };
138139

139140
CommonBehavior commonBehavior3 = new CommonBehavior();
140-
CommonTimeNode commonTimeNode8 = new CommonTimeNode() { Id = (UInt32Value)8U, Duration = "1000", Fill = TimeNodeFillValues.Hold };
141+
CommonTimeNode commonTimeNode8 = new CommonTimeNode() { Id = (UInt32Value)8U, Duration = duration.ToString(), Fill = TimeNodeFillValues.Hold };
141142

142143
TargetElement targetElement3 = new TargetElement();
143144
ShapeTarget shapeTarget3 = new ShapeTarget() { ShapeId = shapeId };
@@ -183,7 +184,7 @@ public Timing GenerateTiming(String shapeId)
183184
Animate animate2 = new Animate() { CalculationMode = AnimateBehaviorCalculateModeValues.Linear, ValueType = AnimateBehaviorValues.Number };
184185

185186
CommonBehavior commonBehavior4 = new CommonBehavior();
186-
CommonTimeNode commonTimeNode9 = new CommonTimeNode() { Id = (UInt32Value)9U, Duration = "1000", Fill = TimeNodeFillValues.Hold };
187+
CommonTimeNode commonTimeNode9 = new CommonTimeNode() { Id = (UInt32Value)9U, Duration = duration.ToString(), Fill = TimeNodeFillValues.Hold };
187188

188189
TargetElement targetElement4 = new TargetElement();
189190
ShapeTarget shapeTarget4 = new ShapeTarget() { ShapeId = shapeId };

PowerPoint/Openize.Slides/Rectangle.cs

Lines changed: 60 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,135 +7,122 @@
77
namespace Openize.Slides
88
{
99
/// <summary>
10-
/// This class represents the rectangle shape within a slide.
10+
/// Represents a rectangle shape within a slide.
1111
/// </summary>
1212
public class Rectangle
1313
{
14-
private double _x;
15-
private double _y;
16-
private double _Width;
17-
private double _Height;
18-
private RectangleShapeFacade _Facade;
19-
private int _shapeIndex;
20-
private string _BackgroundColor = null;
21-
private AnimationType _Animation = AnimationType.None;
2214
/// <summary>
23-
/// Property to get or set X coordinate of the shape.
15+
/// Gets or sets the X coordinate of the rectangle shape.
2416
/// </summary>
25-
public double X { get => _x; set => _x = value; }
17+
public double X { get; set; }
2618

2719
/// <summary>
28-
/// Property to get or set Y coordinate of the shape.
20+
/// Gets or sets the Y coordinate of the rectangle shape.
2921
/// </summary>
30-
public double Y { get => _y; set => _y = value; }
22+
public double Y { get; set; }
3123

3224
/// <summary>
33-
/// Property to get or set width of the shape.
25+
/// Gets or sets the width of the rectangle shape.
3426
/// </summary>
35-
public double Width { get => _Width; set => _Width = value; }
27+
public double Width { get; set; }
3628

3729
/// <summary>
38-
/// Property to get or set height of the shape.
30+
/// Gets or sets the height of the rectangle shape.
3931
/// </summary>
40-
public double Height { get => _Height; set => _Height = value; }
32+
public double Height { get; set; }
4133

4234
/// <summary>
43-
/// Property to get or set the RectangleShapeFacade.
35+
/// Gets or sets the facade that handles rectangle shape operations.
4436
/// </summary>
45-
public RectangleShapeFacade Facade { get => _Facade; set => _Facade = value; }
37+
public RectangleShapeFacade Facade { get; set; }
4638

4739
/// <summary>
48-
/// Property to get or set the shape index within a slide.
40+
/// Gets or sets the index of the shape within a slide.
4941
/// </summary>
50-
public int ShapeIndex { get => _shapeIndex; set => _shapeIndex = value; }
42+
public int ShapeIndex { get; set; }
5143

5244
/// <summary>
53-
/// Property to set or get background color of a rectangle shape.
45+
/// Gets or sets the background color of the rectangle shape.
46+
/// Default value is "Transparent".
5447
/// </summary>
55-
public string BackgroundColor { get => _BackgroundColor; set => _BackgroundColor = value; }
48+
public string BackgroundColor { get; set; } = "Transparent";
49+
5650
/// <summary>
57-
/// Property to set animation
51+
/// Gets or sets the animation type applied to the rectangle shape.
52+
/// Default value is <see cref="AnimationType.None"/>.
5853
/// </summary>
59-
public AnimationType Animation { get => _Animation; set => _Animation = value; }
54+
public AnimationType Animation { get; set; } = AnimationType.None;
55+
6056
/// <summary>
61-
/// Constructor of the Rectangle class initializes the object of RectangleShapeFacade and populates its fields.
57+
/// Initializes a new instance of the <see cref="Rectangle"/> class.
6258
/// </summary>
6359
public Rectangle()
6460
{
65-
_Facade = new RectangleShapeFacade();
66-
_Facade.ShapeIndex = _shapeIndex;
61+
Facade = new RectangleShapeFacade
62+
{
63+
ShapeIndex = ShapeIndex
64+
};
6765

68-
_BackgroundColor = "Transparent";
69-
_x = Utility.EmuToPixels(1349828);
70-
_y = Utility.EmuToPixels(1999619);
71-
_Width = Utility.EmuToPixels(6000000);
72-
_Height = Utility.EmuToPixels(2000000);
66+
X = Utility.EmuToPixels(1349828);
67+
Y = Utility.EmuToPixels(1999619);
68+
Width = Utility.EmuToPixels(6000000);
69+
Height = Utility.EmuToPixels(2000000);
7370

74-
Populate_Facade();
71+
PopulateFacade();
7572
}
7673

7774
/// <summary>
78-
/// Method to update rectangle shape.
75+
/// Updates the rectangle shape by synchronizing its properties with the facade.
7976
/// </summary>
8077
public void Update()
8178
{
82-
Populate_Facade();
83-
_Facade.UpdateShape();
79+
PopulateFacade();
80+
Facade.UpdateShape();
8481
}
8582

8683
/// <summary>
87-
/// Method to populate the fields of the respective facade.
84+
/// Populates the facade with the current rectangle properties.
85+
/// Converts pixel values to EMUs before setting them in the facade.
8886
/// </summary>
89-
private void Populate_Facade()
87+
private void PopulateFacade()
9088
{
91-
_Facade.BackgroundColor = _BackgroundColor;
92-
_Facade.X = Utility.PixelsToEmu(_x);
93-
_Facade.Y = Utility.PixelsToEmu(_y);
94-
_Facade.Width = Utility.PixelsToEmu(_Width);
95-
_Facade.Height = Utility.PixelsToEmu(_Height);
89+
Facade.BackgroundColor = BackgroundColor;
90+
Facade.X = Utility.PixelsToEmu(X);
91+
Facade.Y = Utility.PixelsToEmu(Y);
92+
Facade.Width = Utility.PixelsToEmu(Width);
93+
Facade.Height = Utility.PixelsToEmu(Height);
9694
}
9795

9896
/// <summary>
99-
/// Method for getting the list of rectangle shapes.
97+
/// Retrieves a list of rectangle objects from their corresponding facades.
10098
/// </summary>
101-
/// <param name="RectangleFacades">A list of RectangleShapeFacade objects.</param>
102-
/// <returns>A list of Rectangle objects.</returns>
103-
public static List<Rectangle> GetRectangles(List<RectangleShapeFacade> RectangleFacades)
99+
/// <param name="rectangleFacades">A list of <see cref="RectangleShapeFacade"/> objects.</param>
100+
/// <returns>A list of <see cref="Rectangle"/> objects.</returns>
101+
public static List<Rectangle> GetRectangles(List<RectangleShapeFacade> rectangleFacades)
104102
{
105-
List<Rectangle> Rectangles = new List<Rectangle>();
106-
try
103+
var rectangles = new List<Rectangle>();
104+
foreach (var facade in rectangleFacades)
107105
{
108-
foreach (var facade in RectangleFacades)
106+
rectangles.Add(new Rectangle
109107
{
110-
Rectangle Rectangle = new Rectangle
111-
{
112-
BackgroundColor = facade.BackgroundColor,
113-
X = Utility.EmuToPixels(facade.X),
114-
Y = Utility.EmuToPixels(facade.Y),
115-
Width = Utility.EmuToPixels(facade.Width),
116-
Height = Utility.EmuToPixels(facade.Height),
117-
Facade = facade,
118-
ShapeIndex = facade.ShapeIndex
119-
};
120-
121-
Rectangles.Add(Rectangle);
122-
}
108+
BackgroundColor = facade.BackgroundColor,
109+
X = Utility.EmuToPixels(facade.X),
110+
Y = Utility.EmuToPixels(facade.Y),
111+
Width = Utility.EmuToPixels(facade.Width),
112+
Height = Utility.EmuToPixels(facade.Height),
113+
Facade = facade,
114+
ShapeIndex = facade.ShapeIndex
115+
});
123116
}
124-
catch (Exception ex)
125-
{
126-
string errorMessage = Common.OpenizeException.ConstructMessage(ex, "Getting Rectangle Shapes");
127-
throw new Common.OpenizeException(errorMessage, ex);
128-
}
129-
130-
return Rectangles;
117+
return rectangles;
131118
}
132119

133120
/// <summary>
134-
/// Method to remove the rectangle shape from a slide.
121+
/// Removes the rectangle shape from the slide.
135122
/// </summary>
136123
public void Remove()
137124
{
138-
_Facade.RemoveShape(this.Facade.RectangleShape);
125+
Facade.RemoveShape(Facade.RectangleShape);
139126
}
140127
}
141128
}

0 commit comments

Comments
 (0)