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