Get the name of intersecting button

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Get the name of intersecting button

Post by KennyR » Wed Mar 05, 2014 11:25 pm

I am wondering how to get the name of the button that is being intersected when doing a drag operation.... so for instance... You have 5 buttons in a group and each button has a grab command in the mouseDown handler, how can I determine which button the dragged button is colliding with? I understand using the intersect command works when naming a particular button, but when there are multiple buttons on a screen, it seems labor intensive to list all possible intersect scenarios. Thanks for the help...

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: Get the name of intersecting button

Post by KennyR » Thu Mar 06, 2014 2:00 am

well I am getting good at answering my own questions.... :D

Code: Select all

global vOldLoc
on mouseUp
   repeat with x=1 to the number of btns on this cd
      
      if the intersect(me,btn x) then 
         put the short name of btn x  into vName
         put the loc of btn x  into vLoc
           move me to vLoc in 10 ticks
        exit repeat
        
      else
         end if
      end repeat
    
       move btn vName to vOldLoc in 10 ticks
end mouseUp

on mouseDown
   grab me
   set the layer of me to top
   put the loc of me into vOldLoc
end mouseDown

on mouseStillDown
      set the ink of me to srcOrReverse
end mouseStillDown

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Get the name of intersecting button

Post by Klaus » Thu Mar 06, 2014 2:47 pm

What Kenny said! :D

Hint: "mosuestilldown" is a bit CPU intensive and since you do not set the INK back somewhere,
it might be a good idea to only set the INK once on mousedown:

Code: Select all

global vOldLoc
on mouseUp
   repeat with x=1 to the number of btns on this cd
      
      if the intersect(me,btn x) then 
         put the short name of btn x  into vName
         put the loc of btn x  into vLoc
         move me to vLoc in 10 ticks
         exit repeat
        
      ## Really no empty ELSE case neccesary 8-)
      end if
      end repeat 
      move btn vName to vOldLoc in 10 ticks
end mouseUp

on mouseDown
   grab me
   set the ink of me to srcOrReverse
   set the layer of me to top
   put the loc of me into vOldLoc
end mouseDown

## Look ma, no "mousestilldown" :-)
Best

Klaus

Post Reply