-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStyleBoxExtensions.cs
More file actions
47 lines (41 loc) · 1.51 KB
/
Copy pathStyleBoxExtensions.cs
File metadata and controls
47 lines (41 loc) · 1.51 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
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
using System.Numerics;
using Content.AL.UIKit.Colorspace;
using Content.AL.UIKit.Interfaces;
using Content.AL.UIKit.Styleboxes;
using Robust.Client.Graphics;
namespace Content.AL.UIKit;
[PublicAPI]
public static class StyleBoxExtensions
{
public static float Luminance(this StyleBox? box)
{
switch (box)
{
case StyleBoxFlat flat:
return new OklabColor(flat.BackgroundColor).L;
case StyleBoxTexture tex:
{
var texture = tex.Texture!;
var pix = texture.GetPixel(texture.Width / 2, texture.Height / 2) * tex.Modulate;
return new OklabColor(pix).L;
}
case IBrightnessAware b:
return b.Luminance();
case null:
return 0.0f;
default:
throw new NotImplementedException($"Not yet implemented for a stylebox of type {box.GetType()}");
}
}
public static StyleboxExtruded Extrude(this StyleBox box, Vector2 by, StyleBox? extrusion = default, Color? modulation = default)
{
var b = new StyleboxExtruded(box, by, extrusion, modulation);
return b;
}
public static StyleBoxHSkew Skew(this StyleBox box, Angle by)
{
return new StyleBoxHSkew(box, (float)by.Reduced().Theta);
}
}