Originally Posted by LudiusMaximus
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)