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