annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-InteractiveLabel.lua @ 57:01b63b8ed811 v21

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