fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosBugfixes + Dark Mode skina8034e9

v2.1.1b
2.2 KiB84 linesraw
1local PANEL = class.create("ToolTip", "BasePanel")
2
3PANEL:ACCESSOR("Enabled", "m_bEnabled", true)
4PANEL:ACCESSOR("ArrowX", "m_iArrowX", 0)
5PANEL:ACCESSOR("ArrowY", "m_iArrowY", 0)
6PANEL:ACCESSOR("TooltipColor", "m_cTooltipColor", color(240, 240, 240))
7
8function PANEL:ToolTip()
9	self:super() -- Initialize our baseclass
10	self:SetFocusable(false) -- Ignore focus
11
12	self:SetSize(256, 256)
13	self:DockPadding(8, 8, 8, 0)
14
15	self.m_pTitle = self:Add("Label")
16	self.m_pTitle:Dock(DOCK_TOP)
17	self.m_pTitle:SetLineHeight(0.75)
18
19	self.m_pTitle.Skin = function(this)
20		gui.skinHook("Init", "TooltipTitle", this)
21	end
22
23	self.m_pBody = self:Add("Label")
24	self.m_pBody:Dock(DOCK_FILL)
25	self.m_pBody:SetWrapped(true)
26	self.m_pBody:SetFont("fonts/melee.otf", 11)
27	self.m_pBody:SetLineHeight(0.75)
28	self.m_pBody:SetPos(8, 16+24)
29	self.m_pBody:SetSize(236, 228)
30
31	self.m_pBody.Skin = function(this)
32		gui.skinHook("Init", "TooltipBody", this)
33	end
34end
35
36function PANEL:Skin()
37	gui.skinHook("Init", "Tooltip", self)
38end
39
40function PANEL:SetArrowPos(x, y)
41	self.m_iArrowX = x
42	self.m_iArrowY = y
43end
44
45function PANEL:GetArrowPos()
46	return math.max(5, math.min(self:GetWidth() - 5, self.m_iArrowX)), math.max(5, math.min(self:GetHeight() - 5, self.m_iArrowY))
47end
48
49function PANEL:SetTitle(str)
50	self.m_pTitle:SetText(str)
51end
52
53function PANEL:SetBody(str)
54	self.m_pBody:SetText(str)
55	self.m_pBody:HeightToText()
56	self:SizeToChildren(false, true)
57end
58
59function PANEL:Paint(w, h)
60	graphics.setColor(color(0, 0, 0, 75))
61	graphics.roundRect(8, 8, w-8, h-8, 4)
62
63	graphics.setColor(color_black)
64	graphics.roundRect(4, 4, w-8, h-8, 4)
65
66	local s1 = 5.65685424949 -- sqrt(4^2+4^2)
67	local s2 = 7.07106781187 -- sqrt(5^2+5^2)
68
69	graphics.setColor(self.m_cTooltipColor)
70
71	graphics.push()
72	graphics.translate(self:GetArrowPos()) -- move relative (0,0) to (x,y)
73	graphics.rotate(math.rad(45)) -- rotate coordinate system around relative (0,0) (absolute (x,y))
74
75	graphics.setColor(color_black)
76	graphics.rectangle("fill", -s2/2, -s2/2, s2, s2) -- draw rectangle centered around relative (0,0)
77
78	graphics.setColor(self.m_cTooltipColor)
79	graphics.rectangle("fill", -s1/2, -s1/2, s1, s1) -- draw rectangle centered around relative (0,0)
80	graphics.pop()
81
82	graphics.setColor(self.m_cTooltipColor)
83	graphics.roundRect(5, 5, w-10, h-10, 4)
84end