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
+31 -7
View File
@@ -23,19 +23,43 @@ function BT4ActionBars:OnInitialize()
self.db = Bartender4.db:RegisterNamespace("ActionBars", defaults)
for i=1,10 do
actionbars[i] = ActionBar:Create(i, self.db.profile.Bars[i])
actionbars[i] = self:Create(i, self.db.profile.Bars[i])
end
self.db.RegisterCallback(self, "OnProfileChanged", "ApplyConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "ApplyConfig")
end
function BT4ActionBars:OnEnable()
-- do stuff
end
function BT4ActionBars:ApplyConfig()
for i,v in ipairs(actionbars) do
v:ApplyConfig(self.db.profile.Bars[k])
end
end
function ActionBar:Create(id, config)
local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateDriverTemplate", config), ActionBar_MT)
if not config.x or not config.y then
bar:SetPoint("CENTER", 0, -250 + (id-1) * 38)
local initialPosition
do
function initialPosition(bar)
bar:SetPoint("CENTER", 0, -250 + (bar.id-1) * 38)
bar:SavePosition()
else
bar:LoadPosition()
end
end
function BT4ActionBars:Create(id, config)
local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateDriverTemplate", config), ActionBar_MT)
-- TODO: Setup Buttons and set bar width before pulling initial position
bar:ApplyConfig()
-- for debugging only
bar:Unlock()
return bar
end
function ActionBar:ApplyConfig(config)
Bar.ApplyConfig(self, config)
if not self.config.Position then initialPosition(self) end
end
+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)