PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/unitframes/core/oUF/colors.lua

http://github.com/Asphyxia/Tukui
Lua | 77 lines | 58 code | 14 blank | 5 comment | 10 complexity | 99043593e36125d8c32681aadfa3d6ec MD5 | raw file
 1local WoW41 = select(4, GetBuildInfo()) == 40100
 2
 3local parent, ns = ...
 4local oUF = ns.oUF
 5local Private = oUF.Private
 6
 7local frame_metatable = Private.frame_metatable
 8
 9local colors = {
10	smooth = {
11		1, 0, 0,
12		1, 1, 0,
13		0, 1, 0
14	},
15	disconnected = {.6, .6, .6},
16	tapped = {.6,.6,.6},
17	class = {},
18	reaction = {},
19}
20
21-- We do this because people edit the vars directly, and changing the default
22-- globals makes SPICE FLOW!
23if(IsAddOnLoaded'!ClassColors' and CUSTOM_CLASS_COLORS) then
24	local updateColors = function()
25		for eclass, color in next, CUSTOM_CLASS_COLORS do
26			colors.class[eclass] = {color.r, color.g, color.b}
27		end
28
29		local oUF = ns.oUF or _G[parent]
30		if(oUF) then
31			for _, obj in next, oUF.objects do
32				obj:UpdateAllElements("CUSTOM_CLASS_COLORS")
33			end
34		end
35	end
36
37	updateColors()
38	CUSTOM_CLASS_COLORS:RegisterCallback(updateColors)
39else
40	for eclass, color in next, RAID_CLASS_COLORS do
41		colors.class[eclass] = {color.r, color.g, color.b}
42	end
43end
44
45for eclass, color in next, FACTION_BAR_COLORS do
46	colors.reaction[eclass] = {color.r, color.g, color.b}
47end
48
49-- http://www.wowwiki.com/ColorGradient
50local inf = math.huge
51local ColorGradient = function(perc, ...)
52	-- Translate divison by zeros into 0, so we don't blow select.
53	-- We check perc against itself because we rely on the fact that NaN can't equal NaN.
54	if(perc ~= perc or perc == inf) then perc = 0 end
55
56	if perc >= 1 then
57		local r, g, b = select(select('#', ...) - 2, ...)
58		return r, g, b
59	elseif perc <= 0 then
60		local r, g, b = ...
61		return r, g, b
62	end
63
64	local num = select('#', ...) / 3
65	local segment, relperc = math.modf(perc*(num-1))
66	local r1, g1, b1, r2, g2, b2 = select((segment*3)+1, ...)
67
68	return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc
69end
70
71Private.colors = colors
72
73oUF.colors = colors
74oUF.ColorGradient = ColorGradient
75
76frame_metatable.__index.colors = colors
77frame_metatable.__index.ColorGradient = ColorGradient