Thread: Color picker
View Single Post
01-03-24, 11:21 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
The ColorPickerFrame primarily uses the ColorPickerFrame.func to tell something that is has been used to "select" a color (as the mouse drags across it etc..). You can use it with any widget that has a region that can change color (Texture, FontString) or to just to get the changed r, g, b values.

You can create a Button, make it look like anything then eg.
Lua Code:
  1. local function CancelColor()
  2.     local prevColor = ColorPickerFrame.previousValues
  3.     local colorBox = ColorPickerFrame.colorBox.Texture
  4.     colorBox:SetVertexColor(prevColor.r, prevColor.g, prevColor.b)
  5. end
  6.  
  7. local function ColorChanged()
  8.     local r, g, b = ColorPickerFrame:GetColorRGB()
  9.     local colorBox = ColorPickerFrame.colorBox.Texture
  10.     colorBox:SetVertexColor(r, g, b)
  11.     -- maybe save the settings to Saved Variables or ...?
  12. end
  13.  
  14. local f = CreateFrame("Button", ...) -- Create a button to open the ColorPicker
  15. f:SetSize(20, 20)
  16. f:SetPoint(...)
  17. f.Texture = f:CreateTexture()
  18. f.Texture:SetAllPoints()
  19. f.Texture:SetTexture("Interface\\BUTTONS\\WHITE8X8")-- just a white square but could be anything (presumably white)
  20. f.Texture:SetVertexColor( some r, g, b settings possibly from SavedVariables)
  21.  
  22. f:SetScript("OnClick", function(self)
  23.     ColorPickerFrame.colorBox = self
  24.     local startColor = { r, g, b settings possibly copied from SavedVariables }
  25.     ColorPickerFrame.previousValues = startColor
  26.     ColorPickerFrame.cancelFunc = CancelColor
  27.     ColorPickerFrame.opacityFunc = ColorChanged
  28.     ColorPickerFrame.func = ColorChanged
  29.     ColorPickerFrame:SetColorRGB(startColor.r, startColor.g, startColor.b) -- Set the starting color of the ColorPickerFrame
  30.     ColorPickerFrame:ClearAllPoints()
  31.     ColorPickerFrame:SetPoint(...)
  32.     ColorPickerFrame:Show()
  33. end)

Just the basic basics. You would need to decide what to do to make it work for your situation (and fix any errors, cold coded).

If you want to use a different color picker maybe color picker advanced but I don't know how that one works but presumably the same...ish
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-03-24 at 12:09 PM.
  Reply With Quote