CrabUI
Loading...
Searching...
No Matches
CUIInterpolate.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6using System.IO;
7
8using Barotrauma;
9using Microsoft.Xna.Framework;
10
11namespace CrabUI
12{
13 /// <summary>
14 /// Class containing a few interpolate functions for CUIAnimation
15 /// </summary>
16 public class CUIInterpolate
17 {
18 public static object InterpolateColor(object start, object end, double lambda)
19 {
20 return ((Color)start).To(((Color)end), (float)lambda);
21 }
22
23 public static object InterpolateVector2(object start, object end, double lambda)
24 {
25 Vector2 a = (Vector2)start;
26 Vector2 b = (Vector2)end;
27 return a + (b - a) * (float)lambda;
28 }
29
30 public static object InterpolateFloat(object start, object end, double lambda)
31 {
32 float a = (float)start;
33 float b = (float)end;
34 return a + (b - a) * (float)lambda;
35 }
36
37 public static Dictionary<Type, Func<object, object, double, object>> Interpolate = new();
38
39 internal static void InitStatic()
40 {
41 CUI.OnInit += () =>
42 {
43 Interpolate[typeof(Color)] = InterpolateColor;
44 Interpolate[typeof(Vector2)] = InterpolateVector2;
45 Interpolate[typeof(float)] = InterpolateFloat;
46 };
47
48 CUI.OnDispose += () =>
49 {
50 Interpolate.Clear();
51 };
52 }
53 }
54}
Class containing a few interpolate functions for CUIAnimation.