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