Thread Tools Display Modes
05-19-13, 06:27 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
OnLeave event for overlapping frames

Hi,
I cross post also here trying to find some answer on an addon iussue I always used but I think it is not supported anymore, LitePanels.

The original post is here:
http://www.wowinterface.com/forums/s...283#post278283

To summary the problem on lua code is this:
I'd like to intercept the OnLeave event from a frame (a background) without to have false trigger when I mouse over an upper frame.

The scenario is:
- I make a background.
- I make a 3x3 bar of bt4 to fill the background and make it visible only when I move mouse on.
- I want that also the background will Show/Hide depending on the event OnEnter / OnLeave.

The problem is:
- The background triggers the OnLeave event also when I am mouseover the bt4 bar (that almost fill the background).

The question is:
- Is it possible to let the background trigger the OnLeave event only when leave the perimeter of the frame and not if I am move on another (upper) frame ?

The code:

Lua Code:
  1. lpanels:CreateLayout("Back2", {
  2.  
  3.     {   name = "P1", anchor_to = "BOTTOM", x_off = 0, y_off = 4,
  4.  
  5.         bg_alpha = 0.5, width = 460, height = 120,
  6.  
  7.         border = "SOLID", border_color = "CLASS",
  8.  
  9.     },
  10.  
  11.    
  12.  
  13.     {   name = "P2",
  14.  
  15.         anchor_to="BOTTOMLEFT", anchor_from="BOTTOMRIGHT", anchor_frame = "P1",
  16.  
  17.         x_off = 2, y_off = 0,
  18.  
  19.         bg_alpha = 0.5, width = 115, height = 120,
  20.  
  21.         border = "SOLID", border_color = "CLASS",
  22.  
  23.         OnLoad  = function(self) self:SetAlpha(0) end,
  24.  
  25.         OnEnter = function(self)
  26.  
  27.             self:SetAlpha(1)
  28.  
  29.             -- BT4Bar3:Show()
  30.  
  31.         end,
  32.  
  33.         OnLeave = function(self)
  34.  
  35.             print( "DEBUG: The mouse is over " .. GetMouseFocus():GetName())
  36.  
  37.             if GetMouseFocus():GetParent() ~= self then
  38.  
  39.                 self:SetAlpha(0)
  40.  
  41.             end
  42.  
  43.         end,
  44.     },
  45. } )

I have tried first obvius code like:

Lua Code:
  1. OnLeave = function(self) self:SetAlpha(0) end

Then searching here and there I found in the forum the code below:

Lua Code:
  1. OnLeave = function(self)
  2.             if GetMouseFocus():GetParent() ~= self then
  3.                 self:SetAlpha(0)
  4.             end
  5.         end,

But it doesn't work either ...

Uhm anyone can suggest something else ? :-)
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
05-19-13, 07:09 AM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Two things come to mind, but I'm not sure whether either of them are the correct way of doing this.

You could simply hook your OnEnter/OnLeave functions to each of the buttons as well. You could also hook OnEnter on your background and start an OnUpdate script that polls to check if the cursor position is within the bounds of your background.

Won't something like this work, though?

Code:
local OnLeave = function(self)
	local parent = GetMouseFocus():GetParent()
	if not parent or (parent and parent ~= self) then
		self:SetAlpha(0)
	end
end
It's like the function you posted, but it checks if the mouse focus frame has a parent before attempting to compare it to self. It also hides it if the mouse focus doesn't have a parent (WorldFrame or UIParent). It won't work if the buttons fill the background entirely, though (then OnLeave gets called from the button instead of the background).

Last edited by Haleth : 05-19-13 at 07:15 AM.
  Reply With Quote
05-19-13, 08:21 AM   #3
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Check IsMouseOver:
http://wowprogramming.com/docs/widge...on/IsMouseOver

Work with frame attributes. (frameHovered = true/false)

There is no OnMouseMove event though.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 05-19-13 at 08:23 AM.
  Reply With Quote
05-19-13, 09:59 AM   #4
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
The idea that comes to my mind:Why not setting 'parent' to your bt4-bar ?
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
05-19-13, 11:28 AM   #5
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Originally Posted by zork View Post
Check IsMouseOver:
http://wowprogramming.com/docs/widge...on/IsMouseOver

Work with frame attributes. (frameHovered = true/false)

There is no OnMouseMove event though.
It works, but only if there is not the BT4 bar over the frame.

Without the BT4 bar this works nicely.

Lua Code:
  1. OnLeave = function(self)
  2.             isOver = self:IsMouseOver(878, 108, 976, 4)
  3.             if isOver == true then
  4.                 print ("DEBUG:1")
  5.                 self:SetAlpha(1)
  6.             else
  7.                 self:SetAlpha(0)
  8.                 print ("DEBUG:0")
  9.             end
  10.         end

I think the problem is that the OnLeave trigger should be binded to the BT4 bar (that actually got the event).

Thanks anyway for your answer.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
05-19-13, 11:31 AM   #6
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Originally Posted by Haleth View Post
Two things come to mind, but I'm not sure whether either of them are the correct way of doing this.

You could simply hook your OnEnter/OnLeave functions to each of the buttons as well. You could also hook OnEnter on your background and start an OnUpdate script that polls to check if the cursor position is within the bounds of your background.

Won't something like this work, though?

Code:
local OnLeave = function(self)
	local parent = GetMouseFocus():GetParent()
	if not parent or (parent and parent ~= self) then
		self:SetAlpha(0)
	end
end
It's like the function you posted, but it checks if the mouse focus frame has a parent before attempting to compare it to self. It also hides it if the mouse focus doesn't have a parent (WorldFrame or UIParent). It won't work if the buttons fill the background entirely, though (then OnLeave gets called from the button instead of the background).
Hi Haleth,
the first solution I think is a little bit expensive, the second works but without the BT4 bar over the frame.

Same story of the Zork solution. It works but only if the BT4 bar don't get the mouseover event.

Thanks anyway for your kind answer.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
05-19-13, 11:35 AM   #7
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Originally Posted by Rilgamon View Post
The idea that comes to my mind:Why not setting 'parent' to your bt4-bar ?
Uhm ... explain better pls ? :-)


Edit:

It works ! :-)

Lua Code:
  1. lpanels:CreateLayout("Back2", {
  2.     {   name = "P1", anchor_to = "BOTTOM", x_off = 0, y_off = 4,
  3.         bg_alpha = 1, width = 460, height = 122,
  4.         border = "SOLID", border_color = "CLASS",
  5.     },
  6.    
  7.     {   name = "P2", parent = "BT4Bar3",
  8.         anchor_to="BOTTOMLEFT", anchor_from="BOTTOMRIGHT", anchor_frame = "P1",
  9.         x_off = 2, y_off = 0,
  10.         bg_alpha = 1, width = 115, height = 120,
  11.         border = "SOLID", border_color = "CLASS",
  12.     },
  13.    
  14. } )

It is not so elegant but it works now after an afternoon of tries :-)

Thanks very much for your attention and ideas...
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
05-19-13, 12:00 PM   #8
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by gmarco View Post
It is not so elegant but it works now
Hey, its the most elegant way. Never use a function when you can do without
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
05-19-13, 03:25 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Parenting is *the* way to control visibility based on the visibility of another frame.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » OnLeave event for overlapping frames


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off