Tercio@11: Tercio@11: local DF = _G ["DetailsFramework"] Tercio@11: Tercio@20: if (not DF or not DetailsFrameworkCanLoad) then Tercio@20: return Tercio@20: end Tercio@20: Tercio@11: local _ Tercio@11: local _rawset = rawset --> lua local Tercio@11: local _rawget = rawget --> lua local Tercio@11: local _setmetatable = setmetatable --> lua local Tercio@11: local _unpack = unpack --> lua local Tercio@11: local _type = type --> lua local Tercio@11: local _math_floor = math.floor --> lua local Tercio@11: local loadstring = loadstring --> lua local Tercio@11: Tercio@11: local cleanfunction = function() end Tercio@11: local APIButtonFunctions = false Tercio@11: local ButtonMetaFunctions = {} Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> metatables Tercio@11: Tercio@11: ButtonMetaFunctions.__call = function (_table, value, ...) Tercio@11: return self.func (_table.param1, _table.param2, value, ...) Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> members Tercio@11: Tercio@11: --> tooltip Tercio@11: local gmember_tooltip = function (_object) Tercio@11: return _object:GetTooltip() Tercio@11: end Tercio@11: --> shown Tercio@11: local gmember_shown = function (_object) Tercio@11: return _object:IsShown() Tercio@11: end Tercio@11: --> frame width Tercio@11: local gmember_width = function (_object) Tercio@11: return _object.button:GetWidth() Tercio@11: end Tercio@11: --> frame height Tercio@11: local gmember_height = function (_object) Tercio@11: return _object.button:GetHeight() Tercio@11: end Tercio@11: --> text Tercio@11: local gmember_text = function (_object) Tercio@11: return _object.button.text:GetText() Tercio@11: end Tercio@11: --> function Tercio@11: local gmember_function = function (_object) Tercio@11: return _rawget (_object, "func") Tercio@11: end Tercio@11: --> text color Tercio@11: local gmember_textcolor = function (_object) Tercio@11: return _object.button.text:GetTextColor() Tercio@11: end Tercio@11: --> text font Tercio@11: local gmember_textfont = function (_object) Tercio@11: local fontface = _object.button.text:GetFont() Tercio@11: return fontface Tercio@11: end Tercio@11: --> text size Tercio@11: local gmember_textsize = function (_object) Tercio@11: local _, fontsize = _object.button.text:GetFont() Tercio@11: return fontsize Tercio@11: end Tercio@11: --> texture Tercio@11: local gmember_texture = function (_object) Tercio@11: return {_object.button:GetNormalTexture(), _object.button:GetHighlightTexture(), _object.button:GetPushedTexture(), _object.button:GetDisabledTexture()} Tercio@11: end Tercio@11: --> locked Tercio@11: local gmember_locked = function (_object) Tercio@11: return _rawget (_object, "is_locked") Tercio@11: end Tercio@11: Tercio@11: local get_members_function_index = { Tercio@11: ["tooltip"] = gmember_tooltip, Tercio@11: ["shown"] = gmember_shown, Tercio@11: ["width"] = gmember_width, Tercio@11: ["height"] = gmember_height, Tercio@11: ["text"] = gmember_text, Tercio@11: ["clickfunction"] = gmember_function, Tercio@11: ["texture"] = gmember_texture, Tercio@11: ["locked"] = gmember_locked, Tercio@11: ["fontcolor"] = gmember_textcolor, Tercio@11: ["fontface"] = gmember_textfont, Tercio@11: ["fontsize"] = gmember_textsize, Tercio@11: ["textcolor"] = gmember_textcolor, --alias Tercio@11: ["textfont"] = gmember_textfont, --alias Tercio@11: ["textsize"] = gmember_textsize --alias Tercio@11: } Tercio@11: Tercio@11: ButtonMetaFunctions.__index = function (_table, _member_requested) Tercio@11: Tercio@11: local func = get_members_function_index [_member_requested] Tercio@11: if (func) then Tercio@11: return func (_table, _member_requested) Tercio@11: end Tercio@11: Tercio@11: local fromMe = _rawget (_table, _member_requested) Tercio@11: if (fromMe) then Tercio@11: return fromMe Tercio@11: end Tercio@11: Tercio@11: return ButtonMetaFunctions [_member_requested] Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------------------------------------------------------------- Tercio@11: Tercio@11: --> tooltip Tercio@11: local smember_tooltip = function (_object, _value) Tercio@11: return _object:SetTooltip (_value) Tercio@11: end Tercio@11: --> show Tercio@11: local smember_show = function (_object, _value) Tercio@11: if (_value) then Tercio@11: return _object:Show() Tercio@11: else Tercio@11: return _object:Hide() Tercio@11: end Tercio@11: end Tercio@11: --> hide Tercio@11: local smember_hide = function (_object, _value) Tercio@11: if (not _value) then Tercio@11: return _object:Show() Tercio@11: else Tercio@11: return _object:Hide() Tercio@11: end Tercio@11: end Tercio@11: --> frame width Tercio@11: local smember_width = function (_object, _value) Tercio@11: return _object.button:SetWidth (_value) Tercio@11: end Tercio@11: --> frame height Tercio@11: local smember_height = function (_object, _value) Tercio@11: return _object.button:SetHeight (_value) Tercio@11: end Tercio@11: --> text Tercio@11: local smember_text = function (_object, _value) Tercio@11: return _object.button.text:SetText (_value) Tercio@11: end Tercio@11: --> function Tercio@11: local smember_function = function (_object, _value) Tercio@11: return _rawset (_object, "func", _value) Tercio@11: end Tercio@11: --> text color Tercio@11: local smember_textcolor = function (_object, _value) Tercio@11: local _value1, _value2, _value3, _value4 = DF:ParseColors (_value) Tercio@11: return _object.button.text:SetTextColor (_value1, _value2, _value3, _value4) Tercio@11: end Tercio@11: --> text font Tercio@11: local smember_textfont = function (_object, _value) Tercio@11: return DF:SetFontFace (_object.button.text, _value) Tercio@11: end Tercio@11: --> text size Tercio@11: local smember_textsize = function (_object, _value) Tercio@11: return DF:SetFontSize (_object.button.text, _value) Tercio@11: end Tercio@11: --> texture Tercio@11: local smember_texture = function (_object, _value) Tercio@11: if (_type (_value) == "table") then Tercio@11: local _value1, _value2, _value3, _value4 = unpack (_value) Tercio@11: if (_value1) then Tercio@11: _object.button:SetNormalTexture (_value1) Tercio@11: end Tercio@11: if (_value2) then Tercio@11: _object.button:SetHighlightTexture (_value2, "ADD") Tercio@11: end Tercio@11: if (_value3) then Tercio@11: _object.button:SetPushedTexture (_value3) Tercio@11: end Tercio@11: if (_value4) then Tercio@11: _object.button:SetDisabledTexture (_value4) Tercio@11: end Tercio@11: else Tercio@11: _object.button:SetNormalTexture (_value) Tercio@11: _object.button:SetHighlightTexture (_value, "ADD") Tercio@11: _object.button:SetPushedTexture (_value) Tercio@11: _object.button:SetDisabledTexture (_value) Tercio@11: end Tercio@11: return Tercio@11: end Tercio@11: --> locked Tercio@11: local smember_locked = function (_object, _value) Tercio@11: if (_value) then Tercio@11: _object.button:SetMovable (false) Tercio@11: return _rawset (_object, "is_locked", true) Tercio@11: else Tercio@11: _object.button:SetMovable (true) Tercio@11: _rawset (_object, "is_locked", false) Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: --> text align Tercio@11: local smember_textalign = function (_object, _value) Tercio@11: if (_value == "left" or _value == "<") then Tercio@11: _object.button.text:SetPoint ("left", _object.button, "left", 2, 0) Tercio@11: _object.capsule_textalign = "left" Tercio@11: elseif (_value == "center" or _value == "|") then Tercio@11: _object.button.text:SetPoint ("center", _object.button, "center", 0, 0) Tercio@11: _object.capsule_textalign = "center" Tercio@11: elseif (_value == "right" or _value == ">") then Tercio@11: _object.button.text:SetPoint ("right", _object.button, "right", -2, 0) Tercio@11: _object.capsule_textalign = "right" Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local set_members_function_index = { Tercio@11: ["tooltip"] = smember_tooltip, Tercio@11: ["show"] = smember_show, Tercio@11: ["hide"] = smember_hide, Tercio@11: ["width"] = smember_width, Tercio@11: ["height"] = smember_height, Tercio@11: ["text"] = smember_text, Tercio@11: ["clickfunction"] = smember_function, Tercio@11: ["textcolor"] = smember_textcolor, Tercio@11: ["textfont"] = smember_textfont, Tercio@11: ["textsize"] = smember_textsize, Tercio@11: ["texture"] = smember_texture, Tercio@11: ["locked"] = smember_locked, Tercio@11: ["textalign"] = smember_textalign, Tercio@11: } Tercio@11: Tercio@11: ButtonMetaFunctions.__newindex = function (_table, _key, _value) Tercio@11: local func = set_members_function_index [_key] Tercio@11: if (func) then Tercio@11: return func (_table, _value) Tercio@11: else Tercio@11: return _rawset (_table, _key, _value) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> methods Tercio@11: Tercio@11: --> show & hide Tercio@11: function ButtonMetaFunctions:IsShown() Tercio@11: return self.button:IsShown() Tercio@11: end Tercio@11: function ButtonMetaFunctions:Show() Tercio@11: return self.button:Show() Tercio@11: end Tercio@11: function ButtonMetaFunctions:Hide() Tercio@11: return self.button:Hide() Tercio@11: end Tercio@11: Tercio@11: -- setpoint Tercio@11: function ButtonMetaFunctions:SetPoint (v1, v2, v3, v4, v5) Tercio@11: v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self) Tercio@11: if (not v1) then Tercio@11: error ("SetPoint: Invalid parameter.") Tercio@11: return Tercio@11: end Tercio@11: return self.widget:SetPoint (v1, v2, v3, v4, v5) Tercio@11: end Tercio@11: Tercio@11: -- sizes Tercio@11: function ButtonMetaFunctions:SetSize (w, h) Tercio@11: if (w) then Tercio@11: self.button:SetWidth (w) Tercio@11: end Tercio@11: if (h) then Tercio@11: return self.button:SetHeight (h) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- tooltip Tercio@11: function ButtonMetaFunctions:SetTooltip (tooltip) Tercio@11: if (tooltip) then Tercio@11: return _rawset (self, "have_tooltip", tooltip) Tercio@11: else Tercio@11: return _rawset (self, "have_tooltip", nil) Tercio@11: end Tercio@11: end Tercio@11: function ButtonMetaFunctions:GetTooltip() Tercio@11: return _rawget (self, "have_tooltip") Tercio@11: end Tercio@11: Tercio@11: -- functions Tercio@11: function ButtonMetaFunctions:SetClickFunction (func, param1, param2, clicktype) Tercio@11: if (not clicktype or string.find (string.lower (clicktype), "left")) then Tercio@11: if (func) then Tercio@11: _rawset (self, "func", func) Tercio@11: else Tercio@11: _rawset (self, "func", cleanfunction) Tercio@11: end Tercio@11: Tercio@11: if (param1 ~= nil) then Tercio@11: _rawset (self, "param1", param1) Tercio@11: end Tercio@11: if (param2 ~= nil) then Tercio@11: _rawset (self, "param2", param2) Tercio@11: end Tercio@11: Tercio@11: elseif (clicktype or string.find (string.lower (clicktype), "right")) then Tercio@11: if (func) then Tercio@11: _rawset (self, "funcright", func) Tercio@11: else Tercio@11: _rawset (self, "funcright", cleanfunction) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- text Tercio@11: function ButtonMetaFunctions:SetText (text) Tercio@11: if (text) then Tercio@11: self.button.text:SetText (text) Tercio@11: else Tercio@11: self.button.text:SetText (nil) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- textcolor Tercio@11: function ButtonMetaFunctions:SetTextColor (color, arg2, arg3, arg4) Tercio@11: if (arg2) then Tercio@11: return self.button.text:SetTextColor (color, arg2, arg3, arg4 or 1) Tercio@11: end Tercio@11: local _value1, _value2, _value3, _value4 = DF:ParseColors (color) Tercio@11: return self.button.text:SetTextColor (_value1, _value2, _value3, _value4) Tercio@11: end Tercio@11: Tercio@11: -- textsize Tercio@11: function ButtonMetaFunctions:SetTextSize (size) Tercio@11: return DF:SetFontSize (self.button.text, _value) Tercio@11: end Tercio@11: Tercio@11: -- textfont Tercio@11: function ButtonMetaFunctions:SetTextFont (font) Tercio@11: return DF:SetFontFace (_object.button.text, _value) Tercio@11: end Tercio@11: Tercio@11: -- textures Tercio@11: function ButtonMetaFunctions:SetTexture (normal, highlight, pressed, disabled) Tercio@11: if (normal) then Tercio@11: self.button:SetNormalTexture (normal) Tercio@11: elseif (_type (normal) ~= "boolean") then Tercio@11: self.button:SetNormalTexture (nil) Tercio@11: end Tercio@11: Tercio@11: if (_type (highlight) == "boolean") then Tercio@11: if (highlight and normal and _type (normal) ~= "boolean") then Tercio@11: self.button:SetHighlightTexture (normal, "ADD") Tercio@11: end Tercio@11: elseif (highlight == nil) then Tercio@11: self.button:SetHighlightTexture (nil) Tercio@11: else Tercio@11: self.button:SetHighlightTexture (highlight, "ADD") Tercio@11: end Tercio@11: Tercio@11: if (_type (pressed) == "boolean") then Tercio@11: if (pressed and normal and _type (normal) ~= "boolean") then Tercio@11: self.button:SetPushedTexture (normal) Tercio@11: end Tercio@11: elseif (pressed == nil) then Tercio@11: self.button:SetPushedTexture (nil) Tercio@11: else Tercio@11: self.button:SetPushedTexture (pressed, "ADD") Tercio@11: end Tercio@11: Tercio@11: if (_type (disabled) == "boolean") then Tercio@11: if (disabled and normal and _type (normal) ~= "boolean") then Tercio@11: self.button:SetDisabledTexture (normal) Tercio@11: end Tercio@11: elseif (disabled == nil) then Tercio@11: self.button:SetDisabledTexture (nil) Tercio@11: else Tercio@11: self.button:SetDisabledTexture (disabled, "ADD") Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: -- frame levels Tercio@11: function ButtonMetaFunctions:GetFrameLevel() Tercio@11: return self.button:GetFrameLevel() Tercio@11: end Tercio@11: function ButtonMetaFunctions:SetFrameLevel (level, frame) Tercio@11: if (not frame) then Tercio@11: return self.button:SetFrameLevel (level) Tercio@11: else Tercio@11: local framelevel = frame:GetFrameLevel (frame) + level Tercio@11: return self.button:SetFrameLevel (framelevel) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- icon Tercio@11: function ButtonMetaFunctions:SetIcon (texture, width, height, layout, texcoord, overlay, textdistance, leftpadding) Tercio@11: if (not self.icon) then Tercio@11: self.icon = self:CreateTexture (nil, "artwork") Tercio@11: self.icon:SetSize (self.height*0.8, self.height*0.8) Tercio@11: self.icon:SetPoint ("left", self.widget, "left", 4 + (leftpadding or 0), 0) Tercio@11: self.icon.leftpadding = leftpadding or 0 Tercio@11: self.widget.text:ClearAllPoints() Tercio@11: self.widget.text:SetPoint ("left", self.icon, "right", textdistance or 2, 0) Tercio@11: end Tercio@11: Tercio@11: self.icon:SetTexture (texture) Tercio@11: self.icon:SetSize (width or self.height*0.8, height or self.height*0.8) Tercio@11: self.icon:SetDrawLayer (layout or "artwork") Tercio@11: if (texcoord) then Tercio@11: self.icon:SetTexCoord (unpack (texcoord)) Tercio@11: else Tercio@11: self.icon:SetTexCoord (0, 1, 0, 1) Tercio@11: end Tercio@11: if (overlay) then Tercio@11: if (type (overlay) == "string") then Tercio@11: local r, g, b, a = DF:ParseColors (overlay) Tercio@11: self.icon:SetVertexColor (r, g, b, a) Tercio@11: else Tercio@11: self.icon:SetVertexColor (unpack (overlay)) Tercio@11: end Tercio@11: else Tercio@11: self.icon:SetVertexColor (1, 1, 1, 1) Tercio@11: end Tercio@11: Tercio@11: local w = self.button:GetWidth() Tercio@11: local iconw = self.icon:GetWidth() Tercio@11: local text_width = self.button.text:GetStringWidth() Tercio@11: if (text_width > w-15-iconw) then Tercio@11: if (not short_method) then Tercio@11: local new_width = text_width+15+iconw Tercio@11: self.button:SetWidth (new_width) Tercio@11: elseif (short_method == 1) then Tercio@11: local loop = true Tercio@11: local textsize = 11 Tercio@11: while (loop) do Tercio@11: if (text_width+15+iconw < w or textsize < 8) then Tercio@11: loop = false Tercio@11: break Tercio@11: else Tercio@11: DF:SetFontSize (self.button.text, textsize) Tercio@11: text_width = self.button.text:GetStringWidth() Tercio@11: textsize = textsize - 1 Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: -- frame stratas Tercio@11: function ButtonMetaFunctions:SetFrameStrata() Tercio@11: return self.button:GetFrameStrata() Tercio@11: end Tercio@11: function ButtonMetaFunctions:SetFrameStrata (strata) Tercio@11: if (_type (strata) == "table") then Tercio@11: self.button:SetFrameStrata (strata:GetFrameStrata()) Tercio@11: else Tercio@11: self.button:SetFrameStrata (strata) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- enabled Tercio@11: function ButtonMetaFunctions:IsEnabled() Tercio@11: return self.button:IsEnabled() Tercio@11: end Tercio@11: function ButtonMetaFunctions:Enable() Tercio@11: return self.button:Enable() Tercio@11: end Tercio@11: function ButtonMetaFunctions:Disable() Tercio@11: return self.button:Disable() Tercio@11: end Tercio@11: Tercio@11: -- exec Tercio@11: function ButtonMetaFunctions:Exec() Tercio@11: return self.func (self.param1, self.param2) Tercio@11: end Tercio@11: function ButtonMetaFunctions:Click() Tercio@11: return self.func (self.param1, self.param2) Tercio@11: end Tercio@11: function ButtonMetaFunctions:RightClick() Tercio@11: return self.funcright() Tercio@11: end Tercio@11: Tercio@11: --> hooks Tercio@11: function ButtonMetaFunctions:SetHook (hookType, func) Tercio@11: if (func) then Tercio@11: _rawset (self, hookType.."Hook", func) Tercio@11: else Tercio@11: _rawset (self, hookType.."Hook", nil) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: --> custom textures Tercio@11: function ButtonMetaFunctions:InstallCustomTexture (texture, rect, coords, use_split, side_textures, side_textures2) Tercio@11: Tercio@11: self.button:SetNormalTexture (nil) Tercio@11: self.button:SetPushedTexture (nil) Tercio@11: self.button:SetDisabledTexture (nil) Tercio@11: self.button:SetHighlightTexture (nil) Tercio@11: Tercio@11: local button = self.button Tercio@11: Tercio@11: if (use_split) then Tercio@11: Tercio@11: --> 4 corners Tercio@11: button.textureTopLeft = button:CreateTexture (nil, "artwork"); button.textureTopLeft:SetSize (8, 8); button.textureTopLeft:SetPoint ("topleft", button) Tercio@11: button.textureTopRight = button:CreateTexture (nil, "artwork"); button.textureTopRight:SetSize (8, 8); button.textureTopRight:SetPoint ("topright", button) Tercio@11: button.textureBottomLeft = button:CreateTexture (nil, "artwork"); button.textureBottomLeft:SetSize (8, 8); button.textureBottomLeft:SetPoint ("bottomleft", button) Tercio@11: button.textureBottomRight = button:CreateTexture (nil, "artwork"); button.textureBottomRight:SetSize (8, 8); button.textureBottomRight:SetPoint ("bottomright", button) Tercio@11: Tercio@11: button.textureLeft = button:CreateTexture (nil, "artwork"); button.textureLeft:SetWidth (4); button.textureLeft:SetPoint ("topleft", button.textureTopLeft, "bottomleft"); button.textureLeft:SetPoint ("bottomleft", button.textureBottomLeft, "topleft") Tercio@11: button.textureRight = button:CreateTexture (nil, "artwork"); button.textureRight:SetWidth (4); button.textureRight:SetPoint ("topright", button.textureTopRight, "bottomright"); button.textureRight:SetPoint ("bottomright", button.textureBottomRight, "topright") Tercio@11: button.textureTop = button:CreateTexture (nil, "artwork"); button.textureTop:SetHeight (4); button.textureTop:SetPoint ("topleft", button.textureTopLeft, "topright"); button.textureTop:SetPoint ("topright", button.textureTopRight, "topleft"); Tercio@11: button.textureBottom = button:CreateTexture (nil, "artwork"); button.textureBottom:SetHeight (4); button.textureBottom:SetPoint ("bottomleft", button.textureBottomLeft, "bottomright"); button.textureBottom:SetPoint ("bottomright", button.textureBottomRight, "bottomleft"); Tercio@11: Tercio@11: button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128) Tercio@11: button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128) Tercio@11: button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128) Tercio@11: button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128) Tercio@11: Tercio@11: button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128) Tercio@11: button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128) Tercio@11: button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128) Tercio@11: button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128) Tercio@11: Tercio@11: button.textureTopLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: button.textureTopRight:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: button.textureBottomLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: button.textureBottomRight:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: button.textureLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: button.textureRight:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: button.textureTop:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: button.textureBottom:SetTexture ([[Interface\AddOns\Details\images\default_button]]) Tercio@11: Tercio@11: else Tercio@11: texture = texture or "Interface\\AddOns\\Details\\images\\default_button" Tercio@11: self.button.texture = self.button:CreateTexture (nil, "artwork") Tercio@11: Tercio@11: if (not rect) then Tercio@11: self.button.texture:SetAllPoints (self.button) Tercio@11: else Tercio@11: self.button.texture:SetPoint ("topleft", self.button, "topleft", rect.x1, rect.y1) Tercio@11: self.button.texture:SetPoint ("bottomright", self.button, "bottomright", rect.x2, rect.y2) Tercio@11: end Tercio@11: Tercio@11: if (coords) then Tercio@11: self.button.texture.coords = coords Tercio@11: self.button.texture:SetTexCoord (_unpack (coords.Normal)) Tercio@11: else Tercio@11: self.button.texture:SetTexCoord (0, 1, 0, 0.24609375) Tercio@11: end Tercio@11: Tercio@11: self.button.texture:SetTexture (texture) Tercio@11: end Tercio@11: Tercio@11: if (side_textures) then Tercio@11: local left = self.button:CreateTexture (nil, "overlay") Tercio@11: left:SetTexture ([[Interface\TALENTFRAME\talent-main]]) Tercio@11: left:SetTexCoord (0.13671875, 0.25, 0.486328125, 0.576171875) Tercio@11: left:SetPoint ("left", self.button, 0, 0) Tercio@11: left:SetWidth (10) Tercio@11: left:SetHeight (self.button:GetHeight()+2) Tercio@11: self.button.left_border = left Tercio@11: Tercio@11: local right = self.button:CreateTexture (nil, "overlay") Tercio@11: right:SetTexture ([[Interface\TALENTFRAME\talent-main]]) Tercio@11: right:SetTexCoord (0.01953125, 0.13671875, 0.486328125, 0.576171875) Tercio@11: right:SetPoint ("right", self.button, 0, 0) Tercio@11: right:SetWidth (10) Tercio@11: right:SetHeight (self.button:GetHeight()+2) Tercio@11: self.button.right_border = right Tercio@11: Tercio@11: elseif (side_textures2) then Tercio@11: Tercio@11: local left = self.button:CreateTexture (nil, "overlay") Tercio@11: left:SetTexture ([[Interface\AddOns\Details\images\icons]]) Tercio@11: left:SetTexCoord (94/512, 123/512, 42/512, 87/512) Tercio@11: left:SetPoint ("left", self.button, 0, 0) Tercio@11: left:SetWidth (10) Tercio@11: left:SetHeight (self.button:GetHeight()+2) Tercio@11: self.button.left_border = left Tercio@11: Tercio@11: local right = self.button:CreateTexture (nil, "overlay") Tercio@11: right:SetTexture ([[Interface\AddOns\Details\images\icons]]) Tercio@11: right:SetTexCoord (65/512, 94/512, 42/512, 87/512) Tercio@11: right:SetPoint ("right", self.button, 0, 0) Tercio@11: right:SetWidth (10) Tercio@11: right:SetHeight (self.button:GetHeight()+2) Tercio@11: self.button.right_border = right Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> scripts Tercio@11: Tercio@11: local OnEnter = function (button) Tercio@11: Tercio@11: if (button.textureTopLeft) then Tercio@11: button.textureLeft:SetTexCoord (0, 4/128, 40/128, 56/128) Tercio@11: button.textureRight:SetTexCoord (124/128, 1, 40/128, 56/128) Tercio@11: button.textureTop:SetTexCoord (9/128, 120/128, 33/128, 37/128) Tercio@11: button.textureBottom:SetTexCoord (9/128, 119/128, 60/128, 64/128) Tercio@11: Tercio@11: button.textureTopLeft:SetTexCoord (0, 8/128, 33/128, 40/128) Tercio@11: button.textureTopRight:SetTexCoord (121/128, 1, 33/128, 40/128) Tercio@11: button.textureBottomLeft:SetTexCoord (0, 8/128, 56/128, 64/128) Tercio@11: button.textureBottomRight:SetTexCoord (120/128, 1, 56/128, 64/128) Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.OnEnterHook) then Tercio@11: local interrupt = button.MyObject.OnEnterHook (button, button.MyObject) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: button.MyObject.is_mouse_over = true Tercio@11: Tercio@11: if (button.texture) then Tercio@11: if (button.texture.coords) then Tercio@11: button.texture:SetTexCoord (_unpack (button.texture.coords.Highlight)) Tercio@11: else Tercio@11: button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375) Tercio@11: end Tercio@11: end Tercio@11: Tercio@22: if (button.MyObject.onenter_backdrop_border_color) then Tercio@22: button:SetBackdropBorderColor (unpack (button.MyObject.onenter_backdrop_border_color)) Tercio@22: end Tercio@22: Tercio@22: if (button.MyObject.onenter_backdrop) then Tercio@22: button:SetBackdropColor (unpack (button.MyObject.onenter_backdrop)) Tercio@22: end Tercio@22: Tercio@11: if (button.MyObject.have_tooltip) then Tercio@11: GameCooltip2:Preset (2) Tercio@11: if (type (button.MyObject.have_tooltip) == "function") then Tercio@11: GameCooltip2:AddLine (button.MyObject.have_tooltip() or "") Tercio@11: else Tercio@11: GameCooltip2:AddLine (button.MyObject.have_tooltip) Tercio@11: end Tercio@11: GameCooltip2:ShowCooltip (button, "tooltip") Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnLeave = function (button) Tercio@11: Tercio@11: if (button.textureLeft and not button.MyObject.is_mouse_down) then Tercio@11: button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128) Tercio@11: button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128) Tercio@11: button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128) Tercio@11: button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128) Tercio@11: Tercio@11: button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128) Tercio@11: button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128) Tercio@11: button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128) Tercio@11: button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128) Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.OnLeaveHook) then Tercio@11: local interrupt = button.MyObject.OnLeaveHook (button, button.MyObject) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: button.MyObject.is_mouse_over = false Tercio@11: Tercio@11: if (button.texture and not button.MyObject.is_mouse_down) then Tercio@11: if (button.texture.coords) then Tercio@11: button.texture:SetTexCoord (_unpack (button.texture.coords.Normal)) Tercio@11: else Tercio@11: button.texture:SetTexCoord (0, 1, 0, 0.24609375) Tercio@11: end Tercio@11: end Tercio@11: Tercio@22: if (button.MyObject.onleave_backdrop_border_color) then Tercio@22: button:SetBackdropBorderColor (unpack (button.MyObject.onleave_backdrop_border_color)) Tercio@22: end Tercio@22: Tercio@22: if (button.MyObject.onleave_backdrop) then Tercio@22: button:SetBackdropColor (unpack (button.MyObject.onleave_backdrop)) Tercio@22: end Tercio@22: Tercio@11: if (button.MyObject.have_tooltip) then Tercio@11: if (GameCooltip2:GetText (1) == button.MyObject.have_tooltip or type (button.MyObject.have_tooltip) == "function") then Tercio@11: GameCooltip2:Hide() Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnHide = function (button) Tercio@11: if (button.MyObject.OnHideHook) then Tercio@11: local interrupt = button.MyObject.OnHideHook (button, button.MyObject) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnShow = function (button) Tercio@11: if (button.MyObject.OnShowHook) then Tercio@11: local interrupt = button.MyObject.OnShowHook (button, button.MyObject) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnMouseDown = function (button, buttontype) Tercio@11: if (not button:IsEnabled()) then Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: if (button.textureTopLeft) then Tercio@11: button.textureLeft:SetTexCoord (0, 4/128, 72/128, 88/128) Tercio@11: button.textureRight:SetTexCoord (124/128, 1, 72/128, 88/128) Tercio@11: button.textureTop:SetTexCoord (9/128, 120/128, 65/128, 68/128) Tercio@11: button.textureBottom:SetTexCoord (9/128, 119/128, 92/128, 96/128) Tercio@11: Tercio@11: button.textureTopLeft:SetTexCoord (0, 8/128, 65/128, 71/128) Tercio@11: button.textureTopRight:SetTexCoord (121/128, 1, 65/128, 71/128) Tercio@11: button.textureBottomLeft:SetTexCoord (0, 8/128, 88/128, 96/128) Tercio@11: button.textureBottomRight:SetTexCoord (120/128, 1, 88/128, 96/128) Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.OnMouseDownHook) then Tercio@11: local interrupt = button.MyObject.OnMouseDownHook (button, buttontype, button.MyObject) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: button.MyObject.is_mouse_down = true Tercio@11: Tercio@11: if (button.texture) then Tercio@11: if (button.texture.coords) then Tercio@11: button.texture:SetTexCoord (_unpack (button.texture.coords.Pushed)) Tercio@11: else Tercio@11: button.texture:SetTexCoord (0, 1, 0.5078125, 0.75) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.capsule_textalign) then Tercio@11: if (button.MyObject.icon) then Tercio@11: button.MyObject.icon:SetPoint ("left", button, "left", 5 + (button.MyObject.icon.leftpadding or 0), -1) Tercio@11: elseif (button.MyObject.capsule_textalign == "left") then Tercio@11: button.text:SetPoint ("left", button, "left", 3, -1) Tercio@11: elseif (button.MyObject.capsule_textalign == "center") then Tercio@11: button.text:SetPoint ("center", button, "center", 1, -1) Tercio@11: elseif (button.MyObject.capsule_textalign == "right") then Tercio@11: button.text:SetPoint ("right", button, "right", -1, -1) Tercio@11: end Tercio@11: else Tercio@11: if (button.MyObject.icon) then Tercio@11: button.MyObject.icon:SetPoint ("left", button, "left", 7 + (button.MyObject.icon.leftpadding or 0), -2) Tercio@11: else Tercio@11: button.text:SetPoint ("center", button,"center", 1, -1) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: button.mouse_down = GetTime() Tercio@11: local x, y = GetCursorPosition() Tercio@11: button.x = _math_floor (x) Tercio@11: button.y = _math_floor (y) Tercio@11: Tercio@11: if (not button.MyObject.container.isLocked and button.MyObject.container:IsMovable()) then Tercio@11: if (not button.isLocked and button:IsMovable()) then Tercio@11: button.MyObject.container.isMoving = true Tercio@11: button.MyObject.container:StartMoving() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.options.OnGrab) then Tercio@11: if (_type (button.MyObject.options.OnGrab) == "string" and button.MyObject.options.OnGrab == "PassClick") then Tercio@11: if (buttontype == "LeftButton") then Tercio@11: button.MyObject.func (button.MyObject.param1, button.MyObject.param2) Tercio@11: else Tercio@11: button.MyObject.funcright (button.MyObject.param1, button.MyObject.param2) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnMouseUp = function (button, buttontype) Tercio@11: if (not button:IsEnabled()) then Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: if (button.textureLeft) then Tercio@11: if (button.MyObject.is_mouse_over) then Tercio@11: button.textureLeft:SetTexCoord (0, 4/128, 40/128, 56/128) Tercio@11: button.textureRight:SetTexCoord (124/128, 1, 40/128, 56/128) Tercio@11: button.textureTop:SetTexCoord (9/128, 120/128, 33/128, 37/128) Tercio@11: button.textureBottom:SetTexCoord (9/128, 119/128, 60/128, 64/128) Tercio@11: Tercio@11: button.textureTopLeft:SetTexCoord (0, 8/128, 33/128, 40/128) Tercio@11: button.textureTopRight:SetTexCoord (121/128, 1, 33/128, 40/128) Tercio@11: button.textureBottomLeft:SetTexCoord (0, 8/128, 56/128, 64/128) Tercio@11: button.textureBottomRight:SetTexCoord (120/128, 1, 56/128, 64/128) Tercio@11: else Tercio@11: button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128) Tercio@11: button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128) Tercio@11: button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128) Tercio@11: button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128) Tercio@11: Tercio@11: button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128) Tercio@11: button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128) Tercio@11: button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128) Tercio@11: button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.OnMouseUpHook) then Tercio@11: local interrupt = button.MyObject.OnMouseUpHook (button, buttontype, button.MyObject) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: button.MyObject.is_mouse_down = false Tercio@11: Tercio@11: if (button.texture) then Tercio@11: if (button.texture.coords) then Tercio@11: if (button.MyObject.is_mouse_over) then Tercio@11: button.texture:SetTexCoord (_unpack (button.texture.coords.Highlight)) Tercio@11: else Tercio@11: button.texture:SetTexCoord (_unpack (coords.Normal)) Tercio@11: end Tercio@11: else Tercio@11: if (button.MyObject.is_mouse_over) then Tercio@11: button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375) Tercio@11: else Tercio@11: button.texture:SetTexCoord (0, 1, 0, 0.24609375) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.capsule_textalign) then Tercio@11: if (button.MyObject.icon) then Tercio@11: button.MyObject.icon:SetPoint ("left", button, "left", 4 + (button.MyObject.icon.leftpadding or 0), 0) Tercio@11: elseif (button.MyObject.capsule_textalign == "left") then Tercio@11: button.text:SetPoint ("left", button, "left", 2, 0) Tercio@11: elseif (button.MyObject.capsule_textalign == "center") then Tercio@11: button.text:SetPoint ("center", button, "center", 0, 0) Tercio@11: elseif (button.MyObject.capsule_textalign == "right") then Tercio@11: button.text:SetPoint ("right", button, "right", -2, 0) Tercio@11: end Tercio@11: else Tercio@11: if (button.MyObject.icon) then Tercio@11: button.MyObject.icon:SetPoint ("left", button, "left", 4 + (button.MyObject.icon.leftpadding or 0), 0) Tercio@11: else Tercio@11: button.text:SetPoint ("center", button,"center", 0, 0) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (button.MyObject.container.isMoving) then Tercio@11: button.MyObject.container:StopMovingOrSizing() Tercio@11: button.MyObject.container.isMoving = false Tercio@11: end Tercio@11: Tercio@11: local x, y = GetCursorPosition() Tercio@11: x = _math_floor (x) Tercio@11: y = _math_floor (y) Tercioo@28: if ( Tercioo@28: (x == button.x and y == button.y) or Tercioo@28: (button.mouse_down+0.5 > GetTime() and button:IsMouseOver()) Tercioo@28: ) then Tercio@11: if (buttontype == "LeftButton") then Tercio@11: button.MyObject.func (button, buttontype, button.MyObject.param1, button.MyObject.param2) Tercio@11: else Tercio@11: button.MyObject.funcright (button, buttontype, button.MyObject.param1, button.MyObject.param2) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@22: Tercio@22: function ButtonMetaFunctions:SetTemplate (template) Tercio@22: Tercio@22: if (template.width) then Tercio@22: self:SetWidth (template.width) Tercio@22: end Tercio@22: if (template.height) then Tercio@22: self:SetHeight (template.height) Tercio@22: end Tercio@22: Tercio@22: if (template.backdrop) then Tercio@22: self:SetBackdrop (template.backdrop) Tercio@22: end Tercio@22: if (template.backdropcolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.backdropcolor) Tercio@22: self:SetBackdropColor (r, g, b, a) Tercio@22: self.onleave_backdrop = {r, g, b, a} Tercio@22: end Tercio@22: if (template.backdropbordercolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.backdropbordercolor) Tercio@22: self:SetBackdropBorderColor (r, g, b, a) Tercio@22: self.onleave_backdrop_border_color = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.onentercolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.onentercolor) Tercio@22: self.onenter_backdrop = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.onleavecolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.onleavecolor) Tercio@22: self.onleave_backdrop = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.onenterbordercolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.onenterbordercolor) Tercio@22: self.onenter_backdrop_border_color = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.onleavebordercolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.onleavebordercolor) Tercio@22: self.onleave_backdrop_border_color = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.icon) then Tercio@22: local i = template.icon Tercio@22: self:SetIcon (i.texture, i.width, i.height, i.layout, i.texcoord, i.color, i.textdistance, i.leftpadding) Tercio@22: end Tercio@22: Tercio@22: end Tercio@22: Tercio@22: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> object constructor Tercio@11: Tercio@22: function DF:CreateButton (parent, func, w, h, text, param1, param2, texture, member, name, short_method, button_template, text_template) Tercio@22: return DF:NewButton (parent, parent, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template) Tercio@11: end Tercio@11: Tercio@22: function DF:NewButton (parent, container, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template) Tercio@11: Tercio@11: if (not name) then Tercio@11: name = "DetailsFrameworkButtonNumber" .. DF.ButtonCounter Tercio@11: DF.ButtonCounter = DF.ButtonCounter + 1 Tercio@11: Tercio@11: elseif (not parent) then Tercio@11: return nil Tercio@11: end Tercio@11: if (not container) then Tercio@11: container = parent Tercio@11: end Tercio@11: Tercio@11: if (name:find ("$parent")) then Tercioo@28: local parentName = DF.GetParentName (parent) Tercioo@28: name = name:gsub ("$parent", parentName) Tercio@11: end Tercio@22: Tercio@11: local ButtonObject = {type = "button", dframework = true} Tercio@11: Tercio@11: if (member) then Tercio@11: parent [member] = ButtonObject Tercio@11: end Tercio@11: Tercio@11: if (parent.dframework) then Tercio@11: parent = parent.widget Tercio@11: end Tercio@11: if (container.dframework) then Tercio@11: container = container.widget Tercio@11: end Tercio@11: Tercio@11: --> default members: Tercio@11: --> hooks Tercio@11: ButtonObject.OnEnterHook = nil Tercio@11: ButtonObject.OnLeaveHook = nil Tercio@11: ButtonObject.OnHideHook = nil Tercio@11: ButtonObject.OnShowHook = nil Tercio@11: ButtonObject.OnMouseDownHook = nil Tercio@11: ButtonObject.OnMouseUpHook = nil Tercio@11: --> misc Tercio@11: ButtonObject.is_locked = true Tercio@11: ButtonObject.container = container Tercio@11: ButtonObject.have_tooltip = nil Tercio@11: ButtonObject.options = {OnGrab = false} Tercio@11: Tercio@11: Tercio@11: ButtonObject.button = CreateFrame ("button", name, parent, "DetailsFrameworkButtonTemplate") Tercio@11: ButtonObject.widget = ButtonObject.button Tercio@11: Tercio@22: --ButtonObject.button:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}}) Tercio@11: ButtonObject.button:SetBackdropColor (0, 0, 0, 0.4) Tercio@11: ButtonObject.button:SetBackdropBorderColor (1, 1, 1, 1) Tercio@11: Tercio@11: if (not APIButtonFunctions) then Tercio@11: APIButtonFunctions = true Tercio@11: local idx = getmetatable (ButtonObject.button).__index Tercio@11: for funcName, funcAddress in pairs (idx) do Tercio@11: if (not ButtonMetaFunctions [funcName]) then Tercio@11: ButtonMetaFunctions [funcName] = function (object, ...) Tercio@20: local x = loadstring ( "return _G['"..object.button:GetName().."']:"..funcName.."(...)") Tercio@11: return x (...) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@22: Tercio@11: ButtonObject.button:SetWidth (w or 100) Tercio@11: ButtonObject.button:SetHeight (h or 20) Tercio@11: ButtonObject.button.MyObject = ButtonObject Tercio@11: Tercio@11: ButtonObject.text_overlay = _G [name .. "_Text"] Tercio@11: ButtonObject.disabled_overlay = _G [name .. "_TextureDisabled"] Tercio@11: Tercio@11: ButtonObject.button:SetNormalTexture (texture) Tercio@11: ButtonObject.button:SetPushedTexture (texture) Tercio@11: ButtonObject.button:SetDisabledTexture (texture) Tercio@11: ButtonObject.button:SetHighlightTexture (texture, "ADD") Tercio@11: Tercio@11: ButtonObject.button.text:SetText (text) Tercio@11: ButtonObject.button.text:SetPoint ("center", ButtonObject.button, "center") Tercio@11: Tercio@11: local text_width = ButtonObject.button.text:GetStringWidth() Tercio@11: if (text_width > w-15 and ButtonObject.button.text:GetText() ~= "") then Tercio@11: if (not short_method) then Tercio@11: local new_width = text_width+15 Tercio@11: ButtonObject.button:SetWidth (new_width) Tercio@11: elseif (short_method == 1) then Tercio@11: local loop = true Tercio@11: local textsize = 11 Tercio@11: while (loop) do Tercio@11: if (text_width+15 < w or textsize < 8) then Tercio@11: loop = false Tercio@11: break Tercio@11: else Tercio@11: DF:SetFontSize (ButtonObject.button.text, textsize) Tercio@11: text_width = ButtonObject.button.text:GetStringWidth() Tercio@11: textsize = textsize - 1 Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ButtonObject.func = func or cleanfunction Tercio@11: ButtonObject.funcright = cleanfunction Tercio@11: ButtonObject.param1 = param1 Tercio@11: ButtonObject.param2 = param2 Tercio@11: Tercio@11: ButtonObject.short_method = short_method Tercio@11: Tercio@22: if (text_template) then Tercio@22: if (text_template.size) then Tercio@22: DF:SetFontSize (ButtonObject.button.text, text_template.size) Tercio@20: end Tercio@22: if (text_template.color) then Tercio@22: local r, g, b, a = DF:ParseColors (text_template.color) Tercio@20: ButtonObject.button.text:SetTextColor (r, g, b, a) Tercio@20: end Tercio@22: if (text_template.font) then Tercio@20: local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0") Tercio@22: local font = SharedMedia:Fetch ("font", text_template.font) Tercio@20: DF:SetFontFace (ButtonObject.button.text, font) Tercio@20: end Tercio@20: end Tercio@20: Tercio@11: --> hooks Tercio@11: ButtonObject.button:SetScript ("OnEnter", OnEnter) Tercio@11: ButtonObject.button:SetScript ("OnLeave", OnLeave) Tercio@11: ButtonObject.button:SetScript ("OnHide", OnHide) Tercio@11: ButtonObject.button:SetScript ("OnShow", OnShow) Tercio@11: ButtonObject.button:SetScript ("OnMouseDown", OnMouseDown) Tercio@11: ButtonObject.button:SetScript ("OnMouseUp", OnMouseUp) Tercio@11: Tercio@11: _setmetatable (ButtonObject, ButtonMetaFunctions) Tercio@11: Tercio@22: if (button_template) then Tercio@22: ButtonObject:SetTemplate (button_template) Tercio@22: end Tercio@22: Tercio@11: return ButtonObject Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local pickcolor_callback = function (self, r, g, b, a, button) Tercio@19: a = abs (a-1) Tercio@11: button.MyObject.color_texture:SetVertexColor (r, g, b, a) Tercio@11: button.MyObject:color_callback (r, g, b, a) Tercio@11: end Tercio@19: local pickcolor = function (self, alpha, param2) Tercio@11: local r, g, b, a = self.MyObject.color_texture:GetVertexColor() Tercio@19: a = abs (a-1) Tercio@11: DF:ColorPick (self, r, g, b, a, pickcolor_callback) Tercio@11: end Tercio@11: Tercio@11: local color_button_height = 16 Tercio@11: local color_button_width = 16 Tercio@11: Tercio@11: local set_colorpick_color = function (button, r, g, b, a) Tercio@19: a = a or 1 Tercio@11: button.color_texture:SetVertexColor (r, g, b, a) Tercio@11: end Tercio@11: Tercio@11: local colorpick_cancel = function (self) Tercio@11: ColorPickerFrame:Hide() Tercio@11: end Tercio@11: Tercio@22: function DF:CreateColorPickButton (parent, name, member, callback, alpha, button_template) Tercio@22: return DF:NewColorPickButton (parent, name, member, callback, alpha, button_template) Tercio@11: end Tercio@11: Tercio@22: function DF:NewColorPickButton (parent, name, member, callback, alpha, button_template) Tercio@11: Tercio@11: --button Tercio@22: local button = DF:NewButton (parent, _, name, member, color_button_width, color_button_height, pickcolor, alpha, "param2", nil, nil, nil, button_template) Tercio@11: button.color_callback = callback Tercio@11: button.Cancel = colorpick_cancel Tercio@11: button.SetColor = set_colorpick_color Tercio@11: Tercio@22: if (not button_template) then Tercio@22: button:InstallCustomTexture() Tercio@22: button:SetBackdrop ({edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 6, Tercio@22: bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], insets = {left = 0, right = 0, top = 0, bottom = 0}}) Tercio@22: end Tercio@11: Tercio@11: --textura do fundo Tercio@11: local background = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, nil, "$parentBck") Tercio@11: --background:SetTexture ([[Interface\AddOns\Details\images\icons]]) Tercio@11: background:SetPoint ("topleft", button.widget, "topleft", 1, -2) Tercio@11: background:SetPoint ("bottomright", button.widget, "bottomright", -1, 1) Tercio@11: background:SetTexCoord (0.337890625, 0.390625, 0.625, 0.658203125) Tercio@11: background:SetDrawLayer ("background", 1) Tercio@11: Tercio@11: --textura da cor Tercio@11: local img = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, "color_texture", "$parentTex") Tercio@11: img:SetTexture (1, 1, 1) Tercio@11: img:SetPoint ("topleft", button.widget, "topleft", 1, -2) Tercio@11: img:SetPoint ("bottomright", button.widget, "bottomright", -1, 1) Tercio@11: img:SetDrawLayer ("background", 2) Tercio@11: Tercio@11: return button Tercio@11: Tercio@11: end