-
Notifications
You must be signed in to change notification settings - Fork 836
Expand file tree
/
Copy pathdcolorbutton.lua
More file actions
78 lines (47 loc) · 1.71 KB
/
dcolorbutton.lua
File metadata and controls
78 lines (47 loc) · 1.71 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
local PANEL = {}
local matGrid = Material( "gui/alpha_grid.png", "nocull" )
AccessorFunc( PANEL, "m_bBorder", "DrawBorder", FORCE_BOOL )
AccessorFunc( PANEL, "m_bSelected", "Selected", FORCE_BOOL )
AccessorFunc( PANEL, "m_Color", "Color" )
AccessorFunc( PANEL, "m_PanelID", "ID" )
function PANEL:Init()
self:SetSize( 10, 10 )
self:SetMouseInputEnabled( true )
self:SetText( "" )
self:SetCursor( "hand" )
self:SetZPos( 0 )
self:SetColor( Color( 255, 0, 255 ) )
end
function PANEL:IsDown()
return self.Depressed
end
function PANEL:SetColor( color, hideTooltip )
if ( !hideTooltip ) then
local colorStr = "R: " .. color.r .. "\nG: " .. color.g .. "\nB: " .. color.b .. "\nA: " .. color.a
self:SetTooltip( colorStr )
end
self.m_Color = color
end
function PANEL:Paint( w, h )
if ( self:GetColor().a < 255 ) then -- Grid for Alpha
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( matGrid )
local size = math.max( 128, math.max( w, h ) )
local x, y = w / 2 - size / 2, h / 2 - size / 2
surface.DrawTexturedRect( x, y , size, size )
end
local panelColor = self:GetColor()
surface.SetDrawColor( panelColor.r, panelColor.g, panelColor.b, panelColor.a )
self:DrawFilledRect()
surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( 0, 0, w, 1 )
surface.DrawRect( 0, 0, 1, h )
return false
end
function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )
local ctrl = vgui.Create( ClassName )
ctrl:SetSize( 64, 64 )
ctrl:SetColor( Color( 255, 0, 0, 128 ) )
PropertySheet:AddSheet( ClassName, ctrl, nil, true, true )
end
derma.DefineControl( "DColorButton", "A Color Button", PANEL, "DLabel" )