api: fix cache and limits in gradient color

This commit is contained in:
shagu
2019-05-21 22:46:57 +02:00
parent fcda1664ab
commit ef9f4519f1
+17 -15
View File
@@ -943,11 +943,13 @@ end
-- return r,g,b and hexcolor
local gradientcolors = {}
function pfUI.api.GetColorGradient(perc)
-- fallback to black on bad numbers
if perc < 0 or perc > 1 then return 0,0,0,"|cff000000" end
perc = perc > 1 and 1 or perc
perc = perc < 0 and 0 or perc
if not gradientcolors[perc] then
local index = perc
if not gradientcolors[index] then
local r1, g1, b1, r2, g2, b2
if perc <= 0.5 then
perc = perc * 2
r1, g1, b1 = 1, 0, 0
@@ -958,22 +960,22 @@ function pfUI.api.GetColorGradient(perc)
r2, g2, b2 = 0, 1, 0
end
local r = r1 + (r2 - r1)*perc
local g = g1 + (g2 - g1)*perc
local b = b1 + (b2 - b1)*perc
local r = round(r1 + (r2 - r1) * perc, 4)
local g = round(g1 + (g2 - g1) * perc, 4)
local b = round(b1 + (b2 - b1) * perc, 4)
local h = pfUI.api.rgbhex(r,g,b)
gradientcolors[perc] = {}
gradientcolors[perc].r = r
gradientcolors[perc].g = g
gradientcolors[perc].b = b
gradientcolors[perc].h = h
gradientcolors[index] = {}
gradientcolors[index].r = r
gradientcolors[index].g = g
gradientcolors[index].b = b
gradientcolors[index].h = h
end
return gradientcolors[perc].r,
gradientcolors[perc].g,
gradientcolors[perc].b,
gradientcolors[perc].h
return gradientcolors[index].r,
gradientcolors[index].g,
gradientcolors[index].b,
gradientcolors[index].h
end
-- [ GetNoNameObject ] --