DColorCube/OnUserChanged

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

Contents

DescriptionPanelHook

Function which is called when the color cube slider is moved (through user input). Meant to be overridden.

Arguments

table color

The new color, uses Color structure.

Examples

Example

Creates a color cube which controls the blue saturation and value of a ball image.

-- Frame
MainFrame = vgui.Create("DFrame")
MainFrame:SetSize(320, 200)
MainFrame:Center()
MainFrame:SetTitle("Choose the saturation and value")

-- Image of a ball
local ball_img = vgui.Create("DImage", MainFrame)
ball_img:SetPos(20, 45)
ball_img:SetSize(128, 128)

ball_img:SetImage("sprites/sent_ball")

-- Color cube
local color_cube = vgui.Create("DColorCube", MainFrame)
color_cube:SetPos(160, 40)
color_cube:SetSize(150, 150)

-- Set color to blue
color_cube:SetColor(Color(0, 0, 255))

-- Called when slider is moved by user
function color_cube:OnUserChanged(col)
	
	-- Update ball color
	ball_img:SetImageColor(col)

end

Output:



DColorCube OnUserChanged example1.gif
Personal tools
Navigation