Thread: Colorpicker?
View Single Post
07-13-20, 10:08 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Originally Posted by LudiusMaximus View Post
What exactly is this "self" refering to here?
My bad, I was thinking of my derived ColourPicker button.

I guess the question becomes, what are you doing in ShowColorPicker to gather the variables you want to pass that you couldn't do directly in changedCallback?

If you're calling ShowColorPicker() as the result of a button click (like a target box to change colours as the picker changes), you can set the button as a key of the ColorPickerFrame.

Code:
local function myColorCallback()
    TextureToColour = ColorPickerFrame.colourBox
    local r, g, b = ColorPickerFrame:GetColorRGB()
    TextureToColour:SetVertexColor(r, g, b)
end

local function myColorCancel()
    TextureToColour = ColorPickerFrame.colourBox
    TextureToColour:SetVertexColor(unpack(TextureToColour.previousValues))
end

local function ShowColorPicker(self, r, g, b, a)
	self.previousValues = {r,g,b,a};
	ColorPickerFrame.colourBox = self
	ColorPickerFrame.hasOpacity, ColorPickerFrame.opacity = (a ~= nil), a;
	ColorPickerFrame:SetColorRGB(r,g,b);
	ColorPickerFrame.func, ColorPickerFrame.opacityFunc = myColorCallback, myColorCallback
	ColorPickerFrame.cancelFunc = myColorCancel
	ColorPickerFrame:Show()
end
local button = CreateFrame("Button", nil, UIParent)
button:SetSize(25, 25)
button:SetPoint("LEFT")
button.Texture = button:CreateTexture()
button.Texture:SetAllPoints()
button.Texture:SetTexture("Interface/BUTTONS/WHITE8X8")
button.Texture:SetVertexColor(1, 1, 0)
button:SetScript("OnClick", function(self)
	ShowColorPicker(self.Texture, self.Texture:GetVertexColor())
end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-13-20 at 12:48 PM.
  Reply With Quote