constrain grabbed object to the x or y axis? [solved]

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
sms5138
Posts: 126
Joined: Mon Feb 23, 2015 11:49 pm

constrain grabbed object to the x or y axis? [solved]

Post by sms5138 » Fri Jul 17, 2015 6:49 pm

Hi Everyone,

I'm trying to an group that can only be moved up and down. until this point i've been doing just fine using the following:

Code: Select all

on mouseDown
grab group "boxes"
end mouseDown
however allows me to grab said group, and move it up, down, left, and right... is there a way to tell it to only allow the y axis, or vertical? has anyone come across this before?

thanks in advance for any assistance you can provide!

-Sean
Last edited by sms5138 on Tue Jul 21, 2015 2:51 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: constrain grabbed object to the x or y axis?

Post by dunbarx » Sat Jul 18, 2015 12:40 am

Hi.

Here is a handler from an old thread. I m lazy, and instead of just giving you a method, I am making you do all the work. It actually does much more than you asked for. But make this and play with it. Then see if you can simplify the ideas in it to do what you need.

On a new card, place two line graphics, one vertical and one horizontal, that cross each other. Name the vertical one "vLine". Name the horizontal one "hLine". Make a button and place this in its script:

Code: Select all

on mouseMove x,y
   put the left of grc "vLine" into h
   put the top of grc "hLine" into v      
   put H & "," &  v into origin
   put abs(x-h) into hWindow
   put abs(y-v) into vWindow
   switch
      case vWindow < 10 and hWindow < 10
         set the loc of me to origin
         break
      case vWindow <= 10
         set the loc of me to x &  "," & v
         break
      case hWindow <= 10
         set the loc of me to  h & "," & y
         break
      case hWindow > 10 and vWindow > 10
           set the loc of me to the mouseLoc
          break
   end switch
end mouseMove
Now put the cursor over the button, and bring it near either of the lines. As I said, this is more than you asked (bargained?) for. Can you see the thinking behind it? Can you make your gadget with only a few lines of code? Write back if you need a hand.

Craig Newman

EDIT: Here is the name of that thread: Snap objects while dragging

sms5138
Posts: 126
Joined: Mon Feb 23, 2015 11:49 pm

Re: constrain grabbed object to the x or y axis?

Post by sms5138 » Sun Jul 19, 2015 3:12 pm

Hey Craig!

I really appreciate the help! I'm gonna dig into this later today, and see if i can get it working!

Thanks again!

-Sean

Post Reply