Asa@0: local AceGUI = LibStub("AceGUI-3.0") Asa@0: Asa@0: -- Lua APIs Asa@0: local max, select = math.max, select Asa@0: Asa@0: -- WoW APIs Asa@0: local CreateFrame, UIParent = CreateFrame, UIParent Asa@0: Asa@0: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded Asa@0: -- List them here for Mikk's FindGlobals script Asa@0: -- GLOBALS: GameFontHighlightSmall Asa@0: Asa@0: -------------------------- Asa@0: -- Label -- Asa@0: -------------------------- Asa@0: do Asa@0: local Type = "Label" Asa@0: local Version = 11 Asa@0: Asa@0: local function OnAcquire(self) Asa@0: self:SetHeight(18) Asa@0: self:SetWidth(200) Asa@0: self:SetText("") Asa@0: self:SetImage(nil) Asa@0: self:SetColor() Asa@0: self:SetFontObject() Asa@0: end Asa@0: Asa@0: local function OnRelease(self) Asa@0: self.frame:ClearAllPoints() Asa@0: self.frame:Hide() Asa@0: end Asa@0: Asa@0: local function UpdateImageAnchor(self) Asa@0: local width = self.frame.width or self.frame:GetWidth() or 0 Asa@0: local image = self.image Asa@0: local label = self.label Asa@0: local frame = self.frame Asa@0: local height Asa@0: Asa@0: label:ClearAllPoints() Asa@0: image:ClearAllPoints() Asa@0: Asa@0: if self.imageshown then Asa@0: local imagewidth = image:GetWidth() Asa@0: if (width - imagewidth) < 200 or (label:GetText() or "") == "" then Asa@0: --image goes on top centered when less than 200 width for the text, or if there is no text Asa@0: image:SetPoint("TOP",frame,"TOP",0,0) Asa@0: label:SetPoint("TOP",image,"BOTTOM",0,0) Asa@0: label:SetPoint("LEFT",frame,"LEFT",0,0) Asa@0: label:SetWidth(width) Asa@0: height = image:GetHeight() + label:GetHeight() Asa@0: else Asa@0: --image on the left Asa@0: image:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) Asa@0: label:SetPoint("TOPLEFT",image,"TOPRIGHT",4,0) Asa@0: label:SetWidth(width - imagewidth) Asa@0: height = max(image:GetHeight(), label:GetHeight()) Asa@0: end Asa@0: else Asa@0: --no image shown Asa@0: label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) Asa@0: label:SetWidth(width) Asa@0: height = self.label:GetHeight() Asa@0: end Asa@0: Asa@0: self.resizing = true Asa@0: self.frame:SetHeight(height) Asa@0: self.frame.height = height Asa@0: self.resizing = nil Asa@0: end Asa@0: Asa@0: local function SetText(self, text) Asa@0: self.label:SetText(text or "") Asa@0: UpdateImageAnchor(self) Asa@0: end Asa@0: Asa@0: local function SetColor(self, r, g, b) Asa@0: if not (r and g and b) then Asa@0: r, g, b = 1, 1, 1 Asa@0: end Asa@0: self.label:SetVertexColor(r, g, b) Asa@0: end Asa@0: Asa@0: local function OnWidthSet(self, width) Asa@0: if self.resizing then return end Asa@0: UpdateImageAnchor(self) 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: end Asa@0: else Asa@0: self.imageshown = nil Asa@0: end Asa@0: UpdateImageAnchor(self) Asa@0: end Asa@0: Asa@0: local function SetFont(self, font, height, flags) Asa@0: self.label:SetFont(font, height, flags) Asa@0: end Asa@0: Asa@0: local function SetFontObject(self, font) Asa@0: self.label:SetFontObject(font or GameFontHighlightSmall) 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: UpdateImageAnchor(self) Asa@0: end Asa@0: Asa@0: local function Constructor() Asa@0: local frame = CreateFrame("Frame",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.SetText = SetText Asa@0: self.SetColor = SetColor Asa@0: self.frame = frame Asa@0: self.OnWidthSet = OnWidthSet Asa@0: self.SetImage = SetImage Asa@0: self.SetImageSize = SetImageSize Asa@0: self.SetFont = SetFont Asa@0: self.SetFontObject = SetFontObject Asa@0: frame.obj = self Asa@0: Asa@0: frame:SetHeight(18) Asa@0: frame:SetWidth(200) Asa@0: local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlightSmall") Asa@0: label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) Asa@0: label:SetWidth(200) Asa@0: label:SetJustifyH("LEFT") Asa@0: label:SetJustifyV("TOP") Asa@0: self.label = label Asa@0: Asa@0: local image = frame:CreateTexture(nil,"BACKGROUND") Asa@0: self.image = image 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: