How can I change the color surface.SetDrawColor with the help of DRGBPicker ?
[CODE]function panel()
Panel = vgui.Create( "DPanel" )
Panel:SetPos( 470, 320 )
Panel:SetSize( 400, 400 )
local But = vgui.Create( "DButton",Panel )
But:SetPos( 350, 10 )
But:SetText( "Close" )
But:SetSize( 40, 20 )
But.DoClick = function()
Panel:Remove()
end
local picker = vgui.Create( "DRGBPicker", Panel )
picker:SetPos( 5, 5 )
picker:SetSize( 30, 155 )
local cube = vgui.Create( "DColorCube", Panel )
cube:SetPos( 40, 5 )
cube:SetSize( 155, 155 )
function picker:OnChange( col )
local h = ColorToHSV( col )
local _, s, v = ColorToHSV( cube:GetRGB() )
col = HSVToColor( h, s, v )
cube:SetColor( col )
UpdateColors( col )
end
function cube:OnUserChanged( col )
UpdateColors( col )
end
function UpdateColors( col )
image:( col ) -- there
end
end
concommand.Add( "testpanel", panel)
function image()
surface.SetMaterial( Material( "server/image.png", "noclamp" ) )
surface.SetDrawColor(255, 255, 255, 255) -- This is
surface.DrawTexturedRect(15,15,256,256,256)
end
hook.Add( 'HUDPaint', 'image', image)
[/CODE]
You could create a new variable at the top of your code, like
[CODE]
local color = color_white
[/CODE]
Then just do
[CODE]
function UpdateColors( col )
color = col
end
[/CODE]
And then in the image() function do
[CODE]
surface.SetDrawColor(color.r, color.g, color.b, color.a)
[/CODE]
Or, if you want the full code:
[CODE]
local color = color_white -- Create the color variable (I set it as white for no reason in particular)
function panel() -- please make this function local :(
Panel = vgui.Create( "DPanel" ) -- please make this variable local :(
Panel:SetPos( 470, 320 )
Panel:SetSize( 400, 400 )
local But = vgui.Create( "DButton",Panel )
But:SetPos( 350, 10 )
But:SetText( "Close" )
But:SetSize( 40, 20 )
But.DoClick = function()
Panel:Remove()
end
local picker = vgui.Create( "DRGBPicker", Panel )
picker:SetPos( 5, 5 )
picker:SetSize( 30, 155 )
local cube = vgui.Create( "DColorCube", Panel )
cube:SetPos( 40, 5 )
cube:SetSize( 155, 155 )
function picker:OnChange( col )
local h = ColorToHSV( col )
local _, s, v = ColorToHSV( cube:GetRGB() )
col = HSVToColor( h, s, v )
cube:SetColor( col )
color = col -- Set the variable
end
function cube:OnUserChanged( col )
color = col -- Set the variable
end
end
concommand.Add( "testpanel", panel)
function image() -- please make this function local :(
surface.SetMaterial( Material( "server/image.png", "noclamp" ) )
surface.SetDrawColor(color.r, color.g, color.b, color.a) -- Get the r,g,b,a values of the variable
surface.DrawTexturedRect(15,15,256,256,256)
end
hook.Add( 'HUDPaint', 'image', image)
[/CODE]
(I shortened the code above by removing the function you created, since it wasn't really needed)
Sorry, you need to Log In to post a reply to this thread.