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