Asa@0: local AceGUI = LibStub("AceGUI-3.0") Asa@0: Asa@0: -- Lua APIs Asa@0: local select, max = select, math.max 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 = "InteractiveLabel" Asa@0: local Version = 6 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: self:SetHighlight() Asa@0: self:SetHighlightTexCoord() Asa@0: end Asa@0: Asa@0: local function OnRelease(self) Asa@0: self:SetDisabled(false) 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: local imageheight = image:GetHeight() Asa@0: local labelheight = label:GetHeight() Asa@0: --center image with label Asa@0: if imageheight > labelheight then Asa@0: image:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) Asa@0: label:SetPoint("LEFT",image,"RIGHT",0,0) Asa@0: else Asa@0: label:SetPoint("TOPLEFT",frame,"TOPLEFT",imagewidth,0) Asa@0: image:SetPoint("RIGHT",label,"LEFT",0,0) Asa@0: end Asa@0: label:SetWidth(width - imagewidth) Asa@0: height = max(imageheight, labelheight) 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 SetHighlight(self, ...) Asa@0: self.highlight:SetTexture(...) Asa@0: end Asa@0: Asa@0: local function SetHighlightTexCoord(self, ...) Asa@0: if select('#', ...) >= 1 then Asa@0: self.highlight:SetTexCoord(...) Asa@0: else Asa@0: self.highlight:SetTexCoord(0, 1, 0, 1) 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:EnableMouse(false) Asa@0: self.label:SetTextColor(0.5, 0.5, 0.5) Asa@0: else Asa@0: self.frame:EnableMouse(true) Asa@0: self.label:SetTextColor(1, 1, 1) Asa@0: end 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 OnClick(this, ...) Asa@0: this.obj:Fire("OnClick", ...) Asa@0: AceGUI:ClearFocus() 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: frame:EnableMouse(true) Asa@0: frame:SetScript("OnEnter", OnEnter) Asa@0: frame:SetScript("OnLeave", OnLeave) Asa@0: frame:SetScript("OnMouseDown", OnClick) 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: self.SetHighlight = SetHighlight Asa@0: self.SetHighlightTexCoord = SetHighlightTexCoord Asa@0: self.SetDisabled = SetDisabled 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 highlight = frame:CreateTexture(nil, "OVERLAY") Asa@0: highlight:SetTexture(nil) Asa@0: highlight:SetAllPoints() Asa@0: highlight:SetBlendMode("ADD") Asa@0: highlight:Hide() Asa@0: self.highlight = highlight 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: