nudge objects...

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

nudge objects...

Post by TodayIsTheDay » Mon Sep 14, 2009 8:22 pm

Is it possible to nudge an object?

I know you can drag and drop, etc but can you use the up, down, left, right arrows to nudge an object?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Mon Sep 14, 2009 11:52 pm

If you are in Edit mode and select an object then you can nudge it with the arrowkeys. If you press the shift key at the same time the object nudges 10 pixel.
If you are in Browse mode you could put into the message box (or do it by script) "select button 1" then this button is selected and you can nudge it. When you are done put "select empty" into the message box, hit return and the button is unselected.
regards
Bernd

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Tue Sep 15, 2009 3:27 am

I should have specified. I meant in the final .exe or at runtime.

So could I code the 4 arrow down keys, when pressed to select the button, etc and when key up to unselect?

Thanks again.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Sep 15, 2009 9:39 am

TodayIsTheDay,

please explain a little more when you ask. I have no idea what you want. Do you want to move an arbitrary control with the arrowkeys or do you want to nudge just one control (button or field or whatever) with the arrowkeys.
If it is always one e.g. button you want to move then you would go differently about it compared to nudging different controls at different times.

You could set the loc of an object with the arrowKeys. Just look at what the loc of an object is and then set the loc to a pixel higher lower more to the right or left. That way you dont have to select the object before acting on them.
regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Sep 15, 2009 10:17 am

TodayIsTheDay,

make a new stack place 1 button on it and set the script of the card to

Code: Select all

on arrowKey whichKey
   if the shiftKey is down then
      put 10 into tnudge
   else 
      put 1 into tnudge
   end if
   
   put the loc of button 1 into tOldLoc
   switch whichKey
      case up
         subtract tnudge from item 2 of tOldLoc
         set the loc of btn 1 to tOldLoc
         break
      case down
         add tnudge to item 2 of tOldLoc
         set the loc of btn 1 to tOldLoc
         break
      case left
         subtract tnudge from item 1 of tOldLoc
         set the loc of btn 1 to tOldLoc
         break
      case right
         add tnudge to item 1 of tOldLoc
         set the loc of btn 1 to tOldLoc
         break
   end switch
end arrowKey
this should give you an idea. It would be advisable to avoid nudging the button off the card, you could implement that as an exercise.
regards
Bernd

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Wed Sep 16, 2009 9:58 pm

I'm sorry. What I have is a card with multiple objects on it. I'm wanting to be able to nudge any of them if they are selected...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed Sep 16, 2009 10:33 pm

Hi TodayIsTheDay,

the nudging part is in the script, but how do you want to select the object. Is this under script control or is the user deciding which object should be selected? Could give the scenario?

regards
Bernd

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Thu Sep 17, 2009 6:22 pm

Here's the nudge script from the MetaCard IDE:

on arrowKey which
if the short name of the defaultStack <> the short name of the topStack then pass arrowKey -- RG 090313
--
if (the selectedField) is not empty or the selectedObject is empty\
or word 1 of the selectedObject is "stack"\
or word 1 of the selectedObject is "card"\
and word 2 of the selectedObject is not among the items of "field,button,image,player,scrollbar,graphic"
then pass arrowKey
lock screen
local diff
if the shiftkey is down
then put 10 into diff
else put 1 into diff
repeat for each line l in the selectedObjects
switch which
case "left"
set the left of l to the left of l - diff
break
case "right"
set the left of l to the left of l + diff
break
case "up"
set the top of l to the top of l - diff
break
case "down"
set the top of l to the top of l + diff
break
end switch
end repeat
unlock screen
end arrowKey
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply