annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-InteractiveLabel.lua @ 11:371e14cd2feb

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