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