-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeviceIcons.cs
189 lines (160 loc) · 7.46 KB
/
DeviceIcons.cs
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
using System.Windows.Media.Imaging;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Media;
using System;
using System.Windows;
namespace HeadsetBatteryInfo
{
public enum DeviceType
{
Headset,
ControllerLeft,
ControllerRight,
}
public static class DeviceIcons
{
public struct HeadsetIcons
{
public ImageSource headset;
public ImageSource headsetCharging;
public ImageSource leftController;
public ImageSource rightController;
public ImageSource companyLogo;
}
public enum Company
{
Unknown = -1,
Pico,
Meta
}
public static HeadsetIcons Unknown;
public static HeadsetIcons Pico;
public static HeadsetIcons Meta;
private static SolidColorBrush blueSolid = new SolidColorBrush();
private static SolidColorBrush greenSolid = new SolidColorBrush();
private static SolidColorBrush yellowSolid = new SolidColorBrush();
private static SolidColorBrush redSolid = new SolidColorBrush();
private static SolidColorBrush greySolid = new SolidColorBrush();
private static LinearGradientBrush blueGradientBrush = new LinearGradientBrush();
private static LinearGradientBrush greenGradientBrush = new LinearGradientBrush();
private static LinearGradientBrush yellowGradientBrush = new LinearGradientBrush();
private static LinearGradientBrush redGradientBrush = new LinearGradientBrush();
private static LinearGradientBrush greyGradientBrush = new LinearGradientBrush();
private static Company headsetCompany;
public static HeadsetIcons GetCurrentDeviceIcons()
{
switch (headsetCompany)
{
case Company.Pico:
return Pico;
case Company.Meta:
return Meta;
default:
return Unknown;
}
}
public static void SetCompany(string company)
{
if (company == "pico")
headsetCompany = Company.Pico;
else if (company == "meta")
headsetCompany = Company.Meta;
else
headsetCompany = Company.Unknown;
}
public static Company GetCompany()
{
return headsetCompany;
}
public static LinearGradientBrush GetBlueGradient() => blueGradientBrush;
public static LinearGradientBrush GetGreenGradient() => greenGradientBrush;
public static LinearGradientBrush GetYellowGradient() => yellowGradientBrush;
public static LinearGradientBrush GetRedGradient() => redGradientBrush;
public static LinearGradientBrush GetGreyGradient() => greyGradientBrush;
public static SolidColorBrush GetBlueSolid() => blueSolid;
public static SolidColorBrush GetGreenSolid() => greenSolid;
public static SolidColorBrush GetYellowSolid() => yellowSolid;
public static SolidColorBrush GetRedSolid() => redSolid;
public static SolidColorBrush GetGreySolid() => greySolid;
public static void Init()
{
InitFolder("unknown", true, ref Unknown);
InitFolder("pico", false, ref Pico);
InitFolder("meta", false, ref Meta);
InitGradient();
}
private static void InitFolder(string folder, bool singleControllerImage, ref HeadsetIcons icons)
{
var leftControllerName = singleControllerImage ? "controller" : "left_controller";
var rightControllerName = singleControllerImage ? "controller" : "right_controller";
icons.headset = ConvertBitmapToImageSource(GetImageBitmap($"Assets/Images/{folder}/headset.png")) as BitmapSource;
icons.leftController = ConvertBitmapToImageSource(GetImageBitmap($"Assets/Images/{folder}/{leftControllerName}.png")) as BitmapSource;
icons.rightController = ConvertBitmapToImageSource(GetImageBitmap($"Assets/Images/{folder}/{rightControllerName}.png")) as BitmapSource;
icons.headsetCharging = ConvertBitmapToImageSource(GetImageBitmap($"Assets/Images/{folder}/headset_charging.png")) as BitmapSource;
icons.companyLogo = ConvertBitmapToImageSource(GetImageBitmap($"Assets/Images/{folder}/logo.png"));
}
private static System.Drawing.Bitmap GetImageBitmap(string path)
{
return new System.Drawing.Bitmap(GetImageFileStream(path));
}
private static Stream GetImageFileStream(string path)
{
System.Windows.Resources.StreamResourceInfo res = Application.GetResourceStream(new Uri(path, UriKind.RelativeOrAbsolute));
return res.Stream;
}
private static void InitGradient()
{
blueSolid.Color = Color.FromRgb(55, 152, 231);
blueGradientBrush = new LinearGradientBrush();
{
GradientStop stop1 = new GradientStop(Color.FromRgb(34, 94, 206), 0);
GradientStop stop2 = new GradientStop(Color.FromRgb(55, 152, 231), 1);
blueGradientBrush.GradientStops.Add(stop1);
blueGradientBrush.GradientStops.Add(stop2);
}
greenSolid.Color = Color.FromRgb(76, 199, 48);
greenGradientBrush = new LinearGradientBrush();
{
GradientStop stop1 = new GradientStop(Color.FromRgb(24, 178, 79), 0);
GradientStop stop2 = new GradientStop(Color.FromRgb(76, 199, 48), 1);
greenGradientBrush.GradientStops.Add(stop1);
greenGradientBrush.GradientStops.Add(stop2);
}
yellowSolid.Color = Color.FromRgb(199, 193, 48);
yellowGradientBrush = new LinearGradientBrush();
{
GradientStop stop1 = new GradientStop(Color.FromRgb(178, 172, 24), 0);
GradientStop stop2 = new GradientStop(Color.FromRgb(199, 193, 48), 1);
yellowGradientBrush.GradientStops.Add(stop1);
yellowGradientBrush.GradientStops.Add(stop2);
}
redSolid.Color = Color.FromRgb(199, 76, 48);
redGradientBrush = new LinearGradientBrush();
{
GradientStop stop1 = new GradientStop(Color.FromRgb(178, 24, 79), 0);
GradientStop stop2 = new GradientStop(Color.FromRgb(199, 76, 48), 1);
redGradientBrush.GradientStops.Add(stop1);
redGradientBrush.GradientStops.Add(stop2);
}
greySolid.Color = Color.FromRgb(100, 100, 100);
greyGradientBrush = new LinearGradientBrush();
{
GradientStop stop1 = new GradientStop(Color.FromRgb(150, 150, 150), 0);
GradientStop stop2 = new GradientStop(Color.FromRgb(100, 100, 100), 1);
greyGradientBrush.GradientStops.Add(stop1);
greyGradientBrush.GradientStops.Add(stop2);
}
}
private static ImageSource ConvertBitmapToImageSource(System.Drawing.Bitmap bitmap)
{
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray());
bitmapImage.EndInit();
return bitmapImage;
}
}
}