annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-InteractiveLabel.lua @ 44:7f9a7d2000ea

Added tag r43-release for changeset 2681843ada1c
author Tercio
date Tue, 28 Mar 2017 19:59:18 -0300
parents 52973d00a183
children dbf04157d63e
rev   line source
Tercio@23 1 --[[-----------------------------------------------------------------------------
Tercio@23 2 InteractiveLabel Widget
Tercio@23 3 -------------------------------------------------------------------------------]]
Tercio@23 4 local Type, Version = "InteractiveLabel", 20
Tercio@23 5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
Tercio@23 6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
Tercio@23 7
Tercio@23 8 -- Lua APIs
Tercio@23 9 local select, pairs = select, pairs
Tercio@23 10
Tercio@23 11 -- WoW APIs
Tercio@23 12 local CreateFrame, UIParent = CreateFrame, UIParent
Tercio@23 13
Tercio@23 14 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
Tercio@23 15 -- List them here for Mikk's FindGlobals script
Tercio@23 16 -- GLOBALS: GameFontHighlightSmall
Tercio@23 17
Tercio@23 18 --[[-----------------------------------------------------------------------------
Tercio@23 19 Scripts
Tercio@23 20 -------------------------------------------------------------------------------]]
Tercio@23 21 local function Control_OnEnter(frame)
Tercio@23 22 frame.obj:Fire("OnEnter")
Tercio@23 23 end
Tercio@23 24
Tercio@23 25 local function Control_OnLeave(frame)
Tercio@23 26 frame.obj:Fire("OnLeave")
Tercio@23 27 end
Tercio@23 28
Tercio@23 29 local function Label_OnClick(frame, button)
Tercio@23 30 frame.obj:Fire("OnClick", button)
Tercio@23 31 AceGUI:ClearFocus()
Tercio@23 32 end
Tercio@23 33
Tercio@23 34 --[[-----------------------------------------------------------------------------
Tercio@23 35 Methods
Tercio@23 36 -------------------------------------------------------------------------------]]
Tercio@23 37 local methods = {
Tercio@23 38 ["OnAcquire"] = function(self)
Tercio@23 39 self:LabelOnAcquire()
Tercio@23 40 self:SetHighlight()
Tercio@23 41 self:SetHighlightTexCoord()
Tercio@23 42 self:SetDisabled(false)
Tercio@23 43 end,
Tercio@23 44
Tercio@23 45 -- ["OnRelease"] = nil,
Tercio@23 46
Tercio@23 47 ["SetHighlight"] = function(self, ...)
Tercio@23 48 self.highlight:SetTexture(...)
Tercio@23 49 end,
Tercio@23 50
Tercio@23 51 ["SetHighlightTexCoord"] = function(self, ...)
Tercio@23 52 local c = select("#", ...)
Tercio@23 53 if c == 4 or c == 8 then
Tercio@23 54 self.highlight:SetTexCoord(...)
Tercio@23 55 else
Tercio@23 56 self.highlight:SetTexCoord(0, 1, 0, 1)
Tercio@23 57 end
Tercio@23 58 end,
Tercio@23 59
Tercio@23 60 ["SetDisabled"] = function(self,disabled)
Tercio@23 61 self.disabled = disabled
Tercio@23 62 if disabled then
Tercio@23 63 self.frame:EnableMouse(false)
Tercio@23 64 self.label:SetTextColor(0.5, 0.5, 0.5)
Tercio@23 65 else
Tercio@23 66 self.frame:EnableMouse(true)
Tercio@23 67 self.label:SetTextColor(1, 1, 1)
Tercio@23 68 end
Tercio@23 69 end
Tercio@23 70 }
Tercio@23 71
Tercio@23 72 --[[-----------------------------------------------------------------------------
Tercio@23 73 Constructor
Tercio@23 74 -------------------------------------------------------------------------------]]
Tercio@23 75 local function Constructor()
Tercio@23 76 -- create a Label type that we will hijack
Tercio@23 77 local label = AceGUI:Create("Label")
Tercio@23 78
Tercio@23 79 local frame = label.frame
Tercio@23 80 frame:EnableMouse(true)
Tercio@23 81 frame:SetScript("OnEnter", Control_OnEnter)
Tercio@23 82 frame:SetScript("OnLeave", Control_OnLeave)
Tercio@23 83 frame:SetScript("OnMouseDown", Label_OnClick)
Tercio@23 84
Tercio@23 85 local highlight = frame:CreateTexture(nil, "HIGHLIGHT")
Tercio@23 86 highlight:SetTexture(nil)
Tercio@23 87 highlight:SetAllPoints()
Tercio@23 88 highlight:SetBlendMode("ADD")
Tercio@23 89
Tercio@23 90 label.highlight = highlight
Tercio@23 91 label.type = Type
Tercio@23 92 label.LabelOnAcquire = label.OnAcquire
Tercio@23 93 for method, func in pairs(methods) do
Tercio@23 94 label[method] = func
Tercio@23 95 end
Tercio@23 96
Tercio@23 97 return label
Tercio@23 98 end
Tercio@23 99
Tercio@23 100 AceGUI:RegisterWidgetType(Type, Constructor, Version)
Tercio@23 101