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
|
local PANEL = {}
function PANEL:Init()
self.Hover = false
self.Pressed = false
self.Text = "No-Title Button"
self.ClickSound = "buttons/lightswitch2.wav"
self.ClickEnable = true
self.HoverSound = "common/bugreporter_succeeded.wav"
self.HoverEnable = false
self:SetText("")
self.SetText = function(s,txt) self.Text = txt end
end
function PANEL:OnCursorEntered()
self.Hover = true
if (self.HoverEnable) then surface.PlaySound(self.HoverSound) end
end
function PANEL:EnableHoverSound(bool)
self.HoverEnable = bool
end
function PANEL:SetHoverSound(sound)
self.HoverSound = sound
end
function PANEL:EnableClickSound(bool)
self.ClickEnable = bool
end
function PANEL:SetClickSound(sound)
self.ClickSound = sound
end
function PANEL:OnMousePressed()
self.Pressed = true
self:MouseCapture( true )
end
function PANEL:OnMouseReleased()
if (self.Pressed) then surface.PlaySound(self.ClickSound) self:DoClick() end
self.Pressed = false
self:MouseCapture( false )
end
function PANEL:OnCursorExited()
self.Hover = false
end
function PANEL:Paint(w,h)
if (self.Pressed) then DrawRect( 0 , 0 , w , h , MAIN_GREENCOLOR )
elseif (self.Hover) then DrawRect( 0 , 0 , w , h , MAIN_COLOR2 )
else DrawRect( 0 , 0 , w , h , MAIN_COLORD ) end
DrawText( self.Text, "Trebuchet18", w/2, h/2, MAIN_TEXTCOLOR, 1 )
end
function PANEL:PerformLayout()
end
vgui.Register( "MBButton", PANEL , "Button" )
|