Asa@0: local AceGUI = LibStub("AceGUI-3.0") Asa@0: Asa@0: -- Lua APIs Asa@0: local select = select Asa@0: Asa@0: -- WoW APIs Asa@0: local CreateFrame, UIParent = CreateFrame, UIParent Asa@0: Asa@0: -------------------------- Asa@0: -- Label -- Asa@0: -------------------------- Asa@0: do Asa@0: local Type = "Icon" Asa@0: local Version = 11 Asa@0: Asa@0: local function OnAcquire(self) Asa@0: self:SetHeight(110) Asa@0: self:SetWidth(110) Asa@0: self:SetLabel("") Asa@0: self:SetImage(nil) Asa@0: self:SetImageSize(64, 64) Asa@0: end Asa@0: Asa@0: local function OnRelease(self) Asa@0: self.frame:ClearAllPoints() Asa@0: self.frame:Hide() Asa@0: self:SetDisabled(false) Asa@0: end Asa@0: Asa@0: local function SetLabel(self, text) Asa@0: if text and text ~= "" then Asa@0: self.label:Show() Asa@0: self.label:SetText(text) Asa@0: self.frame:SetHeight(self.image:GetHeight() + 25) Asa@0: else Asa@0: self.label:Hide() Asa@0: self.frame:SetHeight(self.image:GetHeight() + 10) Asa@0: end Asa@0: end Asa@0: Asa@0: local function SetImage(self, path, ...) Asa@0: local image = self.image Asa@0: image:SetTexture(path) Asa@0: Asa@0: if image:GetTexture() then Asa@0: self.imageshown = true Asa@0: local n = select('#', ...) Asa@0: if n == 4 or n == 8 then Asa@0: image:SetTexCoord(...) Asa@0: else Asa@0: image:SetTexCoord(0, 1, 0, 1) Asa@0: end Asa@0: else Asa@0: self.imageshown = nil Asa@0: end Asa@0: end Asa@0: Asa@0: local function SetImageSize(self, width, height) Asa@0: self.image:SetWidth(width) Asa@0: self.image:SetHeight(height) Asa@0: --self.frame:SetWidth(width + 30) Asa@0: if self.label:IsShown() then Asa@0: self.frame:SetHeight(height + 25) Asa@0: else Asa@0: self.frame:SetHeight(height + 10) Asa@0: end Asa@0: end Asa@0: Asa@0: local function SetDisabled(self, disabled) Asa@0: self.disabled = disabled Asa@0: if disabled then Asa@0: self.frame:Disable() Asa@0: self.label:SetTextColor(0.5,0.5,0.5) Asa@0: self.image:SetVertexColor(0.5, 0.5, 0.5, 0.5) Asa@0: else Asa@0: self.frame:Enable() Asa@0: self.label:SetTextColor(1,1,1) Asa@0: self.image:SetVertexColor(1, 1, 1) Asa@0: end Asa@0: end Asa@0: Asa@0: local function OnClick(this, button) Asa@0: this.obj:Fire("OnClick", button) Asa@0: AceGUI:ClearFocus() Asa@0: end Asa@0: Asa@0: local function OnEnter(this) Asa@0: this.obj.highlight:Show() Asa@0: this.obj:Fire("OnEnter") Asa@0: end Asa@0: Asa@0: local function OnLeave(this) Asa@0: this.obj.highlight:Hide() Asa@0: this.obj:Fire("OnLeave") Asa@0: end Asa@0: Asa@0: local function Constructor() Asa@0: local frame = CreateFrame("Button",nil,UIParent) Asa@0: local self = {} Asa@0: self.type = Type Asa@0: Asa@0: self.OnRelease = OnRelease Asa@0: self.OnAcquire = OnAcquire Asa@0: self.SetLabel = SetLabel Asa@0: self.frame = frame Asa@0: self.SetImage = SetImage Asa@0: self.SetImageSize = SetImageSize Asa@0: Asa@0: -- SetText should be deprecated along the way Asa@0: self.SetText = SetLabel Asa@0: self.SetDisabled = SetDisabled Asa@0: Asa@0: frame.obj = self Asa@0: Asa@0: frame:SetHeight(110) Asa@0: frame:SetWidth(110) Asa@0: frame:EnableMouse(true) Asa@0: frame:SetScript("OnClick", OnClick) Asa@0: frame:SetScript("OnLeave", OnLeave) Asa@0: frame:SetScript("OnEnter", OnEnter) Asa@0: local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlight") Asa@0: label:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",0,0) Asa@0: label:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0) Asa@0: label:SetJustifyH("CENTER") Asa@0: label:SetJustifyV("TOP") Asa@0: label:SetHeight(18) Asa@0: self.label = label Asa@0: Asa@0: local image = frame:CreateTexture(nil,"BACKGROUND") Asa@0: self.image = image Asa@0: image:SetWidth(64) Asa@0: image:SetHeight(64) Asa@0: image:SetPoint("TOP",frame,"TOP",0,-5) Asa@0: Asa@0: local highlight = frame:CreateTexture(nil,"OVERLAY") Asa@0: self.highlight = highlight Asa@0: highlight:SetAllPoints(image) Asa@0: highlight:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight") Asa@0: highlight:SetTexCoord(0,1,0.23,0.77) Asa@0: highlight:SetBlendMode("ADD") Asa@0: highlight:Hide() Asa@0: Asa@0: AceGUI:RegisterAsWidget(self) Asa@0: return self Asa@0: end Asa@0: Asa@0: AceGUI:RegisterWidgetType(Type,Constructor,Version) Asa@0: end Asa@0: