vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Name: Crayon-2.0
3 Revision: $Rev: 7622 $
4 Author(s): ckknight (ckknight@gmail.com)
5 Website: http://ckknight.wowinterface.com/
6 Documentation: http://wiki.wowace.com/index.php/Crayon-2.0
7 SVN: http://svn.wowace.com/root/trunk/CrayonLib/Crayon-2.0
8 Description: A library to provide coloring tools.
9 Dependencies: AceLibrary
10 ]]
11  
12 --Theondry (theondry@gmail.com) added the purple. yell at me if it's wrong, please
13  
14 local MAJOR_VERSION = "Crayon-2.0"
15 local MINOR_VERSION = "$Revision: 7622 $"
16  
17 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
18 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
19  
20 local Crayon = {}
21  
22 Crayon.COLOR_HEX_RED = "ff0000"
23 Crayon.COLOR_HEX_ORANGE = "ff7f00"
24 Crayon.COLOR_HEX_YELLOW = "ffff00"
25 Crayon.COLOR_HEX_GREEN = "00ff00"
26 Crayon.COLOR_HEX_WHITE = "ffffff"
27 Crayon.COLOR_HEX_COPPER = "eda55f"
28 Crayon.COLOR_HEX_SILVER = "c7c7cf"
29 Crayon.COLOR_HEX_GOLD = "ffd700"
30 Crayon.COLOR_HEX_PURPLE = "9980CC"
31  
32 function Crayon:Colorize(hexColor, text)
33 return "|cff" .. tostring(hexColor or 'ffffff') .. tostring(text) .. "|r"
34 end
35 function Crayon:Red(text) return self:Colorize(self.COLOR_HEX_RED, text) end
36 function Crayon:Orange(text) return self:Colorize(self.COLOR_HEX_ORANGE, text) end
37 function Crayon:Yellow(text) return self:Colorize(self.COLOR_HEX_YELLOW, text) end
38 function Crayon:Green(text) return self:Colorize(self.COLOR_HEX_GREEN, text) end
39 function Crayon:White(text) return self:Colorize(self.COLOR_HEX_WHITE, text) end
40 function Crayon:Copper(text) return self:Colorize(self.COLOR_HEX_COPPER, text) end
41 function Crayon:Silver(text) return self:Colorize(self.COLOR_HEX_SILVER, text) end
42 function Crayon:Gold(text) return self:Colorize(self.COLOR_HEX_GOLD, text) end
43 function Crayon:Purple(text) return self:Colorize(self.COLOR_HEX_PURPLE, text) end
44  
45 local inf = 1/0
46  
47 function Crayon:GetThresholdColor(quality, worst, worse, normal, better, best)
48 self:argCheck(quality, 2, "number")
49 if quality ~= quality or quality == inf or quality == -inf then
50 return 1, 1, 1
51 end
52 if not best then
53 worst = 0
54 worse = 0.25
55 normal = 0.5
56 better = 0.75
57 best = 1
58 end
59  
60 if worst < best then
61 if (worse == better and quality == worse) or (worst == best and quality == worst) then
62 return 1, 1, 0
63 elseif quality <= worst then
64 return 1, 0, 0
65 elseif quality <= worse then
66 return 1, 0.5 * (quality - worst) / (worse - worst), 0
67 elseif quality <= normal then
68 return 1, 0.5 + 0.5 * (quality - worse) / (normal - worse), 0
69 elseif quality <= better then
70 return 1 - 0.5 * (quality - normal) / (better - normal), 1, 0
71 elseif quality <= best then
72 return 0.5 - 0.5 * (quality - better) / (best - better), 1, 0
73 else
74 return 0, 1, 0
75 end
76 else
77 if (worse == better and quality == worse) or (worst == best and quality == worst) then
78 return 1, 1, 0
79 elseif quality >= worst then
80 return 1, 0, 0
81 elseif quality >= worse then
82 return 1, 0.5 - 0.5 * (quality - worse) / (worst - worse), 0
83 elseif quality >= normal then
84 return 1, 1 - 0.5 * (quality - normal) / (worse - normal), 0
85 elseif quality >= better then
86 return 0.5 + 0.5 * (quality - better) / (normal - better), 1, 0
87 elseif quality >= best then
88 return 0.5 * (quality - best) / (better - best), 1, 0
89 else
90 return 0, 1, 0
91 end
92 end
93 end
94  
95 function Crayon:GetThresholdHexColor(quality, worst, worse, normal, better, best)
96 local r, g, b = self:GetThresholdColor(quality, worst, worse, normal, better, best)
97 return string.format("%02x%02x%02x", r*255, g*255, b*255)
98 end
99  
100 function Crayon:GetThresholdColorTrivial(quality, worst, worse, normal, better, best)
101 self:argCheck(quality, 2, "number")
102 if quality ~= quality or quality == inf or quality == -inf then
103 return 1, 1, 1
104 end
105 if not best then
106 worst = 0
107 worse = 0.25
108 normal = 0.5
109 better = 0.75
110 best = 1
111 end
112  
113 if worst < best then
114 if worse == better and normal == worse then
115 return 1, 1, 0
116 elseif quality <= worst then
117 return 1, 0, 0
118 elseif quality <= worse then
119 return 1, 0.5 * (quality - worst) / (worse - worst), 0
120 elseif quality <= normal then
121 return 1, 0.5 + 0.5 * (quality - worse) / (normal - worse), 0
122 elseif quality <= better then
123 return 1 - (quality - normal) / (better - normal), 1, 0
124 elseif quality <= best then
125 local x = 0.5 * (quality - better) / (best - better)
126 return x, 1 - x, x
127 else
128 return 0.5, 0.5, 0.5
129 end
130 else
131 if worse == better and normal == worse then
132 return 1, 1, 0
133 elseif quality >= worst then
134 return 1, 0, 0
135 elseif quality >= worse then
136 return 1, 0.5 - 0.5 * (quality - worse) / (worst - worse), 0
137 elseif quality >= normal then
138 return 1, 1 - 0.5 * (quality - normal) / (worse - normal), 0
139 elseif quality >= better then
140 return (quality - better) / (normal - better), 1, 0
141 elseif quality >= best then
142 local x = 0.5 * (quality - best) / (better - best)
143 return 0.5 - x, 0.5 + x, 0.5 - x
144 else
145 return 0.5, 0.5, 0.5
146 end
147 end
148 end
149  
150 function Crayon:GetThresholdHexColorTrivial(quality, worst, worse, normal, better, best)
151 local r, g, b = self:GetThresholdColorTrivial(quality, worst, worse, normal, better, best)
152 return string.format("%02x%02x%02x", r*255, g*255, b*255)
153 end
154  
155 AceLibrary:Register(Crayon, MAJOR_VERSION, MINOR_VERSION)
156 Crayon = nil