-
Notifications
You must be signed in to change notification settings - Fork 836
Expand file tree
/
Copy pathdmenubar.lua
More file actions
109 lines (75 loc) · 2.38 KB
/
dmenubar.lua
File metadata and controls
109 lines (75 loc) · 2.38 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
local PANEL = {}
AccessorFunc( PANEL, "m_bBackground", "PaintBackground", FORCE_BOOL )
AccessorFunc( PANEL, "m_bBackground", "DrawBackground", FORCE_BOOL ) -- deprecated
AccessorFunc( PANEL, "m_bIsMenuComponent", "IsMenu", FORCE_BOOL )
Derma_Hook( PANEL, "Paint", "Paint", "MenuBar" )
function PANEL:Init()
self:Dock( TOP )
self:SetTall( 24 )
self.Menus = {}
end
function PANEL:GetOpenMenu()
for k, v in pairs( self.Menus ) do
if ( v:IsVisible() ) then return v end
end
return nil
end
function PANEL:AddOrGetMenu( label )
if ( self.Menus[ label ] ) then return self.Menus[ label ] end
return self:AddMenu( label )
end
function PANEL:AddMenu( label )
local m = DermaMenu()
m:SetDeleteSelf( false )
m:SetDrawColumn( true )
m:Hide()
self.Menus[ label ] = m
local b = self:Add( "DButton" )
b:SetText( label )
b:Dock( LEFT )
b:DockMargin( 5, 0, 0, 0 )
b:SetIsMenu( true )
b:SetPaintBackground( false )
b:SizeToContentsX( 16 )
b.DoClick = function()
if ( m:IsVisible() ) then
m:Hide()
return
end
local x, y = b:LocalToScreen( 0, 0 )
m:Open( x, y + b:GetTall(), false, b )
end
b.OnCursorEntered = function()
local opened = self:GetOpenMenu()
if ( !IsValid( opened ) || opened == m ) then return end
opened:Hide()
b:DoClick()
end
return m
end
function PANEL:OnRemove()
for id, pnl in pairs( self.Menus ) do
pnl:Remove()
end
end
function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )
local pnl = vgui.Create( "Panel" )
pnl:Dock( FILL )
pnl:DockMargin( 2, 22, 2, 2 )
local ctrl = pnl:Add( ClassName )
local m = ctrl:AddMenu( "File" )
m:AddOption( "New", function() MsgN( "Chose New" ) end )
m:AddOption( "File", function() MsgN( "Chose File" ) end )
m:AddOption( "Exit", function() MsgN( "Chose Exit" ) end )
local m2 = ctrl:AddMenu( "Edit" )
m2:AddOption( "Copy", function() MsgN( "Chose Copy" ) end )
m2:AddOption( "Paste", function() MsgN( "Chose Paste" ) end )
m2:AddOption( "Blah", function() MsgN( "Chose Blah" ) end )
local sub = m:AddSubMenu( "Sub Menu" )
sub:SetDeleteSelf( false )
for i = 0, 5 do
sub:AddOption( "Option " .. i, function() MsgN( "Chose sub menu option " .. i ) end )
end
PropertySheet:AddSheet( ClassName, pnl, nil, true, true )
end
derma.DefineControl( "DMenuBar", "", PANEL, "DPanel" )