From acc67ba2a099476a38bbdb0dcf1394c9e44a808a Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Tue, 20 Jan 2009 15:33:02 +0100 Subject: [PATCH] First work on LibWindow-1.1 usage, plumbing for new bar resizing/button positioning --- .pkgmeta | 1 + Bar.lua | 53 +++++++++++++++++++++++++++++++++----------------- Bartender4.lua | 2 ++ Bartender4.toc | 3 ++- MicroMenu.lua | 4 +++- PetBar.lua | 1 - StanceBar.lua | 4 +++- 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/.pkgmeta b/.pkgmeta index 4819ad5..bd74148 100644 --- a/.pkgmeta +++ b/.pkgmeta @@ -13,3 +13,4 @@ externals: libs/AceConfig-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConfig-3.0 libs/LibKeyBound-1.0: svn://svn.wowace.com/wow/libkeybound-1-0/mainline/trunk/LibKeyBound-1.0 libs/LibDBIcon-1.0: svn://svn.wowace.com/wow/libdbicon-1-0/mainline/trunk/LibDBIcon-1.0 + libs/LibWindow-1.1: svn://svn.wowace.com/wow/libwindow-1-1/mainline/trunk/LibWindow-1.1 diff --git a/Bar.lua b/Bar.lua index e1d5a76..a4b3592 100644 --- a/Bar.lua +++ b/Bar.lua @@ -11,7 +11,6 @@ local table_concat, table_insert = table.concat, table.insert ===================================================================================]]-- local defaults = { - scale = 1, alpha = 1, fadeout = false, fadeoutalpha = 0.1, @@ -20,10 +19,14 @@ local defaults = { possess = true, stance = {}, }, + position = { + scale = 1, + }, clickthrough = false, } local Sticky = LibStub("LibSimpleSticky-1.0") +local LibWin = LibStub("LibWindow-1.1") local snapBars = { WorldFrame, UIParent } local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick, barOnUpdateFunc, barOnAttributeChanged @@ -170,7 +173,11 @@ function Bar:ApplyConfig(config) if config then self.config = config end + LibWin.RegisterConfig(self, self.config.position) + + self:UpgradeConfig() if self.disabled then return end + if Bartender4.Locked then self:Lock() else @@ -183,6 +190,29 @@ function Bar:ApplyConfig(config) self:InitVisibilityDriver() end +function Bar:UpgradeConfig() + local version = self.config.version or 1 + if version < 2 then + -- LibWindow migration, move scale into position + if self.config.scale then + self.config.position.scale = self.config.scale + self.config.scale = nil + end + -- LibWindow migration, update position data + do + local pos = self.config.position + self:SetScale(pos.scale) + local x, y, s = pos.x, pos.y, self:GetEffectiveScale() + local point, relPoint = pos.point, pos.relPoint + x, y = x/s, y/s + self:ClearSetPoint(point, UIParent, relPoint, x, y) + LibWin.SavePosition(self) + pos.relPoint = nil + end + end + self.config.version = Bartender4.CONFIG_VERSION +end + function Bar:Unlock() if self.disabled or self.unlocked then return end self.unlocked = true @@ -206,22 +236,11 @@ function Bar:StopDragging() end function Bar:LoadPosition() - if not self.config.position then return end - local pos = self.config.position - local x, y, s = pos.x, pos.y, self:GetEffectiveScale() - local point, relPoint = pos.point, pos.relPoint - x, y = x/s, y/s - self:ClearSetPoint(point, UIParent, relPoint, x, y) + LibWin.RestorePosition(self) end function Bar:SavePosition() - 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 = self:GetEffectiveScale() - x, y = x*s, y*s - pos.x, pos.y = x, y - pos.point, pos.relPoint = point, relPoint + LibWin.SavePosition(self) end function Bar:SetSize(width, height) @@ -243,15 +262,13 @@ function Bar:SetConfigAlpha(alpha) end function Bar:GetConfigScale() - return self.config.scale + return self.config.position.scale end function Bar:SetConfigScale(scale) if scale then - self.config.scale = scale + LibWin.SetScale(self, scale) end - self:SetScale(self.config.scale) - self:LoadPosition() end function Bar:GetClickThrough() diff --git a/Bartender4.lua b/Bartender4.lua index 0c07f26..4cf841f 100644 --- a/Bartender4.lua +++ b/Bartender4.lua @@ -20,6 +20,8 @@ local defaults = { } } +Bartender4.CONFIG_VERSION = 2 + function Bartender4:OnInitialize() self.db = LibStub("AceDB-3.0"):New("Bartender4DB", defaults) self.db.RegisterCallback(self, "OnProfileChanged", "UpdateModuleConfigs") diff --git a/Bartender4.toc b/Bartender4.toc index 76fa3fa..deeba23 100644 --- a/Bartender4.toc +++ b/Bartender4.toc @@ -5,7 +5,7 @@ ## Author: Nevcairiel ## X-Email: h.leppkes AT gmail DOT com ## SavedVariables: Bartender4DB -## OptionalDeps: Ace3, ButtonFacade, LibKeyBound-1.0, LibDBIcon-1.0 +## OptionalDeps: Ace3, ButtonFacade, LibKeyBound-1.0, LibDBIcon-1.0, LibWindow-1.1 ## X-Category: Action Bars ## Version: 4.2.6 @@ -29,6 +29,7 @@ libs\AceConfig-3.0\AceConfig-3.0.xml libs\LibKeyBound-1.0\lib.xml libs\LibDBIcon-1.0\LibDBIcon-1.0.lua +libs\LibWindow-1.1\LibWindow-1.1.lua #@end-no-lib-strip@ libs\SimpleSticky.lua diff --git a/MicroMenu.lua b/MicroMenu.lua index 8efbc51..85dd842 100644 --- a/MicroMenu.lua +++ b/MicroMenu.lua @@ -17,7 +17,9 @@ local defaults = { profile = Bartender4:Merge({ possess = false, }, padding = -3, - scale = 0.8, + position = { + scale = 0.8, + }, }, Bartender4.ButtonBar.defaults) } function MicroMenuMod:OnInitialize() diff --git a/PetBar.lua b/PetBar.lua index f24e726..31a53de 100644 --- a/PetBar.lua +++ b/PetBar.lua @@ -11,7 +11,6 @@ local PetBar = setmetatable({}, {__index = ButtonBar}) local defaults = { profile = Bartender4:Merge({ enabled = true, - scale = 1.0, hidehotkey = true, visibility = { nopet = true, diff --git a/StanceBar.lua b/StanceBar.lua index 8de7a52..149f44f 100644 --- a/StanceBar.lua +++ b/StanceBar.lua @@ -17,7 +17,9 @@ local KeyBound = LibStub("LibKeyBound-1.0") local defaults = { profile = Bartender4:Merge({ enabled = true, - scale = 1.5, + position = { + scale = 1.5, + }, hidehotkey = true, }, Bartender4.ButtonBar.defaults) }