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