Tooltip.cs
2.35 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
using UnityEngine;
namespace UnityEditor.Timeline
{
class Tooltip
{
public GUIStyle style { get; set; }
public string text { get; set; }
GUIStyle m_Font;
public GUIStyle font
{
get
{
if (m_Font != null)
return m_Font;
if (style != null)
return style;
// Default Font.
m_Font = new GUIStyle();
m_Font.font = EditorStyles.label.font;
return m_Font;
}
set { m_Font = value; }
}
float m_Pad = 4.0f;
public float pad
{
get { return m_Pad; }
set { m_Pad = value; }
}
GUIContent m_TextContent;
GUIContent textContent
{
get
{
if (m_TextContent == null)
m_TextContent = new GUIContent();
m_TextContent.text = text;
return m_TextContent;
}
}
Color m_ForeColor = Color.white;
public Color foreColor
{
get { return m_ForeColor; }
set { m_ForeColor = value; }
}
Rect m_Bounds;
public Rect bounds
{
get
{
var size = font.CalcSize(textContent);
m_Bounds.width = size.x + (2.0f * pad);
m_Bounds.height = size.y + 2.0f;
return m_Bounds;
}
set { m_Bounds = value; }
}
public Tooltip(GUIStyle theStyle, GUIStyle font)
{
style = theStyle;
m_Font = font;
}
public Tooltip()
{
style = null;
m_Font = null;
}
public void Draw()
{
if (string.IsNullOrEmpty(text))
return;
if (style != null)
{
using (new GUIColorOverride(DirectorStyles.Instance.customSkin.colorTooltipBackground))
GUI.Label(bounds, GUIContent.none, style);
}
var textBounds = bounds;
textBounds.x += pad;
textBounds.width -= pad;
using (new GUIColorOverride(foreColor))
GUI.Label(textBounds, textContent, font);
}
}
}