Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: Icon Widget Tercio@23: -------------------------------------------------------------------------------]] Tercio@23: local Type, Version = "Icon", 21 Tercio@23: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) Tercio@23: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end Tercio@23: Tercio@23: -- Lua APIs Tercio@23: local select, pairs, print = select, pairs, print Tercio@23: Tercio@23: -- WoW APIs Tercio@23: local CreateFrame, UIParent, GetBuildInfo = CreateFrame, UIParent, GetBuildInfo Tercio@23: Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: Scripts Tercio@23: -------------------------------------------------------------------------------]] Tercio@23: local function Control_OnEnter(frame) Tercio@23: frame.obj:Fire("OnEnter") Tercio@23: end Tercio@23: Tercio@23: local function Control_OnLeave(frame) Tercio@23: frame.obj:Fire("OnLeave") Tercio@23: end Tercio@23: Tercio@23: local function Button_OnClick(frame, button) Tercio@23: frame.obj:Fire("OnClick", button) Tercio@23: AceGUI:ClearFocus() Tercio@23: end Tercio@23: Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: Methods Tercio@23: -------------------------------------------------------------------------------]] Tercio@23: local methods = { Tercio@23: ["OnAcquire"] = function(self) Tercio@23: self:SetHeight(110) Tercio@23: self:SetWidth(110) Tercio@23: self:SetLabel() Tercio@23: self:SetImage(nil) Tercio@23: self:SetImageSize(64, 64) Tercio@23: self:SetDisabled(false) Tercio@23: end, Tercio@23: Tercio@23: -- ["OnRelease"] = nil, Tercio@23: Tercio@23: ["SetLabel"] = function(self, text) Tercio@23: if text and text ~= "" then Tercio@23: self.label:Show() Tercio@23: self.label:SetText(text) Tercio@23: self:SetHeight(self.image:GetHeight() + 25) Tercio@23: else Tercio@23: self.label:Hide() Tercio@23: self:SetHeight(self.image:GetHeight() + 10) Tercio@23: end Tercio@23: end, Tercio@23: Tercio@23: ["SetImage"] = function(self, path, ...) Tercio@23: local image = self.image Tercio@23: image:SetTexture(path) Tercio@23: Tercio@23: if image:GetTexture() then Tercio@23: local n = select("#", ...) Tercio@23: if n == 4 or n == 8 then Tercio@23: image:SetTexCoord(...) Tercio@23: else Tercio@23: image:SetTexCoord(0, 1, 0, 1) Tercio@23: end Tercio@23: end Tercio@23: end, Tercio@23: Tercio@23: ["SetImageSize"] = function(self, width, height) Tercio@23: self.image:SetWidth(width) Tercio@23: self.image:SetHeight(height) Tercio@23: --self.frame:SetWidth(width + 30) Tercio@23: if self.label:IsShown() then Tercio@23: self:SetHeight(height + 25) Tercio@23: else Tercio@23: self:SetHeight(height + 10) Tercio@23: end Tercio@23: end, Tercio@23: Tercio@23: ["SetDisabled"] = function(self, disabled) Tercio@23: self.disabled = disabled Tercio@23: if disabled then Tercio@23: self.frame:Disable() Tercio@23: self.label:SetTextColor(0.5, 0.5, 0.5) Tercio@23: self.image:SetVertexColor(0.5, 0.5, 0.5, 0.5) Tercio@23: else Tercio@23: self.frame:Enable() Tercio@23: self.label:SetTextColor(1, 1, 1) Tercio@23: self.image:SetVertexColor(1, 1, 1, 1) Tercio@23: end Tercio@23: end Tercio@23: } Tercio@23: Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: Constructor Tercio@23: -------------------------------------------------------------------------------]] Tercio@23: local function Constructor() Tercio@23: local frame = CreateFrame("Button", nil, UIParent) Tercio@23: frame:Hide() Tercio@23: Tercio@23: frame:EnableMouse(true) Tercio@23: frame:SetScript("OnEnter", Control_OnEnter) Tercio@23: frame:SetScript("OnLeave", Control_OnLeave) Tercio@23: frame:SetScript("OnClick", Button_OnClick) Tercio@23: Tercio@23: local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontHighlight") Tercio@23: label:SetPoint("BOTTOMLEFT") Tercio@23: label:SetPoint("BOTTOMRIGHT") Tercio@23: label:SetJustifyH("CENTER") Tercio@23: label:SetJustifyV("TOP") Tercio@23: label:SetHeight(18) Tercio@23: Tercio@23: local image = frame:CreateTexture(nil, "BACKGROUND") Tercio@23: image:SetWidth(64) Tercio@23: image:SetHeight(64) Tercio@23: image:SetPoint("TOP", 0, -5) Tercio@23: Tercio@23: local highlight = frame:CreateTexture(nil, "HIGHLIGHT") Tercio@23: highlight:SetAllPoints(image) Tercio@23: highlight:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight") Tercio@23: highlight:SetTexCoord(0, 1, 0.23, 0.77) Tercio@23: highlight:SetBlendMode("ADD") Tercio@23: Tercio@23: local widget = { Tercio@23: label = label, Tercio@23: image = image, Tercio@23: frame = frame, Tercio@23: type = Type Tercio@23: } Tercio@23: for method, func in pairs(methods) do Tercio@23: widget[method] = func Tercio@23: end Tercio@23: -- SetText is deprecated, but keep it around for a while. (say, to WoW 4.0) Tercio@23: if (select(4, GetBuildInfo()) < 40000) then Tercio@23: widget.SetText = widget.SetLabel Tercio@23: else Tercio@23: widget.SetText = function(self, ...) print("AceGUI-3.0-Icon: SetText is deprecated! Use SetLabel instead!"); self:SetLabel(...) end Tercio@23: end Tercio@23: Tercio@23: return AceGUI:RegisterAsWidget(widget) Tercio@23: end Tercio@23: Tercio@23: AceGUI:RegisterWidgetType(Type, Constructor, Version)