mouse everything

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
mattmaier
Posts: 109
Joined: Fri Apr 19, 2013 2:49 am

mouse everything

Post by mattmaier » Fri Jan 16, 2015 5:53 am

I've got little fields with some text in them that the user can drag around. After the user is done dragging I want to update an array with the final location of the field. Usually, the script figures out that the user is done and updates the final location, but every now and then it doesn't. I've got every handler I can find that seems relevant set up to capture the event, but still sometimes none of these handlers gets a message.

Code: Select all

on mouseMove newMouseX,newMouseY
if the mouse is down then
userDrag (the long name of me, newMouseX, newMouseY, the cNodeKey of me)
end if
end mouseMove
on mouseUP
userMoveNode (the cNodeKey of me, the loc of me)
userFinishDrag
end mouseUP
on mouseRelease
userMoveNode (the cNodeKey of me, the loc of me)
end mouseRelease
on mouseLeave
if the mouse is down then
userMoveNode (the cNodeKey of me, the loc of me)
end if
end mouseLeave
I'm not confident that I'm able to consistently replicate the error. I'm using a touchpad and the field's lockText and opaque are set to true. Sometimes it seems like maybe the no-message problem is when the mouse isn't over the text; sometimes it seems like it's when I slide my finger just right as I'm releasing the mouse button. The BYU site said that touch messages are automatically converted to mouse messages, so maybe that's not a problem.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3361
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: mouse everything

Post by bn » Fri Jan 16, 2015 10:20 am

Hi Matt,

I don't see why your code should not work.
In similar situations I use code like this

Code: Select all

local sTrack
local sXDiff, sYDiff

on mouseDown
   put the clickLoc into tClick
   put the loc of me into tLoc
   put item 1 of tLoc - item 1 of tClick into sXDiff
   put item 2 of tLoc - item 2 of tClick into sYDiff
   put true into sTrack
   -- your houseKeeping here 
end mouseDown

on mouseMove x,y
   if sTrack then
      set the loc of me to x + sXDiff, y + sYDiff
      -- houseKeeping 
      -- userDrag (the long name of me, newMouseX, newMouseY, the cNodeKey of me)
   end if
end mouseMove

on mouseUp
   put false into sTrack
   -- houseKeeping
   -- userMoveNode (the cNodeKey of me, the loc of me)
   -- userFinishDrag
end mouseUp

on mouseRelease
   mouseUp
end mouseRelease
try if that does what you want.
Note the script local variables above all handlers.

Kind regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”