yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: ColorPicker Widget yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "ColorPicker", 22 yellowfive@57: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) yellowfive@57: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end yellowfive@57: yellowfive@57: -- Lua APIs yellowfive@57: local pairs = pairs yellowfive@57: yellowfive@57: -- WoW APIs yellowfive@57: local CreateFrame, UIParent = CreateFrame, UIParent yellowfive@57: yellowfive@57: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded yellowfive@57: -- List them here for Mikk's FindGlobals script yellowfive@57: -- GLOBALS: ShowUIPanel, HideUIPanel, ColorPickerFrame, OpacitySliderFrame yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Support functions yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function ColorCallback(self, r, g, b, a, isAlpha) yellowfive@57: if not self.HasAlpha then yellowfive@57: a = 1 yellowfive@57: end yellowfive@57: self:SetColor(r, g, b, a) yellowfive@57: if ColorPickerFrame:IsVisible() then yellowfive@57: --colorpicker is still open yellowfive@57: self:Fire("OnValueChanged", r, g, b, a) yellowfive@57: else yellowfive@57: --colorpicker is closed, color callback is first, ignore it, yellowfive@57: --alpha callback is the final call after it closes so confirm now yellowfive@57: if isAlpha then yellowfive@57: self:Fire("OnValueConfirmed", r, g, b, a) yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function Control_OnEnter(frame) yellowfive@57: frame.obj:Fire("OnEnter") yellowfive@57: end yellowfive@57: yellowfive@57: local function Control_OnLeave(frame) yellowfive@57: frame.obj:Fire("OnLeave") yellowfive@57: end yellowfive@57: yellowfive@57: local function ColorSwatch_OnClick(frame) yellowfive@57: HideUIPanel(ColorPickerFrame) yellowfive@57: local self = frame.obj yellowfive@57: if not self.disabled then yellowfive@57: ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG") yellowfive@57: ColorPickerFrame:SetFrameLevel(frame:GetFrameLevel() + 10) yellowfive@57: ColorPickerFrame:SetClampedToScreen(true) yellowfive@57: yellowfive@57: ColorPickerFrame.func = function() yellowfive@57: local r, g, b = ColorPickerFrame:GetColorRGB() yellowfive@57: local a = 1 - OpacitySliderFrame:GetValue() yellowfive@57: ColorCallback(self, r, g, b, a) yellowfive@57: end yellowfive@57: yellowfive@57: ColorPickerFrame.hasOpacity = self.HasAlpha yellowfive@57: ColorPickerFrame.opacityFunc = function() yellowfive@57: local r, g, b = ColorPickerFrame:GetColorRGB() yellowfive@57: local a = 1 - OpacitySliderFrame:GetValue() yellowfive@57: ColorCallback(self, r, g, b, a, true) yellowfive@57: end yellowfive@57: yellowfive@57: local r, g, b, a = self.r, self.g, self.b, self.a yellowfive@57: if self.HasAlpha then yellowfive@57: ColorPickerFrame.opacity = 1 - (a or 0) yellowfive@57: end yellowfive@57: ColorPickerFrame:SetColorRGB(r, g, b) yellowfive@57: yellowfive@57: ColorPickerFrame.cancelFunc = function() yellowfive@57: ColorCallback(self, r, g, b, a, true) yellowfive@57: end yellowfive@57: yellowfive@57: ShowUIPanel(ColorPickerFrame) yellowfive@57: end yellowfive@57: AceGUI:ClearFocus() yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Methods yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local methods = { yellowfive@57: ["OnAcquire"] = function(self) yellowfive@57: self:SetHeight(24) yellowfive@57: self:SetWidth(200) yellowfive@57: self:SetHasAlpha(false) yellowfive@57: self:SetColor(0, 0, 0, 1) yellowfive@57: self:SetDisabled(nil) yellowfive@57: self:SetLabel(nil) yellowfive@57: end, yellowfive@57: yellowfive@57: -- ["OnRelease"] = nil, yellowfive@57: yellowfive@57: ["SetLabel"] = function(self, text) yellowfive@57: self.text:SetText(text) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetColor"] = function(self, r, g, b, a) yellowfive@57: self.r = r yellowfive@57: self.g = g yellowfive@57: self.b = b yellowfive@57: self.a = a or 1 yellowfive@57: self.colorSwatch:SetVertexColor(r, g, b, a) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetHasAlpha"] = function(self, HasAlpha) yellowfive@57: self.HasAlpha = HasAlpha yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetDisabled"] = function(self, disabled) yellowfive@57: self.disabled = disabled yellowfive@57: if self.disabled then yellowfive@57: self.frame:Disable() yellowfive@57: self.text:SetTextColor(0.5, 0.5, 0.5) yellowfive@57: else yellowfive@57: self.frame:Enable() yellowfive@57: self.text:SetTextColor(1, 1, 1) yellowfive@57: end yellowfive@57: end yellowfive@57: } yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Constructor yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function Constructor() yellowfive@57: local frame = CreateFrame("Button", nil, UIParent) yellowfive@57: frame:Hide() yellowfive@57: yellowfive@57: frame:EnableMouse(true) yellowfive@57: frame:SetScript("OnEnter", Control_OnEnter) yellowfive@57: frame:SetScript("OnLeave", Control_OnLeave) yellowfive@57: frame:SetScript("OnClick", ColorSwatch_OnClick) yellowfive@57: yellowfive@57: local colorSwatch = frame:CreateTexture(nil, "OVERLAY") yellowfive@57: colorSwatch:SetWidth(19) yellowfive@57: colorSwatch:SetHeight(19) yellowfive@57: colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") yellowfive@57: colorSwatch:SetPoint("LEFT") yellowfive@57: yellowfive@57: local texture = frame:CreateTexture(nil, "BACKGROUND") yellowfive@57: texture:SetWidth(16) yellowfive@57: texture:SetHeight(16) yellowfive@57: texture:SetTexture(1, 1, 1) yellowfive@57: texture:SetPoint("CENTER", colorSwatch) yellowfive@57: texture:Show() yellowfive@57: yellowfive@57: local checkers = frame:CreateTexture(nil, "BACKGROUND") yellowfive@57: checkers:SetWidth(14) yellowfive@57: checkers:SetHeight(14) yellowfive@57: checkers:SetTexture("Tileset\\Generic\\Checkers") yellowfive@57: checkers:SetTexCoord(.25, 0, 0.5, .25) yellowfive@57: checkers:SetDesaturated(true) yellowfive@57: checkers:SetVertexColor(1, 1, 1, 0.75) yellowfive@57: checkers:SetPoint("CENTER", colorSwatch) yellowfive@57: checkers:Show() yellowfive@57: yellowfive@57: local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight") yellowfive@57: text:SetHeight(24) yellowfive@57: text:SetJustifyH("LEFT") yellowfive@57: text:SetTextColor(1, 1, 1) yellowfive@57: text:SetPoint("LEFT", colorSwatch, "RIGHT", 2, 0) yellowfive@57: text:SetPoint("RIGHT") yellowfive@57: yellowfive@57: --local highlight = frame:CreateTexture(nil, "HIGHLIGHT") yellowfive@57: --highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") yellowfive@57: --highlight:SetBlendMode("ADD") yellowfive@57: --highlight:SetAllPoints(frame) yellowfive@57: yellowfive@57: local widget = { yellowfive@57: colorSwatch = colorSwatch, yellowfive@57: text = text, yellowfive@57: frame = frame, yellowfive@57: type = Type yellowfive@57: } yellowfive@57: for method, func in pairs(methods) do yellowfive@57: widget[method] = func yellowfive@57: end yellowfive@57: yellowfive@57: return AceGUI:RegisterAsWidget(widget) yellowfive@57: end yellowfive@57: yellowfive@57: AceGUI:RegisterWidgetType(Type, Constructor, Version)