Mercurial > wow > hotcorners
comparison Libs/LibDBIcon-1.0/LibDBIcon-1.0.lua @ 20:9ad7f3c634f1 v8.0.1.020
- Updated Libraries.
author | Tercio |
---|---|
date | Fri, 20 Jul 2018 19:13:08 -0300 |
parents | 371e14cd2feb |
children | 3596dadf9a90 |
comparison
equal
deleted
inserted
replaced
19:817b319cd8ce | 20:9ad7f3c634f1 |
---|---|
1 --[[ | |
2 Name: DBIcon-1.0 | |
3 Revision: $Rev: 56 $ | |
4 Author(s): Rabbit (rabbit.magtheridon@gmail.com) | |
5 Description: Allows addons to register to recieve a lightweight minimap icon as an alternative to more heavy LDB displays. | |
6 Dependencies: LibStub | |
7 License: GPL v2 or later. | |
8 ]] | |
9 | |
10 --[[ | |
11 Copyright (C) 2008-2011 Rabbit | |
12 | |
13 This program is free software; you can redistribute it and/or | |
14 modify it under the terms of the GNU General Public License | |
15 as published by the Free Software Foundation; either version 2 | |
16 of the License, or (at your option) any later version. | |
17 | |
18 This program is distributed in the hope that it will be useful, | |
19 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 GNU General Public License for more details. | |
22 | |
23 You should have received a copy of the GNU General Public License | |
24 along with this program; if not, write to the Free Software | |
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
26 ]] | |
27 | 1 |
28 ----------------------------------------------------------------------- | 2 ----------------------------------------------------------------------- |
29 -- DBIcon-1.0 | 3 -- LibDBIcon-1.0 |
30 -- | 4 -- |
31 -- Disclaimer: Most of this code was ripped from Barrel but fixed, streamlined | 5 -- Allows addons to easily create a lightweight minimap icon as an alternative to heavier LDB displays. |
32 -- and cleaned up a lot so that it no longer sucks. | |
33 -- | 6 -- |
34 | 7 |
35 local DBICON10 = "LibDBIcon-1.0" | 8 local DBICON10 = "LibDBIcon-1.0" |
36 local DBICON10_MINOR = tonumber(("$Rev: 56 $"):match("(%d+)")) | 9 local DBICON10_MINOR = 36 -- Bump on changes |
37 if not LibStub then error(DBICON10 .. " requires LibStub.") end | 10 if not LibStub then error(DBICON10 .. " requires LibStub.") end |
38 local ldb = LibStub("LibDataBroker-1.1", true) | 11 local ldb = LibStub("LibDataBroker-1.1", true) |
39 if not ldb then error(DBICON10 .. " requires LibDataBroker-1.1.") end | 12 if not ldb then error(DBICON10 .. " requires LibDataBroker-1.1.") end |
40 local lib = LibStub:NewLibrary(DBICON10, DBICON10_MINOR) | 13 local lib = LibStub:NewLibrary(DBICON10, DBICON10_MINOR) |
41 if not lib then return end | 14 if not lib then return end |
43 lib.disabled = lib.disabled or nil | 16 lib.disabled = lib.disabled or nil |
44 lib.objects = lib.objects or {} | 17 lib.objects = lib.objects or {} |
45 lib.callbackRegistered = lib.callbackRegistered or nil | 18 lib.callbackRegistered = lib.callbackRegistered or nil |
46 lib.callbacks = lib.callbacks or LibStub("CallbackHandler-1.0"):New(lib) | 19 lib.callbacks = lib.callbacks or LibStub("CallbackHandler-1.0"):New(lib) |
47 lib.notCreated = lib.notCreated or {} | 20 lib.notCreated = lib.notCreated or {} |
48 | 21 lib.tooltip = lib.tooltip or CreateFrame("GameTooltip", "LibDBIconTooltip", UIParent, "GameTooltipTemplate") |
49 function lib:IconCallback(event, name, key, value, dataobj) | 22 |
23 function lib:IconCallback(event, name, key, value) | |
50 if lib.objects[name] then | 24 if lib.objects[name] then |
51 if key == "icon" then | 25 if key == "icon" then |
52 lib.objects[name].icon:SetTexture(value) | 26 lib.objects[name].icon:SetTexture(value) |
53 elseif key == "iconCoords" then | 27 elseif key == "iconCoords" then |
54 lib.objects[name].icon:UpdateCoord() | 28 lib.objects[name].icon:UpdateCoord() |
71 ldb.RegisterCallback(lib, "LibDataBroker_AttributeChanged__iconG", "IconCallback") | 45 ldb.RegisterCallback(lib, "LibDataBroker_AttributeChanged__iconG", "IconCallback") |
72 ldb.RegisterCallback(lib, "LibDataBroker_AttributeChanged__iconB", "IconCallback") | 46 ldb.RegisterCallback(lib, "LibDataBroker_AttributeChanged__iconB", "IconCallback") |
73 lib.callbackRegistered = true | 47 lib.callbackRegistered = true |
74 end | 48 end |
75 | 49 |
76 -- Tooltip code ripped from StatBlockCore by Funkydude | |
77 local function getAnchors(frame) | 50 local function getAnchors(frame) |
78 local x, y = frame:GetCenter() | 51 local x, y = frame:GetCenter() |
79 if not x or not y then return "CENTER" end | 52 if not x or not y then return "CENTER" end |
80 local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or "" | 53 local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or "" |
81 local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM" | 54 local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM" |
84 | 57 |
85 local function onEnter(self) | 58 local function onEnter(self) |
86 if self.isMoving then return end | 59 if self.isMoving then return end |
87 local obj = self.dataObject | 60 local obj = self.dataObject |
88 if obj.OnTooltipShow then | 61 if obj.OnTooltipShow then |
89 GameTooltip:SetOwner(self, "ANCHOR_NONE") | 62 lib.tooltip:SetOwner(self, "ANCHOR_NONE") |
90 GameTooltip:SetPoint(getAnchors(self)) | 63 lib.tooltip:SetPoint(getAnchors(self)) |
91 obj.OnTooltipShow(GameTooltip) | 64 obj.OnTooltipShow(lib.tooltip) |
92 GameTooltip:Show() | 65 lib.tooltip:Show() |
93 elseif obj.OnEnter then | 66 elseif obj.OnEnter then |
94 obj.OnEnter(self) | 67 obj.OnEnter(self) |
95 end | 68 end |
96 end | 69 end |
97 | 70 |
98 local function onLeave(self) | 71 local function onLeave(self) |
99 local obj = self.dataObject | 72 local obj = self.dataObject |
100 GameTooltip:Hide() | 73 lib.tooltip:Hide() |
101 if obj.OnLeave then obj.OnLeave(self) end | 74 if obj.OnLeave then obj.OnLeave(self) end |
102 end | 75 end |
103 | 76 |
104 -------------------------------------------------------------------------------- | 77 -------------------------------------------------------------------------------- |
105 | 78 |
106 local onClick, onMouseUp, onMouseDown, onDragStart, onDragStop, onDragEnd, updatePosition | 79 local onClick, onMouseUp, onMouseDown, onDragStart, onDragStop, updatePosition |
107 | 80 |
108 do | 81 do |
109 local minimapShapes = { | 82 local minimapShapes = { |
110 ["ROUND"] = {true, true, true, true}, | 83 ["ROUND"] = {true, true, true, true}, |
111 ["SQUARE"] = {false, false, false, false}, | 84 ["SQUARE"] = {false, false, false, false}, |
163 self:LockHighlight() | 136 self:LockHighlight() |
164 self.isMouseDown = true | 137 self.isMouseDown = true |
165 self.icon:UpdateCoord() | 138 self.icon:UpdateCoord() |
166 self:SetScript("OnUpdate", onUpdate) | 139 self:SetScript("OnUpdate", onUpdate) |
167 self.isMoving = true | 140 self.isMoving = true |
168 GameTooltip:Hide() | 141 lib.tooltip:Hide() |
169 end | 142 end |
170 end | 143 end |
171 | 144 |
172 function onDragStop(self) | 145 function onDragStop(self) |
173 self:SetScript("OnUpdate", nil) | 146 self:SetScript("OnUpdate", nil) |
195 button:SetFrameStrata("MEDIUM") | 168 button:SetFrameStrata("MEDIUM") |
196 button:SetSize(31, 31) | 169 button:SetSize(31, 31) |
197 button:SetFrameLevel(8) | 170 button:SetFrameLevel(8) |
198 button:RegisterForClicks("anyUp") | 171 button:RegisterForClicks("anyUp") |
199 button:RegisterForDrag("LeftButton") | 172 button:RegisterForDrag("LeftButton") |
200 button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight") | 173 button:SetHighlightTexture(136477) --"Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight" |
201 local overlay = button:CreateTexture(nil, "OVERLAY") | 174 local overlay = button:CreateTexture(nil, "OVERLAY") |
202 overlay:SetSize(53, 53) | 175 overlay:SetSize(53, 53) |
203 overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder") | 176 overlay:SetTexture(136430) --"Interface\\Minimap\\MiniMap-TrackingBorder" |
204 overlay:SetPoint("TOPLEFT") | 177 overlay:SetPoint("TOPLEFT") |
205 local background = button:CreateTexture(nil, "BACKGROUND") | 178 local background = button:CreateTexture(nil, "BACKGROUND") |
206 background:SetSize(20, 20) | 179 background:SetSize(20, 20) |
207 background:SetTexture("Interface\\Minimap\\UI-Minimap-Background") | 180 background:SetTexture(136467) --"Interface\\Minimap\\UI-Minimap-Background" |
208 background:SetPoint("TOPLEFT", 7, -5) | 181 background:SetPoint("TOPLEFT", 7, -5) |
209 local icon = button:CreateTexture(nil, "ARTWORK") | 182 local icon = button:CreateTexture(nil, "ARTWORK") |
210 icon:SetSize(17, 17) | 183 icon:SetSize(17, 17) |
211 icon:SetTexture(object.icon) | 184 icon:SetTexture(object.icon) |
212 icon:SetPoint("TOPLEFT", 7, -6) | 185 icon:SetPoint("TOPLEFT", 7, -6) |