Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: InteractiveLabel Widget Tercio@23: -------------------------------------------------------------------------------]] Tercio@51: local Type, Version = "InteractiveLabel", 21 Tercio@23: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) Tercio@23: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end Tercio@23: Tercio@23: -- Lua APIs Tercio@23: local select, pairs = select, pairs Tercio@23: Tercio@23: -- WoW APIs Tercio@23: local CreateFrame, UIParent = CreateFrame, UIParent Tercio@23: Tercio@23: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded Tercio@23: -- List them here for Mikk's FindGlobals script Tercio@23: -- GLOBALS: GameFontHighlightSmall Tercio@23: Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: Scripts Tercio@23: -------------------------------------------------------------------------------]] Tercio@23: local function Control_OnEnter(frame) Tercio@23: frame.obj:Fire("OnEnter") Tercio@23: end Tercio@23: Tercio@23: local function Control_OnLeave(frame) Tercio@23: frame.obj:Fire("OnLeave") Tercio@23: end Tercio@23: Tercio@23: local function Label_OnClick(frame, button) Tercio@23: frame.obj:Fire("OnClick", button) Tercio@23: AceGUI:ClearFocus() Tercio@23: end Tercio@23: Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: Methods Tercio@23: -------------------------------------------------------------------------------]] Tercio@23: local methods = { Tercio@23: ["OnAcquire"] = function(self) Tercio@23: self:LabelOnAcquire() Tercio@23: self:SetHighlight() Tercio@23: self:SetHighlightTexCoord() Tercio@23: self:SetDisabled(false) Tercio@23: end, Tercio@23: Tercio@23: -- ["OnRelease"] = nil, Tercio@23: Tercio@23: ["SetHighlight"] = function(self, ...) Tercio@23: self.highlight:SetTexture(...) Tercio@23: end, Tercio@23: Tercio@23: ["SetHighlightTexCoord"] = function(self, ...) Tercio@23: local c = select("#", ...) Tercio@23: if c == 4 or c == 8 then Tercio@23: self.highlight:SetTexCoord(...) Tercio@23: else Tercio@23: self.highlight:SetTexCoord(0, 1, 0, 1) Tercio@23: end Tercio@23: end, Tercio@23: Tercio@23: ["SetDisabled"] = function(self,disabled) Tercio@23: self.disabled = disabled Tercio@23: if disabled then Tercio@23: self.frame:EnableMouse(false) Tercio@23: self.label:SetTextColor(0.5, 0.5, 0.5) Tercio@23: else Tercio@23: self.frame:EnableMouse(true) Tercio@23: self.label:SetTextColor(1, 1, 1) Tercio@23: end Tercio@23: end Tercio@23: } Tercio@23: Tercio@23: --[[----------------------------------------------------------------------------- Tercio@23: Constructor Tercio@23: -------------------------------------------------------------------------------]] Tercio@23: local function Constructor() Tercio@23: -- create a Label type that we will hijack Tercio@23: local label = AceGUI:Create("Label") Tercio@23: Tercio@23: local frame = label.frame Tercio@23: frame:EnableMouse(true) Tercio@23: frame:SetScript("OnEnter", Control_OnEnter) Tercio@23: frame:SetScript("OnLeave", Control_OnLeave) Tercio@23: frame:SetScript("OnMouseDown", Label_OnClick) Tercio@23: Tercio@23: local highlight = frame:CreateTexture(nil, "HIGHLIGHT") Tercio@23: highlight:SetTexture(nil) Tercio@23: highlight:SetAllPoints() Tercio@23: highlight:SetBlendMode("ADD") Tercio@23: Tercio@23: label.highlight = highlight Tercio@23: label.type = Type Tercio@23: label.LabelOnAcquire = label.OnAcquire Tercio@23: for method, func in pairs(methods) do Tercio@23: label[method] = func Tercio@23: end Tercio@23: Tercio@23: return label Tercio@23: end Tercio@23: Tercio@23: AceGUI:RegisterWidgetType(Type, Constructor, Version) Tercio@23: