Thread Tools Display Modes
05-20-20, 12:22 PM   #1
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Colorpicker?

Can anybody tell me how to use this?
https://wow.gamepedia.com/Using_the_ColorPickerFrame
seems to be outdated (global ShowColorPicker() does not exist any more)
just as everything I could find on the forums...
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
05-20-20, 02:09 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
I've not played with it myself but this is Blizzards files for it which has changed at least once for at least the last 3 expansions.

https://www.townlong-yak.com/framexm...ickerFrame.xml

ShowColorPicker is on that page you linked .. it's one you code in yourself it seems.
__________________
  Reply With Quote
05-20-20, 04:22 PM   #3
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
You are right. I completely missed that definition of ShowColorPicker() further above on the wiki page. Thanks!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
07-12-20, 04:43 PM   #4
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Finally got back to this, and two questions arose:

Code:
function ShowColorPicker(r, g, b, a, changedCallback)
 ColorPickerFrame.hasOpacity, ColorPickerFrame.opacity = (a ~= nil), a;
 ColorPickerFrame.previousValues = {r,g,b,a};
 ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = 
  changedCallback, changedCallback, changedCallback;
 ColorPickerFrame:SetColorRGB(r,g,b);
 ColorPickerFrame:Hide(); -- Need to run the OnShow handler.
 ColorPickerFrame:Show();
end

local function myColorCallback(restore)
 local newR, newG, newB, newA;
 if restore then
  -- The user bailed, we extract the old color from the table created by ShowColorPicker.
  newR, newG, newB, newA = unpack(restore);
 else
  -- Something changed
  newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
 end
 
 -- Update our internal storage.
 print(newR, newG, newB, newA);
end

ShowColorPicker(r, g, b, a, myColorCallback);

1st Question:
Code:
local myPackedColor = {1, 1, 1, 1};
ShowColorPicker(unpack(myPackedColor), myColorCallback);
When I do this, ShowColorPicker() only gets the first return value of unpack() as its first argument, the second argument is already the myColorCallback function. Is there a correct way of doing this? For other functions like e.g. SetColorTexture(unpack(myPackedColor)) it works.


2nd Question:
Is there a way to pass additional arguments to the changedCallback function? Or do I have to do this with "public" variables?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
07-12-20, 08:09 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
1. The vararg needs to go at th end.
Code:
local function ShowColorPicker(changedCallback, r, g, b, a)
    ....
end
Code:
local myPackedColor = {1, 1, 1, 1};
ShowColorPicker(myColorCallback, unpack(myPackedColor));
2. I'm not sure what you mean by "public"
Code:
local function changedCallback(self)
   if self.WhatEveryYouWantToCheck == xxx then
   end
end
The above is pretty public but you could use either local variables or variables in your addon table if you wanted to set them in a different .lua module

Code:
local addonName, addonTable = ...
local a, b, c
local function changedCallback(self)
   if a == x and b = y and not c then
      ...
   end
   if addonTable.SomeVariable == x then
      ...
   end
end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-12-20 at 08:24 PM.
  Reply With Quote
07-13-20, 04:47 AM   #6
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Thanks for the reply!
Originally Posted by Fizzlemizz View Post
1. The vararg needs to go at th end.
Ah, that makes sense! :-)


Originally Posted by Fizzlemizz View Post
2. I'm not sure what you mean by "public"
What I tried to say was, that I would prefer passing something from ShowColorPicker() to changedCallback() in a variable that is only accessible by these two functions.
Originally Posted by Fizzlemizz View Post
Code:
local function changedCallback(self)
   if self.WhatEveryYouWantToCheck == xxx then
   end
end
What exactly is this "self" refering to here? The ColorPicker? In the example it seems like the only argument of the callback functions is "restore" if any. Or does this only apply to the cancelFunc?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
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
07-13-20, 02:39 PM   #8
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
All right. I mean, what I basically want to do is to use the color picker in several different places, changing a different color each time. So I have to let ColorPicker() know what variable it should change. Passing arguments to ColorPicker() like ColorPicker("variableName") ist straight forward, but my question was how I could pass "variableName" on to the callback functions.

Now I understand that I have to do this with another (what I called "public" as it can be accessed from anywhere in my addon) variable (be it ColorPicker.tmpVariableName or local tmpVariableName).

Thanks!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Colorpicker?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off