-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleAnimations.cs
More file actions
300 lines (259 loc) · 9.63 KB
/
SampleAnimations.cs
File metadata and controls
300 lines (259 loc) · 9.63 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
using FishUI;
using FishUI.Controls;
using System;
using System.Numerics;
namespace FishUIDemos
{
/// <summary>
/// Demonstrates the animation system with various transition effects.
/// </summary>
public class SampleAnimations : ISample
{
FishUI.FishUI FUI;
public string Name => "Animations";
public TakeScreenshotFunc TakeScreenshot { get; set; }
// Controls that will be animated
Button fadeButton;
Button slideButton;
Button scaleButton;
Panel animatedPanel;
ProgressBar animatedProgress;
public FishUI.FishUI CreateUI(FishUISettings UISettings, IFishUIGfx Gfx, IFishUIInput Input, IFishUIEvents Events)
{
FUI = new FishUI.FishUI(UISettings, Gfx, Input, Events);
FUI.Init();
FishUITheme theme = UISettings.LoadTheme(ThemePreferences.LoadThemePath(), applyImmediately: true);
return FUI;
}
public void Init()
{
// === Title ===
Label titleLabel = new Label("Animation System Demo");
titleLabel.Position = new Vector2(20, 20);
titleLabel.Size = new Vector2(300, 30);
titleLabel.Alignment = Align.Left;
FUI.AddControl(titleLabel);
// Screenshot button
ImageRef iconCamera = FUI.Graphics.LoadImage("data/silk_icons/camera.png");
Button screenshotBtn = new Button();
screenshotBtn.Icon = iconCamera;
screenshotBtn.Position = new Vector2(330, 20);
screenshotBtn.Size = new Vector2(30, 30);
screenshotBtn.IsImageButton = true;
screenshotBtn.TooltipText = "Take a screenshot";
screenshotBtn.OnButtonPressed += (btn, mbtn, pos) => TakeScreenshot?.Invoke(Name);
FUI.AddControl(screenshotBtn);
// === Fade Animations ===
Label fadeLabel = new Label("Fade Animations");
fadeLabel.Position = new Vector2(20, 60);
fadeLabel.Alignment = Align.Left;
FUI.AddControl(fadeLabel);
fadeButton = new Button();
fadeButton.Text = "Fade Me!";
fadeButton.Position = new Vector2(20, 85);
fadeButton.Size = new Vector2(100, 30);
FUI.AddControl(fadeButton);
Button fadeInBtn = new Button();
fadeInBtn.Text = "Fade In";
fadeInBtn.Position = new Vector2(130, 85);
fadeInBtn.Size = new Vector2(70, 30);
fadeInBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
fadeButton.FadeIn(0.5f, Easing.EaseOutQuad);
};
FUI.AddControl(fadeInBtn);
Button fadeOutBtn = new Button();
fadeOutBtn.Text = "Fade Out";
fadeOutBtn.Position = new Vector2(205, 85);
fadeOutBtn.Size = new Vector2(70, 30);
fadeOutBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
fadeButton.FadeOut(0.5f, Easing.EaseInQuad);
};
FUI.AddControl(fadeOutBtn);
// === Slide Animations ===
Label slideLabel = new Label("Slide Animations");
slideLabel.Position = new Vector2(20, 130);
slideLabel.Alignment = Align.Left;
FUI.AddControl(slideLabel);
slideButton = new Button();
slideButton.Text = "Slide Me!";
slideButton.Position = new Vector2(20, 155);
slideButton.Size = new Vector2(100, 30);
FUI.AddControl(slideButton);
Button slideLeftBtn = new Button();
slideLeftBtn.Text = "? Left";
slideLeftBtn.Position = new Vector2(130, 155);
slideLeftBtn.Size = new Vector2(60, 30);
slideLeftBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
slideButton.SlideIn(new Vector2(-100, 0), 0.4f, Easing.EaseOutBack);
};
FUI.AddControl(slideLeftBtn);
Button slideRightBtn = new Button();
slideRightBtn.Text = "Right ?";
slideRightBtn.Position = new Vector2(195, 155);
slideRightBtn.Size = new Vector2(60, 30);
slideRightBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
slideButton.SlideIn(new Vector2(100, 0), 0.4f, Easing.EaseOutBack);
};
FUI.AddControl(slideRightBtn);
Button slideUpBtn = new Button();
slideUpBtn.Text = "? Up";
slideUpBtn.Position = new Vector2(260, 155);
slideUpBtn.Size = new Vector2(50, 30);
slideUpBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
slideButton.SlideIn(new Vector2(0, -50), 0.4f, Easing.EaseOutBounce);
};
FUI.AddControl(slideUpBtn);
// === Scale/Bounce Animations ===
Label scaleLabel = new Label("Scale Animations");
scaleLabel.Position = new Vector2(20, 200);
scaleLabel.Alignment = Align.Left;
FUI.AddControl(scaleLabel);
scaleButton = new Button();
scaleButton.Text = "Bounce Me!";
scaleButton.Position = new Vector2(20, 225);
scaleButton.Size = new Vector2(100, 30);
FUI.AddControl(scaleButton);
Button bounceBtn = new Button();
bounceBtn.Text = "Bounce";
bounceBtn.Position = new Vector2(130, 225);
bounceBtn.Size = new Vector2(70, 30);
bounceBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
scaleButton.ScaleBounce(1.2f, 0.3f);
};
FUI.AddControl(bounceBtn);
Button growBtn = new Button();
growBtn.Text = "Grow";
growBtn.Position = new Vector2(205, 225);
growBtn.Size = new Vector2(60, 30);
growBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
scaleButton.AnimateSize(new Vector2(150, 40), 0.3f, Easing.EaseOutElastic);
};
FUI.AddControl(growBtn);
Button shrinkBtn = new Button();
shrinkBtn.Text = "Shrink";
shrinkBtn.Position = new Vector2(270, 225);
shrinkBtn.Size = new Vector2(60, 30);
shrinkBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
scaleButton.AnimateSize(new Vector2(100, 30), 0.3f, Easing.EaseOutQuad);
};
FUI.AddControl(shrinkBtn);
// === Easing Comparison ===
Label easingLabel = new Label("Easing Functions");
easingLabel.Position = new Vector2(20, 280);
easingLabel.Alignment = Align.Left;
FUI.AddControl(easingLabel);
// Create panels to demonstrate different easing functions
string[] easingNames = { "Linear", "EaseOut", "EaseOutBack", "EaseOutElastic", "EaseOutBounce" };
Easing[] easings = { Easing.Linear, Easing.EaseOut, Easing.EaseOutBack, Easing.EaseOutElastic, Easing.EaseOutBounce };
for (int i = 0; i < easingNames.Length; i++)
{
Label easingNameLabel = new Label(easingNames[i]);
easingNameLabel.Position = new Vector2(20, 305 + i * 35);
easingNameLabel.Size = new Vector2(100, 20);
easingNameLabel.Alignment = Align.Left;
FUI.AddControl(easingNameLabel);
Panel easingPanel = new Panel();
easingPanel.Position = new Vector2(130, 305 + i * 35);
easingPanel.Size = new Vector2(30, 25);
easingPanel.Variant = PanelVariant.Highlight;
FUI.AddControl(easingPanel);
// Store for animation
int index = i;
Easing easing = easings[i];
}
Button animateEasingsBtn = new Button();
animateEasingsBtn.Text = "Animate All Easings";
animateEasingsBtn.Position = new Vector2(20, 485);
animateEasingsBtn.Size = new Vector2(150, 30);
animateEasingsBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
AnimateEasingPanels();
};
FUI.AddControl(animateEasingsBtn);
// === Panel Animation ===
Label panelLabel = new Label("Panel Animation");
panelLabel.Position = new Vector2(350, 60);
panelLabel.Alignment = Align.Left;
FUI.AddControl(panelLabel);
animatedPanel = new Panel();
animatedPanel.Position = new Vector2(350, 85);
animatedPanel.Size = new Vector2(150, 100);
animatedPanel.Variant = PanelVariant.Bright;
FUI.AddControl(animatedPanel);
Label panelContent = new Label("Animated Panel");
panelContent.Position = new Vector2(10, 40);
panelContent.Alignment = Align.Left;
animatedPanel.AddChild(panelContent);
Button movePanelBtn = new Button();
movePanelBtn.Text = "Move Panel";
movePanelBtn.Position = new Vector2(350, 195);
movePanelBtn.Size = new Vector2(100, 30);
movePanelBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
var currentPos = new Vector2(animatedPanel.Position.X, animatedPanel.Position.Y);
var targetPos = currentPos.X > 400 ? new Vector2(350, 85) : new Vector2(450, 120);
animatedPanel.AnimatePosition(targetPos, 0.5f, Easing.EaseOutBack);
};
FUI.AddControl(movePanelBtn);
// === Progress Bar Animation ===
Label progressLabel = new Label("Progress Animation");
progressLabel.Position = new Vector2(350, 240);
progressLabel.Alignment = Align.Left;
FUI.AddControl(progressLabel);
animatedProgress = new ProgressBar();
animatedProgress.Position = new Vector2(350, 265);
animatedProgress.Size = new Vector2(200, 25);
animatedProgress.Value = 0.3f;
FUI.AddControl(animatedProgress);
Button animateProgressBtn = new Button();
animateProgressBtn.Text = "Animate Progress";
animateProgressBtn.Position = new Vector2(350, 300);
animateProgressBtn.Size = new Vector2(120, 30);
animateProgressBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
float targetProgress = animatedProgress.Value < 0.5f ? 1f : 0f;
FishUITween.Float(FUI.Animations, animatedProgress, "Progress",
animatedProgress.Value, targetProgress, 1f, Easing.EaseInOutQuad,
v => animatedProgress.Value = v);
};
FUI.AddControl(animateProgressBtn);
// === Animation Info ===
Label infoLabel = new Label("Active Animations: 0");
infoLabel.Position = new Vector2(350, 350);
infoLabel.Size = new Vector2(200, 20);
infoLabel.Alignment = Align.Left;
infoLabel.ID = "animationCountLabel";
FUI.AddControl(infoLabel);
}
private void AnimateEasingPanels()
{
// Find all highlight panels and animate them
var controls = FUI.GetAllControls();
int panelIndex = 0;
Easing[] easings = { Easing.Linear, Easing.EaseOut, Easing.EaseOutBack, Easing.EaseOutElastic, Easing.EaseOutBounce };
foreach (var control in controls)
{
if (control is Panel panel && panel.Variant == PanelVariant.Highlight)
{
if (panelIndex < easings.Length)
{
var startX = 130f;
var endX = 280f;
var currentX = panel.Position.X;
var targetX = currentX < 200 ? endX : startX;
panel.AnimatePosition(new Vector2(targetX, panel.Position.Y), 1f, easings[panelIndex]);
panelIndex++;
}
}
}
}
}
}