Page 1 of 1

getPanelAt observations

Posted: Tue May 26, 2009 12:38 am
by ray
I just started looking at Love and trying out this Leif library. I was browsing the code, not very thoroughly, and I happened to look at a function in leif.lua called getPanelAt, which is used for determining what panel was clicked on. I noticed 2 things about it:

1. The function checks all the children of a panel first before allowing the parent to claim the click. This is good, because children should exist in front of the parent. But it seems to me that if you first check to see whether the point in question is geometrically inside of the parent, before checking children, then much less checking of children would occur, and recursively and so on and the function would be much less expensive.

2. The function checks children in the same order in which they are drawn. Child objects drawn first appear to be on the bottom and child objects drawn last appear to be on top. Therefore, it would seem to me that if overlap is possible, you would want to check the children in the reverse of the order in which they are drawn.

I have only spent a few minutes looking at the code, so I probably missed or misinterpreted something.

Re: getPanelAt observations

Posted: Tue May 26, 2009 2:44 pm
by Robin
That's all right and all, but shouldn't this go under the Leif thread?

Re: getPanelAt observations

Posted: Mon Jun 08, 2009 12:12 am
by Kaze
Sorry about the extremely late reply. I don't read these forums anymore.

1. Okay.
2. Actually, leif.drawPanel uses leif.npairs, which is the opposite of ipairs.
The _children table actually has the top-most panel at the index 1, so ipairs checks from the top-most to bottom-most.