Garry's Mod Wiki

DColorPalette

Description

The DColorPalette allows the player to select a color from a list of given colors.
This panel supports saving across sessions via the panel cookie system.
Use Panel:SetCookieName to change "save files".

View source

Parent

Derives methods, etc not listed on this page from DIconLayout.

Implements

Implements or overrides the following hooks/methods. If you want to override these, you probably want to call the original function too.

Events

DColorPalette:OnValueChanged( table newcol )
Called when the color is changed after clicking a new value. For Override

Methods

DColorPalette:DoClick( table clr, Panel btn )
We advise against using this. It may be changed or removed in a future update. Basically the same functionality as DColorPalette:OnValueChanged, you should use that instead! For Override
number DColorPalette:GetButtonSize()
An AccessorFunc that returns the size of each palette button. Set by DColorPalette:SetButtonSize.
string DColorPalette:GetConVarA()
An AccessorFunc that returns the ConVar name for the alpha channel of the color. See also: DColorPalette:GetConVarR - For the red channel DColorPalette:GetConVarG - For the green channel DColorPalette:GetConVarB - For the blue channel
string DColorPalette:GetConVarB()
An AccessorFunc that returns the ConVar name for the blue channel of the color. See also: DColorPalette:GetConVarR - For the red channel DColorPalette:GetConVarG - For the green channel DColorPalette:GetConVarA - For the alpha channel
string DColorPalette:GetConVarG()
An AccessorFunc that returns the ConVar name for the green channel of the color. See also: DColorPalette:GetConVarR - For the red channel DColorPalette:GetConVarB - For the blue channel DColorPalette:GetConVarA - For the alpha channel
string DColorPalette:GetConVarR()
An AccessorFunc that returns the ConVar name for the red channel of the color. See also: DColorPalette:GetConVarG - For the green channel DColorPalette:GetConVarB - For the blue channel DColorPalette:GetConVarA - For the alpha channel
number DColorPalette:GetNumRows()
An AccessorFunc that returns the number of rows of the palette, provided 6 colors fill each row. This value is equal to the number of colors in the DColorPalette divided by 6.
DColorPalette:NetworkColorChange()
This is used internally - although you're able to use it you probably shouldn't. Used internally to make sure changes on one palette affect other palettes with same name.
DColorPalette:OnRightClickButton( Panel pnl )
Called when a palette button has been pressed. For Override
DColorPalette:Reset()
Resets this entire color palette to a default preset one, without saving. See DColorPalette:ResetSavedColors for version that also saves the changes.
DColorPalette:ResetSavedColors()
Resets this entire color palette to a default preset one and saves the changes. See DColorPalette:Reset for version that does not save the changes.
DColorPalette:SaveColor( Panel btn, table clr )
Saves the color of given button across sessions. The color is saved as a panel cookie, see Panel:SetCookie and Panel:SetCookieName. It is expected that the amount of colors per palette (Panel:SetCookieName) is the same every time.
DColorPalette:SetButtonSize( number size )
Sets the size of each palette button. This is best kept to such a number, where this equation would return a whole number: WidthOfColorPalette / ButtonSize= WholeNumber If not, there will be ugly whitespace on the right side of the panel.
DColorPalette:SetColor( table clr )
We advise against using this. It may be changed or removed in a future update. Currently does nothing. Intended to "select" the color.
DColorPalette:SetColorButtons( table tab )
Clears the palette and adds new buttons with given colors.
DColorPalette:SetConVarA( string convar )
An AccessorFunc that sets the ConVar name for the alpha channel of the color. See also: DColorPalette:SetConVarR - For the red channel DColorPalette:SetConVarG - For the green channel DColorPalette:SetConVarB - For the blue channel
DColorPalette:SetConVarB( string convar )
An AccessorFunc that sets the ConVar name for the blue channel of the color. See also: DColorPalette:SetConVarR - For the red channel DColorPalette:SetConVarG - For the green channel DColorPalette:SetConVarA - For the alpha channel
DColorPalette:SetConVarG( string convar )
An AccessorFunc that sets the ConVar name for the green channel of the color. See also: DColorPalette:SetConVarR - For the red channel DColorPalette:SetConVarB - For the blue channel DColorPalette:SetConVarA - For the alpha channel
DColorPalette:SetConVarR( string convar )
An AccessorFunc that sets the ConVar name for the red channel of the color. See also: DColorPalette:SetConVarG - For the green channel DColorPalette:SetConVarB - For the blue channel DColorPalette:SetConVarA - For the alpha channel
DColorPalette:SetNumRows( number rows )
Roughly sets the number of colors that can be picked by the user. If the DColorPalette is exactly 6 rows tall, this function will set the number of colors shown per row in the palette. This is an AccessorFunc DColorPalette:Reset or DColorPalette:ResetSavedColors must be called after this function to apply changes.
DColorPalette:UpdateConVar( string name, string key, table clr )
This is used internally - although you're able to use it you probably shouldn't. Internal helper function for DColorPalette:UpdateConVars.
DColorPalette:UpdateConVars( table clr )
This is used internally - although you're able to use it you probably shouldn't. Updates all the console variables set by DColorPalette:SetConVarR and so on with given color. Called internally when a palette color is clicked.

Example

Creates a DColorPalette in a DFrame, clicking on a color will change the DColorButton's color to the selected color

local Frame = vgui.Create( "DFrame" ) Frame:SetSize( 170, 200 ) Frame:Center() Frame:MakePopup() local DColorPalette = vgui.Create( "DColorPalette", Frame ) DColorPalette:SetPos( 5, 50 ) DColorPalette:SetSize( 160, 50 ) local DColorButton = vgui.Create( "DColorButton", Frame ) DColorButton:SetSize( 50, 50 ) DColorButton:SetPos( 60, 100 ) -- This function is assigned AFTER DColorButton is created so we can use the DColorButton DColorPalette.OnValueChanged = function( s, value ) DColorButton:SetColor( value ) end

Preview from the derma_controls concmd

image.png