Hello everyone!
I have been working on a very small gui implementation, and for the life of me cannot come up with a way to do something(in theory seems very straightforward).
If 2 frames with an x, y, width, and height, are overlapping, how can you set the top-most window to "active" or "selected?" Everything I start to come up with becomes incredibly verbose for something that will be called every frame update, so I'm hoping someone out there might have a better idea(that works of course ). I thought a push/pop might work, but determining the top window to move to the top still selects multiple, almost like I need to filter through the table backwards.
Any help would be appreciated
Overlapping Object Selection
Re: Overlapping Object Selection
Have you tried using z-levels?
Re: Overlapping Object Selection
Could you please post a .love file and explain how to reproduce the problem?
Check out my blog on gamedev
Re: Overlapping Object Selection
micha wrote:Could you please post a .love file and explain how to reproduce the problem?
OP is killost_RD wrote:Have you tried using z-levels?
Re: Overlapping Object Selection
A z-list would seem beneficial for draw order, the problem I have come across was how to get the top-most selected window.
I used the example from Nova-fusion to throw a quick example up(so you can see what I mean, if I had a way to demonstrate it any better... it would be fixed lol )
When the objects overlap, and you try to move only one, they both move. I need to be able to set the "top" one to current, so only it will be moveable.
I also need to be able to select another rect as the top or current by clicking the other where they dont overlap to set it on top.
Using the boundaries to determine another window is selected is fine, until they overlap, then I run into a problem with it returning multiple true statements for the collision check to set the rect on top.
Hopefully this clears it up
EDIT>>
I used the example from Nova-fusion to throw a quick example up(so you can see what I mean, if I had a way to demonstrate it any better... it would be fixed lol )
When the objects overlap, and you try to move only one, they both move. I need to be able to set the "top" one to current, so only it will be moveable.
I also need to be able to select another rect as the top or current by clicking the other where they dont overlap to set it on top.
Using the boundaries to determine another window is selected is fine, until they overlap, then I run into a problem with it returning multiple true statements for the collision check to set the rect on top.
Hopefully this clears it up
EDIT>>
I have no idea what that means.OP is kil
- Attachments
-
- Drag.love
- (616 Bytes) Downloaded 247 times
Re: Overlapping Object Selection
Just stop when you get the first one!vynom wrote:A z-list would seem beneficial for draw order, the problem I have come across was how to get the top-most selected window.
It's a joke and slang for "OP died", you didn't respond for a while so I assumed you were gone.vynom wrote:I have no idea what that means.OP is kil
Anyway,
Code: Select all
function love.draw()
for i=#Rect.list,1,-1 do -- opposite order
Rect.list[i]:draw()
end
end
function love.mousepressed(x, y, button)
if button == "l" then
for i,v in ipairs(Rect.list) do -- assuming Rect.list is sorted so that first windows are higher
if x > v.x and x < v.x + v.width
and y > v.y and y < v.y + v.height
then
v.dragging.active = true
v.dragging.diffX = x - v.x
v.dragging.diffY = y - v.y
return -- stop here!
end
end
end
end
Code: Select all
local top, z = nil, -1
for _,v in ipairs(Rect.list) do
if v.z > z and <...check hit...> then
z = v.z
top = v
end
end
if not top then return end -- none hit
Last edited by s-ol on Tue Nov 18, 2014 10:53 pm, edited 1 time in total.
Re: Overlapping Object Selection
As far as I understand the topmost object is the one that is last drawn. So if you draw objects like from 1 to n, then the nth indexed object will always be topmost regardless where the object resides on the window. So to figure out which object it hits, just go it through in reverse order ( from n to 1 ), until it hits one, or if none of the boxes are within boundaries then pick none.
Edit: Also to point out the post on top of mine, never use pairs() if you want to be sure to have defined order. Atleast according to lua tutorial there is no guarantee in which order pairs() returns, unlike ipairs always goes from 1 to n. http://lua-users.org/wiki/ForTutorial
Altho according to this http://coronalabs.com/blog/2013/03/12/p ... mizations/ in lua using ipairs is not recommended, because apparently it generates some overhead, but to just use for loop.
Edit: Also to point out the post on top of mine, never use pairs() if you want to be sure to have defined order. Atleast according to lua tutorial there is no guarantee in which order pairs() returns, unlike ipairs always goes from 1 to n. http://lua-users.org/wiki/ForTutorial
Altho according to this http://coronalabs.com/blog/2013/03/12/p ... mizations/ in lua using ipairs is not recommended, because apparently it generates some overhead, but to just use for loop.
Code: Select all
for i = 1, #table do
print( table[i] )
end
Re: Overlapping Object Selection
Both were what I was looking for, along with removing and readding to the table to move it to the end, thanks!
Re: Overlapping Object Selection
whoops, I meant to use ipairs there aswell.Muris wrote:As far as I understand the topmost object is the one that is last drawn. So if you draw objects like from 1 to n, then the nth indexed object will always be topmost regardless where the object resides on the window. So to figure out which object it hits, just go it through in reverse order ( from n to 1 ), until it hits one, or if none of the boxes are within boundaries then pick none.
Edit: Also to point out the post on top of mine, never use pairs() if you want to be sure to have defined order. Atleast according to lua tutorial there is no guarantee in which order pairs() returns, unlike ipairs always goes from 1 to n. http://lua-users.org/wiki/ForTutorial
Altho according to this http://coronalabs.com/blog/2013/03/12/p ... mizations/ in lua using ipairs is not recommended, because apparently it generates some overhead, but to just use for loop.
Code: Select all
for i = 1, #table do print( table[i] ) end
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests