-
Notifications
You must be signed in to change notification settings - Fork 841
Expand file tree
/
Copy pathdframe.lua
More file actions
260 lines (167 loc) · 6.33 KB
/
dframe.lua
File metadata and controls
260 lines (167 loc) · 6.33 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
local PANEL = {}
AccessorFunc( PANEL, "m_bIsMenuComponent", "IsMenu", FORCE_BOOL )
AccessorFunc( PANEL, "m_bDraggable", "Draggable", FORCE_BOOL )
AccessorFunc( PANEL, "m_bSizable", "Sizable", FORCE_BOOL )
AccessorFunc( PANEL, "m_bScreenLock", "ScreenLock", FORCE_BOOL )
AccessorFunc( PANEL, "m_bDeleteOnClose", "DeleteOnClose", FORCE_BOOL )
AccessorFunc( PANEL, "m_bPaintShadow", "PaintShadow", FORCE_BOOL )
AccessorFunc( PANEL, "m_iMinWidth", "MinWidth", FORCE_NUMBER )
AccessorFunc( PANEL, "m_iMinHeight", "MinHeight", FORCE_NUMBER )
AccessorFunc( PANEL, "m_bBackgroundBlur", "BackgroundBlur", FORCE_BOOL )
function PANEL:Init()
self:SetFocusTopLevel( true )
--self:SetCursor( "sizeall" )
self:SetPaintShadow( true )
self.btnClose = vgui.Create( "DButton", self )
self.btnClose:SetText( "" )
self.btnClose.DoClick = function ( button ) self:Close() end
self.btnClose.Paint = function( panel, w, h ) derma.SkinHook( "Paint", "WindowCloseButton", panel, w, h ) end
self.btnMaxim = vgui.Create( "DButton", self )
self.btnMaxim:SetText( "" )
self.btnMaxim.DoClick = function ( button ) self:Close() end
self.btnMaxim.Paint = function( panel, w, h ) derma.SkinHook( "Paint", "WindowMaximizeButton", panel, w, h ) end
self.btnMaxim:SetEnabled( false )
self.btnMinim = vgui.Create( "DButton", self )
self.btnMinim:SetText( "" )
self.btnMinim.DoClick = function ( button ) self:Close() end
self.btnMinim.Paint = function( panel, w, h ) derma.SkinHook( "Paint", "WindowMinimizeButton", panel, w, h ) end
self.btnMinim:SetEnabled( false )
self.lblTitle = vgui.Create( "DLabel", self )
self.lblTitle.UpdateColours = function( label, skin )
if ( self:IsActive() ) then return label:SetTextStyleColor( skin.Colours.Window.TitleActive ) end
return label:SetTextStyleColor( skin.Colours.Window.TitleInactive )
end
self:SetDraggable( true )
self:SetSizable( false )
self:SetScreenLock( false )
self:SetDeleteOnClose( true )
self:SetTitle( "Window" )
self:SetMinWidth( 50 )
self:SetMinHeight( 50 )
-- This turns off the engine drawing
self:SetPaintBackgroundEnabled( false )
self:SetPaintBorderEnabled( false )
self.m_fCreateTime = SysTime()
self:DockPadding( 5, 24 + 5, 5, 5 )
end
function PANEL:ShowCloseButton( bShow )
self.btnClose:SetVisible( bShow )
self.btnMaxim:SetVisible( bShow )
self.btnMinim:SetVisible( bShow )
end
function PANEL:GetTitle()
return self.lblTitle:GetText()
end
function PANEL:SetTitle( strTitle )
self.lblTitle:SetText( strTitle )
end
function PANEL:Close()
self:SetVisible( false )
if ( self:GetDeleteOnClose() ) then
self:Remove()
end
self:OnClose()
end
function PANEL:OnClose()
end
function PANEL:Center()
self:InvalidateLayout( true )
self:CenterVertical()
self:CenterHorizontal()
end
function PANEL:IsActive()
if ( self:HasFocus() ) then return true end
if ( vgui.FocusedHasParent( self ) ) then return true end
return false
end
function PANEL:SetIcon( str )
if ( !str && IsValid( self.imgIcon ) ) then
return self.imgIcon:Remove() -- We are instructed to get rid of the icon, do it and bail.
end
if ( !IsValid( self.imgIcon ) ) then
self.imgIcon = vgui.Create( "DImage", self )
end
if ( IsValid( self.imgIcon ) ) then
self.imgIcon:SetMaterial( Material( str ) )
end
end
function PANEL:Think()
local mousex = math.Clamp( gui.MouseX(), 1, ScrW() - 1 )
local mousey = math.Clamp( gui.MouseY(), 1, ScrH() - 1 )
if ( self.Dragging ) then
local x = mousex - self.Dragging[1]
local y = mousey - self.Dragging[2]
-- Lock to screen bounds if screenlock is enabled
if ( self:GetScreenLock() ) then
x = math.Clamp( x, 0, ScrW() - self:GetWide() )
y = math.Clamp( y, 0, ScrH() - self:GetTall() )
end
self:SetPos( x, y )
end
if ( self.Sizing ) then
local x = mousex - self.Sizing[1]
local y = mousey - self.Sizing[2]
local px, py = self:GetPos()
if ( x < self.m_iMinWidth ) then x = self.m_iMinWidth elseif ( x > ScrW() - px && self:GetScreenLock() ) then x = ScrW() - px end
if ( y < self.m_iMinHeight ) then y = self.m_iMinHeight elseif ( y > ScrH() - py && self:GetScreenLock() ) then y = ScrH() - py end
self:SetSize( x, y )
self:SetCursor( "sizenwse" )
return
end
local screenX, screenY = self:LocalToScreen( 0, 0 )
if ( self.Hovered && self.m_bSizable && mousex > ( screenX + self:GetWide() - 20 ) && mousey > ( screenY + self:GetTall() - 20 ) ) then
self:SetCursor( "sizenwse" )
return
end
if ( self.Hovered && self:GetDraggable() && mousey < ( screenY + 24 ) ) then
self:SetCursor( "sizeall" )
return
end
self:SetCursor( "arrow" )
-- Don't allow the frame to go higher than 0
if ( self.y < 0 ) then
self:SetPos( self.x, 0 )
end
end
function PANEL:Paint( w, h )
if ( self.m_bBackgroundBlur ) then
Derma_DrawBackgroundBlur( self, self.m_fCreateTime )
end
derma.SkinHook( "Paint", "Frame", self, w, h )
return true
end
function PANEL:OnMousePressed()
local screenX, screenY = self:LocalToScreen( 0, 0 )
if ( self.m_bSizable && gui.MouseX() > ( screenX + self:GetWide() - 20 ) && gui.MouseY() > ( screenY + self:GetTall() - 20 ) ) then
self.Sizing = { gui.MouseX() - self:GetWide(), gui.MouseY() - self:GetTall() }
self:MouseCapture( true )
return
end
if ( self:GetDraggable() && gui.MouseY() < ( screenY + 24 ) ) then
self.Dragging = { gui.MouseX() - self.x, gui.MouseY() - self.y }
self:MouseCapture( true )
return
end
end
function PANEL:OnMouseReleased()
self.Dragging = nil
self.Sizing = nil
self:MouseCapture( false )
end
function PANEL:PerformLayout()
local titlePush = 0
if ( IsValid( self.imgIcon ) ) then
self.imgIcon:SetPos( 5, 5 )
self.imgIcon:SetSize( 16, 16 )
titlePush = 16
end
self.btnClose:SetPos( self:GetWide() - 31 - 4, 0 )
self.btnClose:SetSize( 31, 24 )
self.btnMaxim:SetPos( self:GetWide() - 31 * 2 - 4, 0 )
self.btnMaxim:SetSize( 31, 24 )
self.btnMinim:SetPos( self:GetWide() - 31 * 3 - 4, 0 )
self.btnMinim:SetSize( 31, 24 )
self.lblTitle:SetPos( 8 + titlePush, 2 )
self.lblTitle:SetSize( self:GetWide() - 25 - titlePush, 20 )
end
derma.DefineControl( "DFrame", "A simple window", PANEL, "EditablePanel" )