WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Color picker (https://www.wowinterface.com/forums/showthread.php?t=59750)

dragonflyy 01-03-24 10:34 AM

Color picker
 
Is there a way to embed the color picker into my own frame instead of using WoW's popup? Would I just have to look into the colorpicker.xml and recreate it for my own use, or is there another way?

Fizzlemizz 01-03-24 11:21 AM

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

insery 01-03-24 02:15 PM

What are you working on with the color picker? Have you considered using a different color picker, like Color Picker Advanced, for your project?

dragonflyy 01-04-24 01:15 AM

I actually changed what I am doing for this, so think you for the responses :)


All times are GMT -6. The time now is 11:12 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI