From c285b34964f9d211a6a48654646326bcaae8afd9 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Thu, 26 Mar 2009 14:49:10 +0100 Subject: [PATCH] Added options to center the bars both vertically and horizontally. --- Options/Bar.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/Options/Bar.lua b/Options/Bar.lua index b3ccbf9..988a2a2 100644 --- a/Options/Bar.lua +++ b/Options/Bar.lua @@ -17,7 +17,7 @@ local function round(num, idp) end -- option utilty functions -local optGetter, optSetter, visibilityGetter, visibilitySetter, customEnabled, customDisabled, customCopy, clickThroughVis, posGet, posSet +local optGetter, optSetter, visibilityGetter, visibilitySetter, customEnabled, customDisabled, customCopy, clickThroughVis, posGet, posSet, centerHorz, centerVert, resetPos do local getBar, optionMap, callFunc -- maps option keys to function names @@ -109,6 +109,43 @@ do bar.config.position[opt] = value bar:LoadPosition() end + + function centerHorz(info) + local bar = getBar(info[2]) + local pos = bar.config.position + local x_mod = (pos.growHorizontal == "RIGHT") and -1 or 1 + pos.x = (bar.overlay:GetWidth() / 2) * pos.scale * x_mod + if pos.point == "CENTER" or pos.point == "LEFT" or pos.point == "RIGHT" then -- no special handling + pos.point = "CENTER" + else + pos.point = pos.point:gsub("LEFT", ""):gsub("RIGHT", "") + end + bar:LoadPosition() + end + + function centerVert(info) + local bar = getBar(info[2]) + local pos = bar.config.position + local y_mod = (pos.growVertical == "DOWN") and 1 or -1 + pos.y = (bar.overlay:GetHeight() / 2) * pos.scale * y_mod + if pos.point == "CENTER" or pos.point == "TOP" or pos.point == "BOTTOM" then -- no special handling + pos.point = "CENTER" + else + pos.point = pos.point:gsub("TOP", ""):gsub("BOTTOM", "") + end + bar:LoadPosition() + end + + function resetPos(info) + local bar = getBar(info[2]) + local pos = bar.config.position + local x_mod = (pos.growHorizontal == "RIGHT") and -1 or 1 + local y_mod = (pos.growVertical == "DOWN") and 1 or -1 + pos.x = (bar.overlay:GetWidth() / 2) * pos.scale * x_mod + pos.y = (bar.overlay:GetHeight() / 2) * pos.scale * y_mod + pos.point = "CENTER" + bar:LoadPosition() + end end local _, class = UnitClass("player") @@ -381,6 +418,37 @@ function Bar:GetOptionObject() get = posGet, set = posSet, }, + nl2 = { + order = 25, + type = "description", + name = "", + }, + centerhorz = { + order = 31, + type = "execute", + name = L["Center Horizontally"], + desc = L["Centers the bar horizontally on screen."], + func = centerHorz, + }, + centervert = { + order = 31, + type = "execute", + name = L["Center Vertically"], + desc = L["Centers the bar vertically on screen."], + func = centerVert, + }, + nl2 = { + order = 35, + type = "description", + name = " ", + }, + reset = { + order = 40, + type = "execute", + name = L["Reset Position"], + desc = L["Reset the position of this bar completly if it ended up off-screen and you cannot reach it anymore."], + func = resetPos, + }, }, } }