Quantcast
local addonName, addon = ...
local L = addon.L

function addon:ColorGradient(perc, ...)
    local num = select("#", ...)
    local hexes = type(select(1, ...)) == "string"

    if perc == 1 then
        return select(num-2, ...), select(num-1, ...), select(num, ...)
    end

    num = num / 3

    local segment, relperc = math.modf(perc*(num-1))
    local r1, g1, b1, r2, g2, b2
    r1, g1, b1 = select((segment*3)+1, ...), select((segment*3)+2, ...), select((segment*3)+3, ...)
    r2, g2, b2 = select((segment*3)+4, ...), select((segment*3)+5, ...), select((segment*3)+6, ...)

    if not r2 or not g2 or not b2 then
        return r1, g1, b1
    else
        return r1 + (r2-r1)*relperc,
        g1 + (g2-g1)*relperc,
        b1 + (b2-b1)*relperc
    end
end

function addon:SavePosition(f)
    local name = f:GetName()
    local x,y = f:GetLeft(), f:GetTop()
    local s = f:GetEffectiveScale()

    x,y = x*s,y*s

    local opt = addon.db.profile.positions[name]
    if not opt then
        addon.db.profile.positions[name] = {}
        opt = addon.db.profile.positions[name]
    end
    opt.PosX = x
    opt.PosY = y
end

function addon:RestorePosition(f)
    local name = f:GetName()
    local opt = addon.db.profile.positions[name]
    if not opt then
        addon.db.profile.positions[name] = {}
        opt = addon.db.profile.positions[name]
    end

    local x = opt.PosX
    local y = opt.PosY

    local s = f:GetEffectiveScale()

    if not x or not y then
        f:ClearAllPoints()
        f:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
        return
    end

    x,y = x/s,y/s

    f:ClearAllPoints()
    f:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y)
end