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

http://github.com/Asphyxia/Tukui · Lua · 77 lines · 58 code · 14 blank · 5 comment · 15 complexity · 99043593e36125d8c32681aadfa3d6ec MD5 · raw file

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