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