tercio@0: --[[----------------------------------------------------------------------------- tercio@0: InteractiveLabel Widget tercio@0: -------------------------------------------------------------------------------]] Tercio@17: local Type, Version = "InteractiveLabel", 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 = select, pairs tercio@0: tercio@0: -- WoW APIs tercio@0: local CreateFrame, UIParent = CreateFrame, UIParent tercio@0: tercio@0: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded tercio@0: -- List them here for Mikk's FindGlobals script tercio@0: -- GLOBALS: GameFontHighlightSmall 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 Label_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:LabelOnAcquire() tercio@0: self:SetHighlight() tercio@0: self:SetHighlightTexCoord() tercio@0: self:SetDisabled(false) tercio@0: end, tercio@0: tercio@0: -- ["OnRelease"] = nil, tercio@0: tercio@0: ["SetHighlight"] = function(self, ...) tercio@0: self.highlight:SetTexture(...) tercio@0: end, tercio@0: tercio@0: ["SetHighlightTexCoord"] = function(self, ...) tercio@0: local c = select("#", ...) tercio@0: if c == 4 or c == 8 then tercio@0: self.highlight:SetTexCoord(...) tercio@0: else tercio@0: self.highlight:SetTexCoord(0, 1, 0, 1) 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:EnableMouse(false) tercio@0: self.label:SetTextColor(0.5, 0.5, 0.5) tercio@0: else tercio@0: self.frame:EnableMouse(true) tercio@0: self.label:SetTextColor(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: -- create a Label type that we will hijack tercio@0: local label = AceGUI:Create("Label") tercio@0: tercio@0: local frame = label.frame tercio@0: frame:EnableMouse(true) tercio@0: frame:SetScript("OnEnter", Control_OnEnter) tercio@0: frame:SetScript("OnLeave", Control_OnLeave) tercio@0: frame:SetScript("OnMouseDown", Label_OnClick) tercio@0: tercio@0: local highlight = frame:CreateTexture(nil, "HIGHLIGHT") tercio@0: highlight:SetTexture(nil) tercio@0: highlight:SetAllPoints() tercio@0: highlight:SetBlendMode("ADD") tercio@0: tercio@0: label.highlight = highlight tercio@0: label.type = Type tercio@0: label.LabelOnAcquire = label.OnAcquire tercio@0: for method, func in pairs(methods) do tercio@0: label[method] = func tercio@0: end tercio@0: tercio@0: return label tercio@0: end tercio@0: tercio@0: AceGUI:RegisterWidgetType(Type, Constructor, Version) tercio@0: