Posted 25 August 2014 - 06:38 PM
the problem is that i am making a program where you drag boxes around.
for every mouse_drag or mouse_click event, i am checking if the previous cursor coords or the current ones are in the box,
i am keeping track of the prev coords by at the end of the loop setting them to the current one, i need this because when i started dragging inside the box and then moved my cursor while dragging out of the box it would not see that its dragging anymore because its outside.
so the problem is that it only checks if the cursor is in the box or the prev cursor every mouse click or drag, so what happens is, i release the box and the prev coords stay in the box of course, so the next time i click it will move the box to where i clicked, and not dragged. and as you can image, this keeps happening until the universe ends( or my laptop runs out of juice )
i know i have done it before but i just cant find my old code back.
i dont care if you fix my current system or make a new system to drag the boxes around.
since i dont want to spoil to much of the project i am working on, i will only post this bit of code that is relevant
the inrange2() function is a function i made to see if a pair of coords are indisde 2 others wih means 3 arguments for each axis and 6 in total
for every mouse_drag or mouse_click event, i am checking if the previous cursor coords or the current ones are in the box,
i am keeping track of the prev coords by at the end of the loop setting them to the current one, i need this because when i started dragging inside the box and then moved my cursor while dragging out of the box it would not see that its dragging anymore because its outside.
so the problem is that it only checks if the cursor is in the box or the prev cursor every mouse click or drag, so what happens is, i release the box and the prev coords stay in the box of course, so the next time i click it will move the box to where i clicked, and not dragged. and as you can image, this keeps happening until the universe ends( or my laptop runs out of juice )
i know i have done it before but i just cant find my old code back.
i dont care if you fix my current system or make a new system to drag the boxes around.
since i dont want to spoil to much of the project i am working on, i will only post this bit of code that is relevant
Spoiler
if ev[1] == "mouse_drag" or ev[1] == "mouse_click" then
if ev[2] == 1 then
for k,v in pairs( tiles ) do
local posx, posy = v.window.getPosition()
if inrange2( ev[3], ev[4], posx + scroll, posy, posx + scroll + v.width * theme.start.appSizeX, posy + v.height * theme.start.appSizeY ) or
inrange2( lastX, lastY, posx + scroll, posy, posx + scroll + v.width * theme.start.appSizeX, posy + v.height * theme.start.appSizeY ) then
v.dragged = true
dragOffsetX = -(ev[3] - posx)
dragOffsetY = -(ev[4] - posy)
v.window.reposition( ev[3] + dragOffsetX + ( ev[3] - lastX ), ev[4] + dragOffsetY + ( ev[4] - lastY ), v.width * theme.start.appSizeX, v.height * theme.start.appSizeY )
else
v.dragged = false
end
end
end
end
the inrange2() function is a function i made to see if a pair of coords are indisde 2 others wih means 3 arguments for each axis and 6 in total
Edited on 25 August 2014 - 04:39 PM