-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMessageCenter.ShadowAndOutline.cs
99 lines (79 loc) · 4.17 KB
/
MessageCenter.ShadowAndOutline.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
using UnityEngine;
namespace BepInEx
{
/// <summary>
/// Utilities for drawing IMGUI elements like labels with outlines around them.
/// </summary>
internal static class ShadowAndOutline
{
/// <summary>
/// Draw a label with an outline
/// </summary>
/// <param name="rect">Size of the control</param>
/// <param name="text">Text of the label</param>
/// <param name="style">Style to be applied to the label</param>
/// <param name="txtColor">Color of the text</param>
/// <param name="outlineColor">Color of the outline</param>
/// <param name="outlineThickness">Thickness of the outline in pixels</param>
public static void DrawOutline(Rect rect, string text, GUIStyle style, Color txtColor, Color outlineColor, int outlineThickness)
{
var backupColor = style.normal.textColor;
//Color backupGuiColor = GUI.color;
style.normal.textColor = outlineColor;
GUI.color = outlineColor;
var baseRect = rect;
rect.x -= outlineThickness;
rect.y -= outlineThickness;
while (rect.x++ < baseRect.x + outlineThickness)
GUI.Label(rect, text, style);
rect.x--;
while (rect.y++ < baseRect.y + outlineThickness)
GUI.Label(rect, text, style);
rect.y--;
while (rect.x-- > baseRect.x - outlineThickness)
GUI.Label(rect, text, style);
rect.x++;
while (rect.y-- > baseRect.y - outlineThickness)
GUI.Label(rect, text, style);
style.normal.textColor = txtColor;
//GUI.color = backupGuiColor;
GUI.Label(baseRect, text, style);
style.normal.textColor = backupColor;
}
/// <summary>
/// Draw a label with a shadow
/// </summary>
/// <param name="rect">Size of the control</param>
/// <param name="content">Contents of the label</param>
/// <param name="style">Style to be applied to the label</param>
/// <param name="txtColor">Color of the outline</param>
/// <param name="shadowColor">Color of the text</param>
/// <param name="shadowOffset">Offset of the shadow in pixels</param>
public static void DrawShadow(Rect rect, GUIContent content, GUIStyle style, Color txtColor, Color shadowColor, Vector2 shadowOffset)
{
var backupColor = style.normal.textColor;
style.normal.textColor = shadowColor;
rect.x += shadowOffset.x;
rect.y += shadowOffset.y;
GUI.Label(rect, content, style);
style.normal.textColor = txtColor;
rect.x -= shadowOffset.x;
rect.y -= shadowOffset.y;
GUI.Label(rect, content, style);
style.normal.textColor = backupColor;
}
public static void DrawLayoutShadow(GUIContent content, GUIStyle style, Color txtColor, Color shadowColor, Vector2 direction, params GUILayoutOption[] options) => DrawShadow(GUILayoutUtility.GetRect(content, style, options), content, style, txtColor, shadowColor, direction);
public static bool DrawButtonWithShadow(Rect r, GUIContent content, GUIStyle style, float shadowAlpha, Vector2 direction)
{
GUIStyle letters = new GUIStyle(style);
letters.normal.background = null;
letters.hover.background = null;
letters.active.background = null;
bool result = GUI.Button(r, content, style);
Color color = r.Contains(Event.current.mousePosition) ? letters.hover.textColor : letters.normal.textColor;
DrawShadow(r, content, letters, color, new Color(0f, 0f, 0f, shadowAlpha), direction);
return result;
}
public static bool DrawLayoutButtonWithShadow(GUIContent content, GUIStyle style, float shadowAlpha, Vector2 direction, params GUILayoutOption[] options) => DrawButtonWithShadow(GUILayoutUtility.GetRect(content, style, options), content, style, shadowAlpha, direction);
}
}