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