vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 --[[
3 Name: PaintChips-2.0
4 Revision: $Rev: 14862 $
5 Author: Tekkub Stoutwrithe (tekkub@gmail.com)
6 Website: http://wiki.wowace.com/index.php/Metrognome_Embedded_Library
7 Documentation: http://wiki.wowace.com/index.php/Metrognome_Embedded_Library_Methods
8 SVN: svn://svn.wowace.com/root/trunk/Metrognome/Metrognome-2.0
9 Description: Color managing library
10 Dependencies: AceLibrary
11  
12 Need hex codes? http://www.december.com/html/spec/colorcodes.html
13 ]]
14  
15 local vmajor, vminor = "PaintChips-2.0", "$Revision: 14862 $"
16  
17 if not AceLibrary then error(vmajor .. " requires AceLibrary.") end
18 if not AceLibrary:IsNewVersion(vmajor, vminor) then return end
19  
20  
21 local colors = " white:FFFFFF black:000000 blue:0000FF magenta:ff00ff cyan:00ffff green:00ff00 yellow:ffff00 orange:ff7f00 red:ff0000"
22  
23 local lib = {}
24 local lib_mt = {}
25 setmetatable(lib, lib_mt)
26  
27  
28 -- Activate a new instance of this library
29 local function activate(self, oldLib, oldDeactivate)
30 if oldLib then self.vars = oldLib.vars
31 else
32 self.vars = {
33 rgb = {},
34 rgbperc = {},
35 hex = {},
36 }
37 end
38  
39 -- Register the Blizzy UI's colors
40 for i,v in pairs(DebuffTypeColor) do self:RegisterColor("DebuffType"..i, v.r*255, v.g*255, v.b*255) end
41 for i,v in pairs(RAID_CLASS_COLORS) do self:RegisterColor(i, v.r*255, v.g*255, v.b*255) end
42 for i=0,6 do
43 local r,g,b = GetItemQualityColor(i)
44 r,g,b = r*255, g*255, b*255
45 self:RegisterColor("ItemQuality"..i, r,g,b)
46 self:RegisterColor("ItemQuality"..getglobal("ITEM_QUALITY".. i.. "_DESC"), r,g,b)
47 end
48  
49 if oldDeactivate then oldDeactivate(oldLib) end
50 end
51  
52  
53 function lib:RegisterColor(name, hexorred, green, blue)
54 if type(name) == "string" and type(hexorred) == "number" and type(green) == "number" and type(blue) == "number" then
55 name = string.lower(name)
56 if hexorred <=1 and green <= 1 and blue <= 1 then hexorred, green, blue = hexorred*255, green*255, blue*255 end
57 local hex = string.format("%02x%02x%02x", hexorred, green, blue)
58 if not self.vars.hex[name] then self.vars.hex[name] = hex end
59 elseif type(name) == "string" and type(hexorred) == "string" and string.len(hexorred) == 6 then
60 name = string.lower(name)
61 if not self.vars.hex[name] then self.vars.hex[name] = hexorred end
62 else
63 self:error('Usage: RegisterColor("name", "hexcode") or RegisterColor("name", red, green, blue)')
64 end
65 end
66  
67  
68 -- Accepts hex strings in three formats: "|cAARRGGBB", "AARRGGBB", "RRGGBB"
69 -- string will be indexed by the exact string you pass, use this as the name for any query calls
70 function lib:RegisterHex(hex)
71 local l = string.len(hex)
72 if l < 6 then self:error("Invalid hex string") end
73 if l > 6 then hex = string.sub(hex, l-5) end
74  
75 local name = string.lower(hex)
76 if not self.vars.hex[name] then self.vars.hex[name] = hex end
77 end
78  
79  
80 function lib:GetHex(name)
81 if not name then return end
82 name = string.lower(name)
83  
84 if not self.vars.hex[name] then
85 local _, _, hex = string.find(colors, " "..name..":(%S+)")
86 if hex then self.vars.hex[name] = hex end
87 end
88  
89 return self.vars.hex[name]
90 end
91  
92  
93 function lib:GetRGB(name)
94 local hex = self:GetHex(name)
95 if not hex then return end
96  
97 if not self.vars.rgb[hex] then
98 local rhex, ghex,bhex = string.sub(hex,1,2), string.sub(hex,3,4), string.sub(hex,5,6)
99 local r,g,b = tonumber(rhex, 16), tonumber(ghex, 16), tonumber(bhex, 16)
100  
101 self.vars.rgb[hex] = {r,g,b}
102 end
103  
104 return self.vars.rgb[hex], unpack(self.vars.rgb[hex])
105 end
106  
107  
108 function lib:GetRGBPercent(name)
109 local hex = self:GetHex(name)
110 if not hex then return end
111  
112 if not self.vars.rgbperc[hex] then
113 local rhex, ghex,bhex = string.sub(hex,1,2), string.sub(hex,3,4), string.sub(hex,5,6)
114 local r,g,b = tonumber(rhex, 16)/255, tonumber(ghex, 16)/255, tonumber(bhex, 16)/255
115  
116 self.vars.rgbperc[hex] = {r,g,b}
117 end
118  
119 return self.vars.rgbperc[hex], unpack(self.vars.rgbperc[hex])
120 end
121  
122  
123 -- Syntax sugar.
124 -- local C = AceLibrary("PaintChips-2.0")
125 -- local hexcolor = C"white"
126 lib_mt.__call = lib.GetHex
127  
128  
129 --------------------------------
130 -- Load this bitch! --
131 --------------------------------
132 AceLibrary:Register(lib, vmajor, vminor, activate)
133