/trunk/CompactBars/libs
local sbar = LibStub:NewLibrary(major, minor) |
if( not sbar ) then return end |
local scaleinfo |
local default = { |
texture = "Interface\\ChatFrame\\ChatFrameBackground" |
} |
--*------------------------------------------- |
-- private methods |
--*------------------------------------------- |
local function getMaxPos() |
local maxpos = 0 |
if not bars then return false end |
for _, bar in pairs(bars) do |
if bar.pos and maxpos < bar.pos then |
maxpos = bar.pos |
end |
end |
return maxpos |
end |
function sbar:clearBar(inp) |
if inp.frame then inp.frame:Hide() end |
for k, v in pairs(inp) do |
-- simple bubble sort |
local n=1 |
while bartupd[n] do n=n+1 end; n=n-1 |
qsort(bartupd, 1, n, function(x, y) return (x.start+x.dur) < (y.start + y.dur) end) |
qsort(bartupd, 1, n, function(x, y) return (x.start+x.dur) <= (y.start + y.dur) end) |
-- |
del(bartupd) |
end |
-- |
local function changeFrameLevel(bars) |
if not bars or #bars <= 1 then return end |
local maxfl = #bars + 2 |
for _, bar in pairs(bars) do |
if bar.frame:GetFrameLevel() >= maxfl then |
bar.frame:SetFrameLevel(2) |
else |
bar.frame:SetFrameLevel(bar.frame:GetFrameLevel() + 1) |
end |
end |
end |
-- check is relative to the scale |
local function checkDistance(f1, f2) |
if scaleinfo.horizontal then |
local pos1 = f1:GetHeight() + f1:GetLeft() |
local pos2 = f2:GetHeight() + f2:GetLeft() |
return math.abs(pos1 - pos2) |
else |
local pos1 = f1:GetTop() |
local pos2 = f2:GetTop() |
DEFAULT_CHAT_FRAME:AddMessage(pos1) |
DEFAULT_CHAT_FRAME:AddMessage(pos2) |
return math.abs(pos1 - pos2) |
end |
end |
local function overlapRotate() |
if not bars or #bars == 0 then return end |
-- |
for i = 0, 10 do -- go through every position |
local tab = newList() |
local first = true |
for _, bar in pairs(bars) do |
if bar.pos and bar.pos == i then |
table.insert(tab, bar) |
end |
end |
-- now check if there is a frame that is near to another frame |
for _, bar in pairs(tab) do |
local ftab = {} |
tinsert(ftab, bar) |
for _, barcheck in pairs(tab) do |
if barcheck ~= bar then |
if checkDistance(bar.frame, barcheck.frame) < 5 then |
DEFAULT_CHAT_FRAME:AddMessage(checkDistance(bar.frame, barcheck.frame)) |
tinsert(ftab, barcheck) |
end |
end |
end |
if #ftab > 1 then |
DEFAULT_CHAT_FRAME:AddMessage(#ftab.."test") |
changeFrameLevel(ftab) |
end |
ftab = nil |
end |
tab = nil |
end |
end |
local function checkLog() |
if not scaleinfo.amaxtimes then return false end |
local count = 0 |
end |
-- |
local el = 0 |
local overlap = 0 |
local function OnUpdate(self, elapsed) |
el = el + elapsed |
overlap = overlap + elapsed |
--if el < 1 then return end |
local count = 0 |
if bars then |
else |
OnVerticalUpdate(bars, el, scaleinfo.maxneg, scaleinfo.maxtime, scaleinfo.loflag) |
end |
if overlap >= 0.8 then |
--overlapRotate() |
overlap = 0 |
updateBarsFrameLevel() |
end |
el = 0 |
end |
local function createVericalScale(height, maxtime, steps, handler, loflag, texture) |
f:SetScript("OnMouseDown", OnDragStart) |
f:SetScript("OnMouseUp", OnDragStop) |
local maintexture = f:CreateTexture(nil, "BACKGROUND") |
maintexture:SetTexture(texture or default.texture) |
--maintexture:SetTexture(texture or default.texture) |
maintexture:SetPoint("CENTER", 0, -1) |
maintexture:SetHeight(2) |
maintexture:SetVertexColor(1, 1, 1, 1) |
font:SetText(string.sub(tostring(secforstep * i), 1, 3)) |
end |
local tex = f:CreateTexture(nil, "BACKGROUND") |
tex:SetTexture(texture or default.texture) |
--tex:SetTexture(texture or default.texture) |
tex:SetHeight(6) |
tex:SetWidth(2) |
tex:SetVertexColor(1, 1, 1, 1) |
--tex:SetVertexColor(1, 1, 1, 1) |
if not loflag then |
if i == steps then |
tex:SetPoint("BOTTOMLEFT", width -2, 16) |
font:SetText(tex) |
end |
local tex = f:CreateTexture(nil, "BACKGROUND") |
tex:SetTexture(texture or default.texture) |
--tex:SetTexture(texture or default.texture) |
tex:SetHeight(6) |
tex:SetWidth(2) |
tex:SetVertexColor(1, 1, 1, 1) |
end |
local function getMaxPos() |
local maxpos = 0 |
if not bars then return false end |
for _, bar in pairs(bars) do |
if bar.pos and maxpos < bar.pos then |
maxpos = bar.pos |
end |
end |
return maxpos |
end |
local function updateFrameLevel() |
if not getMaxPos() then return end |
for i = 0, getMaxPos() do |