Disable input on children when moving the parent

Hello all,

my paintings app is evolving into some sort of point and click thingy and I have one small problem to solve.
Each painting has several children, clickable areas that will trigger some actions.
The user can zoom into the painting and then move it around to have a closer look. I do not want a clickable area to register input should the cursor happen to rest on it when moving the parent has completed and the mouse is released (while the parent is moving and the mouse is pressed, everything works as intended).
I would like to solve this with the use of flags, searched to forum but could not produce code that works.
This is what I’ve got so far, obviously not working:

	if action_id == hash("touch") then
		-- fill movement array
		table.insert(actions_array_x, action.x)
		table.insert(actions_array_y, action.y)
		if gui.pick_node(image, action.x, action.y) then 
			if image_scale == zoom_limit_lower then
				gui.set_position(image, vmath.vector3(0, 0, 0))
			end
			-- allow moving the image only when the image is scaled
			if action.pressed and image_scale > zoom_limit_lower then
				print("image pressed")
				image_moving = true
			elseif action.released then
				print("image released")
				image_moving = false
				reset_movement_variables()
			end
			if image_moving == true then
				calculate_movement()
				calculate_boundary()
				position_image()
			end
		end
		if image_moving == false then
			for i = 1, #buttons_array do
				local button = buttons_array[i]
				-- runs when the cursor is on the button after the moving of the image is completed
				if gui.pick_node(button, action.x, action.y) then
					-- prints when the image is scaled
					print("button"..i.." picked")
					if action.pressed then
						-- does not print when the image is scaled
						print("button"..i.." pressed")
					elseif action.released then
						-- prints when the image is scaled
						print("button"..i.." released")
					end
				end	
			end
		end
	end

If someone could point me into the right direction, I would be very grateful.

Yes, I think you should register one flag plus the position when the user pressed the mouse button:

local pos = vmath.vector3(action.x, action.y, 0)
if action.pressed then
    self.pressed = true
    self.pressed_position = pos
end

Next I’d check when you start dragging the map and set a flag when it happens.

local pos = vmath.vector3(action.x, action.y, 0)
if self.pressed then
    local distance = vmath.length(pos - self.pressed_pos)
    if distance > 20 then
          self.dragging = true
    end
end

Finally on release I’d ignore the release event if the user has dragged the mouse:

if action.release then
    if not self.dragging then
           -- handle the release event here
    end
    self.pressed = false
    self.dragging = false
end
1 Like

Hi @britzl - cool, that is really nifty. You just caught me fiddling about with a timer to detect the length of a click, but your solution is much better.
I need a break, enjoy the sunshine and grab a coffee in town, then I will put your code into action. Thanks a lot for your help!

2 Likes

Back from town and reporting back:

@britzl, thanks to your help everything works perfectly now and I just removed the now obsolete test project I posted before.

2 Likes