DColorCube/SetBaseRGB

From Garry's Mod
Jump to: navigation, search
 DColorCube:SetBaseRGB( )

Contents

DescriptionPanelFunc

Sets the base color and the color used to draw the color cube panel itself.

NOTE

Calling this when using a color that isn't 100% saturated and valued (HSVToColor with saturation and value set to 1) causes the color cube to look inaccurate compared to the color that's returned by methods like DColorCube:GetRGB and DColorCube:OnUserChanged. You should use DColorCube:SetColor instead

Arguments

table color

The base color to set, uses Color structure.

Examples

Example

Creates a background panel and color cube that controls the background color. Demonstrates how setting the base RGB explicitly can cause a disconnect between the color represented by the cube and the color output.

-- Background panel
BGPanel = vgui.Create("DPanel")
BGPanel:SetSize(200, 200)
BGPanel:Center()

-- Color cube
local color_cube = vgui.Create("DColorCube", BGPanel)
color_cube:SetSize(180, 180)
color_cube:Center()

-- Base color set to white
color_cube:SetBaseRGB(Color(255, 255, 255))

-- Called when the color is changed by user input
function color_cube:OnUserChanged(col)

	-- Update background panel color
	BGPanel:SetBackgroundColor(col)
	
end

Output:

Notice how the output/background color doesn't match the color where the slider is positioned.

DColorCube SetBaseRGB example1.png
Personal tools
Navigation