getPanelAt observations
Posted: Tue May 26, 2009 12:38 am
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.
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.