Quantcast

Allow specifying a padding when comparing frames with Intersect

Scott Sibley [09-17-10 - 19:47]
Allow specifying a padding when comparing frames with Intersect
Filename
Modules/Bars.lua
Modules/Histograms.lua
Modules/Text.lua
diff --git a/Modules/Bars.lua b/Modules/Bars.lua
index ae1dbac..8fec1ce 100644
--- a/Modules/Bars.lua
+++ b/Modules/Bars.lua
@@ -153,10 +153,10 @@ local intersectUpdate = function()
 	for k, widget in pairs(mod.bars or {}) do
 		if widget.config.intersect and type(widget.bar) == "table" then
 			for frame in pairs(frame_cache) do
-				if GetMouseFocus() ~= UIParent and environment.Intersect and environment.Intersect(frame, widget.bar) then
+				if environment.Intersect(widget.bar, frame, widget.config.xPad1 or 0, widget.config.yPad1 or 0, widget.config.xPad2 or 0, widget.config.yPad2 or 0) then
 					widget.hidden = true
 					widget.bar:Hide()
-				elseif environment.Intersect and not environment.Intersect(frame, widget.bar) and widget.hidden and (UnitExists(StarTip.unit or "mouseover") and not widget.config.persistent) then
+				elseif not environment.Intersect(widget.bar, frame, widget.config.xPad1 or 0, widget.config.yPad1 or 0, widget.config.xPad2 or 0, widget.config.yPad2 or 0) and widget.hidden and UnitExists(StarTip.unit or "mouseover") then
 					widget.hidden = false
 					widget.bar:Show()
 				else
@@ -348,7 +348,6 @@ function mod:OnEnable()
 	GameTooltip:SetClampRectInsets(0, 0, 10, 10)
 	StarTip:SetOptionsDisabled(options, false)
 	intersectTimer = intersectTimer or LibTimer:New("Texts.intersectTimer", 100, true, intersectUpdate)
-	intersectTimer:Start()
 end

 function mod:OnDisable()
@@ -380,6 +379,7 @@ function mod:SetUnit()
 			bar.secondBar.bar:Show()
 		end
 	end
+	intersectTimer:Start()
 end

 function mod:SetItem()
@@ -391,6 +391,7 @@ function mod:SetItem()
 			bar.secondBar.bar:Hide()
 		end
 	end
+	intersectTimer:Start()
 end

 function mod:SetSpell()
@@ -402,6 +403,7 @@ function mod:SetSpell()
 			bar.secondBar.bar:Hide()
 		end
 	end
+	intersectTimer:Start()
 end

 function mod:OnHide()
@@ -417,6 +419,7 @@ function mod:OnHide()
 			bar.secondBar.bar:Hide()
 		end
 	end
+	intersectTimer:Stop()
 end

 local function colorGradient(perc)
diff --git a/Modules/Histograms.lua b/Modules/Histograms.lua
index 2aea1db..e64f147 100644
--- a/Modules/Histograms.lua
+++ b/Modules/Histograms.lua
@@ -205,13 +205,13 @@ local intersectUpdate = function()
 		frame_cache[GetMouseFocus()] = true
 	end
 	for k, widget in pairs(mod.histograms or {}) do
-		for i, bar in ipairs(widget.bars) do
-			for parent in pairs(frame_cache) do
-				if widget.config.intersect and type(bar) == "table" then
-					if environment.Intersect(parent, bar) then
+		for parent in pairs(frame_cache) do
+			for i, bar in ipairs(widget.bars or {}) do
+				if widget.config.intersect then
+					if environment.Intersect(bar, parent, widget.config.xPad1 or 0, widget.config.yPad1 or 0, widget.config.xPad2 or 0, widget.config.yPad2 or 0) then
 						widget.hidden = true
 						bar:Hide()
-					elseif environment.Intersect(parent, bar) and widget.hidden then
+					elseif environment.Intersect(bar, parent, widget.config.xPad1 or 0, widget.config.yPad1 or 0, widget.config.xPad2 or 0, widget.config.yPad2 or 0) and widget.hidden then
 						widget.hidden = false
 						bar:Show()
 					end
@@ -425,6 +425,7 @@ function mod:SetUnit()
 		end
 		widget:Start()
 	end
+	intersectTimer:Start()
 end

 function mod:SetItem()
@@ -436,6 +437,7 @@ function mod:SetItem()
 			widget:Stop()
 		end
 	end
+	intersectTimer:Start()
 end

 function mod:SetSpell()
@@ -447,6 +449,7 @@ function mod:SetSpell()
 			widget:Stop()
 		end
 	end
+	intersectTimer:Start()
 end

 function mod:OnHide()
@@ -462,6 +465,7 @@ function mod:OnHide()
 			widget:Stop()
 		end
 	end
+	intersectTimer:Stop()
 end

 local function colorGradient(perc)
diff --git a/Modules/Text.lua b/Modules/Text.lua
index 95906b9..2db9fab 100644
--- a/Modules/Text.lua
+++ b/Modules/Text.lua
@@ -278,12 +278,12 @@ local intersectUpdate = function()
 		frame_cache[GetMouseFocus()] = true
 	end
 	for k, widget in pairs(mod.texts) do
-		for parent in pairs(frame_cache) and type(widget.text) == "table" do
+		for parent in pairs(frame_cache) do
 			if widget.config.intersect then
-				if environment.Intersect(parent, widget.text) then
+				if environment.Intersect(widget.text, parent, widget.config.xPad1 or 0, widget.config.yPad1 or 0, widget.config.xPad2 or 0, widget.config.yPad2 or 0) then
 					widget.hidden = true
 					widget.text:Hide()
-				elseif not environment.Intersect(parent, widget.text) and widget.hidden then
+				elseif not environment.Intersect(widget.text, parent, widget.config.xPad1 or 0, widget.config.yPad1 or 0, widget.config.xPad2 or 0, widget.config.yPad2 or 0) and widget.hidden then
 					widget.hidden = false
 					widget.text:Show()
 				end
@@ -476,7 +476,6 @@ function mod:OnEnable()
 	self:ClearTexts()
 	createTexts()
 	intersectTimer = intersectTimer or LibTimer:New("Texts.intersectTimer", 100, true, intersectUpdate)
-	intersectTimer:Start()
 	GameTooltip:SetClampRectInsets(0, 0, 10, 10)
 	StarTip:SetOptionsDisabled(options, false)
 end
@@ -507,6 +506,7 @@ function mod:SetUnit()
 		text:Start()
 		text.text:Show()
 	end
+	intersectTimer:Start()
 end

 function mod:SetItem()
@@ -516,6 +516,7 @@ function mod:SetItem()
 			text.text:Hide()
 		end
 	end
+	intersectTimer:Start()
 end

 function mod:SetSpell()
@@ -525,6 +526,7 @@ function mod:SetSpell()
 			text.text:Hide()
 		end
 	end
+	intersectTimer:Start()
 end

 function mod:OnHide()
@@ -538,6 +540,7 @@ function mod:OnHide()
 			text.text:Hide()
 		end
 	end
+	intersectTimer:Stop()
 end

 function mod:RebuildOpts()