1 --[[-----------------------------------------------------------------------------
3 -------------------------------------------------------------------------------]]
4 local Type, Version = "ColorPicker", 21
5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
12 local CreateFrame, UIParent = CreateFrame, UIParent
14 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
15 -- List them here for Mikk's FindGlobals script
16 -- GLOBALS: ShowUIPanel, HideUIPanel, ColorPickerFrame, OpacitySliderFrame
18 --[[-----------------------------------------------------------------------------
20 -------------------------------------------------------------------------------]]
21 local function ColorCallback(self, r, g, b, a, isAlpha)
22 if not self.HasAlpha then
25 self:SetColor(r, g, b, a)
26 if ColorPickerFrame:IsVisible() then
27 --colorpicker is still open
28 self:Fire("OnValueChanged", r, g, b, a)
30 --colorpicker is closed, color callback is first, ignore it,
31 --alpha callback is the final call after it closes so confirm now
33 self:Fire("OnValueConfirmed", r, g, b, a)
38 --[[-----------------------------------------------------------------------------
40 -------------------------------------------------------------------------------]]
41 local function Control_OnEnter(frame)
42 frame.obj:Fire("OnEnter")
45 local function Control_OnLeave(frame)
46 frame.obj:Fire("OnLeave")
49 local function ColorSwatch_OnClick(frame)
50 HideUIPanel(ColorPickerFrame)
51 local self = frame.obj
52 if not self.disabled then
53 ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG")
54 ColorPickerFrame:SetClampedToScreen(true)
56 ColorPickerFrame.func = function()
57 local r, g, b = ColorPickerFrame:GetColorRGB()
58 local a = 1 - OpacitySliderFrame:GetValue()
59 ColorCallback(self, r, g, b, a)
62 ColorPickerFrame.hasOpacity = self.HasAlpha
63 ColorPickerFrame.opacityFunc = function()
64 local r, g, b = ColorPickerFrame:GetColorRGB()
65 local a = 1 - OpacitySliderFrame:GetValue()
66 ColorCallback(self, r, g, b, a, true)
69 local r, g, b, a = self.r, self.g, self.b, self.a
71 ColorPickerFrame.opacity = 1 - (a or 0)
73 ColorPickerFrame:SetColorRGB(r, g, b)
75 ColorPickerFrame.cancelFunc = function()
76 ColorCallback(self, r, g, b, a, true)
79 ShowUIPanel(ColorPickerFrame)
84 --[[-----------------------------------------------------------------------------
86 -------------------------------------------------------------------------------]]
88 ["OnAcquire"] = function(self)
91 self:SetHasAlpha(false)
92 self:SetColor(0, 0, 0, 1)
97 -- ["OnRelease"] = nil,
99 ["SetLabel"] = function(self, text)
100 self.text:SetText(text)
103 ["SetColor"] = function(self, r, g, b, a)
108 self.colorSwatch:SetVertexColor(r, g, b, a)
111 ["SetHasAlpha"] = function(self, HasAlpha)
112 self.HasAlpha = HasAlpha
115 ["SetDisabled"] = function(self, disabled)
116 self.disabled = disabled
117 if self.disabled then
119 self.text:SetTextColor(0.5, 0.5, 0.5)
122 self.text:SetTextColor(1, 1, 1)
127 --[[-----------------------------------------------------------------------------
129 -------------------------------------------------------------------------------]]
130 local function Constructor()
131 local frame = CreateFrame("Button", nil, UIParent)
134 frame:EnableMouse(true)
135 frame:SetScript("OnEnter", Control_OnEnter)
136 frame:SetScript("OnLeave", Control_OnLeave)
137 frame:SetScript("OnClick", ColorSwatch_OnClick)
139 local colorSwatch = frame:CreateTexture(nil, "OVERLAY")
140 colorSwatch:SetWidth(19)
141 colorSwatch:SetHeight(19)
142 colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch")
143 colorSwatch:SetPoint("LEFT")
145 local texture = frame:CreateTexture(nil, "BACKGROUND")
147 texture:SetHeight(16)
148 texture:SetTexture(1, 1, 1)
149 texture:SetPoint("CENTER", colorSwatch)
152 local checkers = frame:CreateTexture(nil, "BACKGROUND")
153 checkers:SetWidth(14)
154 checkers:SetHeight(14)
155 checkers:SetTexture("Tileset\\Generic\\Checkers")
156 checkers:SetTexCoord(.25, 0, 0.5, .25)
157 checkers:SetDesaturated(true)
158 checkers:SetVertexColor(1, 1, 1, 0.75)
159 checkers:SetPoint("CENTER", colorSwatch)
162 local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight")
164 text:SetJustifyH("LEFT")
165 text:SetTextColor(1, 1, 1)
166 text:SetPoint("LEFT", colorSwatch, "RIGHT", 2, 0)
167 text:SetPoint("RIGHT")
169 --local highlight = frame:CreateTexture(nil, "HIGHLIGHT")
170 --highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
171 --highlight:SetBlendMode("ADD")
172 --highlight:SetAllPoints(frame)
175 colorSwatch = colorSwatch,
180 for method, func in pairs(methods) do
181 widget[method] = func
184 return AceGUI:RegisterAsWidget(widget)
187 AceGUI:RegisterWidgetType(Type, Constructor, Version)