-
Notifications
You must be signed in to change notification settings - Fork 3
/
DResizableDock.lua
108 lines (83 loc) · 2.12 KB
/
DResizableDock.lua
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
local PANEL = {}
PANEL.Grip = 6
PANEL.Padding = 0
function PANEL:Init()
self:SetMouseInputEnabled( true )
-- self:SetPaintBackground( false )
self:SetSize( 64, 64 )
end
function PANEL:Setup( side, panel, tall )
self:SetSide( side )
self:SetTall( tall )
panel:SetParent( self )
panel:Dock( FILL )
end
function PANEL:SetSide( side )
self.Align = side
self.IsVertical = (side == LEFT or side == RIGHT)
self:SetGripSize( 4 )
return self
end
function PANEL:SetGripSize( size )
self.Grip = size
local align = self.Align
local padding = self.Padding
if align == TOP then
self:DockPadding( padding, padding, padding, size )
elseif align == RIGHT then
self:DockPadding( size, padding, padding, padding )
elseif align == LEFT then
self:DockPadding( padding, padding, size, padding )
elseif align == BOTTOM then
self:DockPadding( padding, size, padding, padding )
end
self:Dock( align )
end
function PANEL:CanSizeAt( x, y )
local align = self.Align
local grip = self.Grip
if align == TOP then
return y >= self:GetTall() - grip
elseif align == RIGHT then
return x <= grip
elseif align == LEFT then
return x >= self:GetWide() - grip
elseif align == BOTTOM then
return y <= grip
end
end
function PANEL:Paint()
end
function PANEL:OnMousePressed( code )
if code != MOUSE_LEFT then return end
local x, y = self:ScreenToLocal( gui.MousePos() )
if self:CanSizeAt( x, y ) then
self.Resizing = true
self:MouseCapture( true )
end
end
function PANEL:OnMouseReleased( code )
if code != MOUSE_LEFT then return end
self.Resizing = false
self:MouseCapture( false )
end
function PANEL:OnCursorMoved( x, y )
if self.Resizing then
local align = self.Align
if align == TOP then
self:SetTall( y )
elseif align == RIGHT then
self:SetWide( self:GetWide() - x )
elseif align == LEFT then
self:SetWide( x )
elseif align == BOTTOM then
self:SetTall( self:GetTall() - y )
end
end
if self.Resizing or self:CanSizeAt( x, y ) then
self:SetCursor( self.IsVertical and "sizewe" or "sizens" )
else
self:SetCursor( "arrow" )
end
end
vgui.Register( "DResizableDock", PANEL, "DPanel" )