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