improved frame placement code, will take advantage of the build-in blizzy code to always save position relative to the nearest edge (or center)

This commit is contained in:
Hendrik Leppkes
2007-11-30 15:11:00 +00:00
parent cfa080b1cf
commit 038d5dacae
2 changed files with 51 additions and 13 deletions
+20 -6
View File
@@ -15,6 +15,7 @@ Bartender4.Bar = {}
Bartender4.Bar.prototype = Bar
function Bartender4.Bar:Create(id, template, config)
local bar = setmetatable(CreateFrame("Button", ("BT4Bar%s"):format(id), UIParent, template), Bar_MT)
bar.id = id
bar:EnableMouse(false)
bar:SetMovable(true)
@@ -72,6 +73,14 @@ do
end
end
function Bar:ApplyConfig(config)
if config then
self.config = config
end
self:Lock()
self:LoadPosition()
end
function Bar:Unlock()
self:EnableMouse(true)
self:SetScript("OnEnter", barOnEnter)
@@ -104,18 +113,23 @@ function Bar:Lock()
end
function Bar:LoadPosition()
local x, y, s = self.config.x, self.config.y, self:GetEffectiveScale()
if not self.config.Position then return end
local pos = self.config.Position
local x, y, s = pos.x, pos.y, UIParent:GetEffectiveScale()
local point, relPoint = pos.point, pos.relPoint
x, y = x/s, y/s
self:ClearAllPoints()
self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", x, y)
self:SetPoint(point, UIParent, relPoint, x, y)
end
function Bar:SavePosition()
local x, y = self:GetLeft(), self:GetBottom()
local s = self:GetEffectiveScale()
if not self.config.Position then self.config.Position = {} end
local pos = self.config.Position
local point, parent, relPoint, x, y = self:GetPoint()
local s = UIParent:GetEffectiveScale()
x, y = x*s, y*s
self.config.x = x
self.config.y = y
pos.x, pos.y = x, y
pos.point, pos.relPoint = point, relPoint
end
function Bar:SetSize(width, height)