2023-12-06 02:13:01 -05:00
|
|
|
|
|
|
|
local tall = 12
|
|
|
|
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 )
|
|
|
|
|
|
|
|
PANEL.Title = "No title"
|
|
|
|
|
|
|
|
function PANEL:Init()
|
|
|
|
|
|
|
|
self:SetFocusTopLevel( true )
|
|
|
|
|
|
|
|
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 )
|
2023-12-06 20:50:04 -05:00
|
|
|
surface.SetDrawColor( schema( "fg" ) )
|
2023-12-06 02:13:01 -05:00
|
|
|
surface.DrawRect( 0, 0, w, h )
|
|
|
|
|
2023-12-06 20:50:04 -05:00
|
|
|
draw.SimpleText( "X", "Benny_10", ss(3.3), ss(0), schema_c( "bg" ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
|
2023-12-06 02:13:01 -05:00
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
self:SetDraggable( true )
|
|
|
|
self:SetSizable( false )
|
|
|
|
self:SetScreenLock( false )
|
|
|
|
self:SetDeleteOnClose( true )
|
|
|
|
self:SetTitle( "Window" )
|
|
|
|
|
|
|
|
self:SetMinWidth( ss(50) )
|
|
|
|
self:SetMinHeight( ss(50) )
|
|
|
|
|
|
|
|
-- This turns off the engine drawing
|
|
|
|
self:SetPaintBackgroundEnabled( false )
|
|
|
|
self:SetPaintBorderEnabled( false )
|
|
|
|
|
|
|
|
self.m_fCreateTime = SysTime()
|
|
|
|
|
|
|
|
self:DockPadding( ss(2), ss(2+tall), ss(2), ss(2) )
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:ShowCloseButton( bShow )
|
|
|
|
self.btnClose:SetVisible( bShow )
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:GetTitle()
|
|
|
|
return self.Title
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:SetTitle( strTitle )
|
|
|
|
self.Title = 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: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 + ss(16) ) ) 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 )
|
|
|
|
surface.SetDrawColor( schema( "bg" ) )
|
|
|
|
surface.DrawRect( 0, 0, w, h )
|
|
|
|
|
|
|
|
surface.SetDrawColor( schema( "fg" ) )
|
2023-12-06 20:50:04 -05:00
|
|
|
surface.DrawOutlinedRect( 0, 0, w, ss(tall), ss(0.5) )
|
2023-12-06 02:13:01 -05:00
|
|
|
|
2023-12-06 20:50:04 -05:00
|
|
|
draw.SimpleText( self.Title, "Benny_12", ss(2), ss(1), schema_c( "fg" ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
|
2023-12-06 02:13:01 -05:00
|
|
|
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 + ss(tall) ) ) 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()
|
|
|
|
self.btnClose:SetPos( self:GetWide() - ss(12+2), ss(2) )
|
|
|
|
self.btnClose:SetSize( ss(12), ss(tall-4) )
|
|
|
|
end
|
|
|
|
|
|
|
|
derma.DefineControl( "BFrame", "A simple window", PANEL, "EditablePanel" )
|