Moving button unwanted behaviour
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Moving button unwanted behaviour
I also have an other issue to solve that i have problems with.
Which is: The buttons I move are part of a group. To prevent a button I am moving to slide behind an already existing button in that group I would like to set the layer to top while moving the button. However because the button is member of a group this is not possible.
Anybody suggestions?
Which is: The buttons I move are part of a group. To prevent a button I am moving to slide behind an already existing button in that group I would like to set the layer to top while moving the button. However because the button is member of a group this is not possible.
Anybody suggestions?
Re: Moving button unwanted behaviour
Hi mrcoollion,
...
set the relayerGroupedControls to TRUE
## do your relayer thing here...
set the relayerGroupedControls to FALSE
...
Be careful to not "layer" your button out of the group this way!
Best
Klaus
yes!mrcoollion wrote:Anybody suggestions?
...
set the relayerGroupedControls to TRUE
## do your relayer thing here...
set the relayerGroupedControls to FALSE
...
Be careful to not "layer" your button out of the group this way!
Best
Klaus
Re: Moving button unwanted behaviour
Yep, what klaus said.
A couple additions.. When you officially start to move the button, you might want to save its current layer so that you can revert after drag.
Also, to keep from layering your way out of the group you can find the correct number to relayer to by getting the layer of the owner of your button (which would be the group) and add the number of controls in the group. (the number of controls in the owner of me) SO if the layer of the group is 5, and there are 5 objects in the group, layering your button to 10 will put it on top of all other grouped objects while still keeping it in the group. Of course it wold get more complicated if you have nested groups..
EDIT.. Heres some code that does the relayering. Modified from one of my earlier posts.
Also be aware, if you don't want a script in every button you can either assign behaviors, or you can put the script in the group, and use "the target" instead of "of me" to make all your buttons movable from a single script.
A couple additions.. When you officially start to move the button, you might want to save its current layer so that you can revert after drag.
Also, to keep from layering your way out of the group you can find the correct number to relayer to by getting the layer of the owner of your button (which would be the group) and add the number of controls in the group. (the number of controls in the owner of me) SO if the layer of the group is 5, and there are 5 objects in the group, layering your button to 10 will put it on top of all other grouped objects while still keeping it in the group. Of course it wold get more complicated if you have nested groups..
EDIT.. Heres some code that does the relayering. Modified from one of my earlier posts.
Code: Select all
-- there is still a problem with this method, but it should be easy enough to fix..
-- if you click the button and drag the mouse away before 2 seconds without releasing it,
-- the button will 'jump' to the mouse location after 2 seconds
-- one could add a mouseleave handler that resets the moveDelay if needed.
local MovingDelay,sMoving,sMessage,slayer
constant kDelay=500
on mousedown
put the millisec into MovingDelay
put true into sMoving
send "talkToTheHand" to me in kDelay millisec -- sets the cursor to hand, doesn't rely on mousemove
put the result into sMessage -- the message id so we can cancel it if the mouse leaves the button before time
end mousedown
command talkToTheHand
set the cursor to hand
-- save the current layer of the object being dragged
put the layer of me into sLayer
-- allow grouped objects to be relayered
set the relayerGroupedControls to true
-- set the layer to the layer of the group + the number of controls in the group.
set the layer of me to the number of controls in the owner of me + the layer of the owner of me
lock cursor
end talkToTheHand
---------------------------------------------------------------------------------
on mouseMove
if sMoving is not empty and the millisec - MovingDelay > kDelay then
set the loc of me to the mouseLoc
else
if the mouseloc is not within the rect of me then
cancel sMessage
put empty into sMoving
unlock cursor
end if
end if
end mouseMove
---------------------------------------------------------------------------------
on mouseup
unlock cursor
answer information "The mouse was down for" && the millisec - movingDelay && "milliseconds"
-- revert to the previous layer
set the layer of me to sLayer
put empty into sLayer
put empty into sMoving
end mouseup
---------------------------------------------------------------------------------
on mouseRelease
-- this is needed on the off chance you move the mouse fast enough to
-- be outside the rect of the button on mouseup. In which case, mouseup is not sent
-- to the button, but mouserelease still is.
unlock cursor
answer information "The mouse was down for" && the millisec - movingDelay && "milliseconds"
-- revert to the previous layer
set the layer of me to sLayer
put empty into sLayer
put empty into sMoving
end mouseRelease
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Moving button unwanted behaviour
Thx Klaus , (and sturgis.... our posts crossed ) ..
Works great.
I am surprised that I can even use 'set the layer of me to top' .. I though this would place the button outside of the group but it seems to work fine.
Below is the way I used it.
In 'on mouseDown' I do the following:
After I moved the button I set the button to its original layer like this.
The wait and the 'set the visited of me to false' I use to show the visited icon for 1 second. Be aware that the position in the script of the wait and the visited command line are important (in my case at least because the buttons are grouped).
in 'on Mouseup' and 'on mouseRelease' i do the following:
Thanks again Klaus.
Works great.
I am surprised that I can even use 'set the layer of me to top' .. I though this would place the button outside of the group but it seems to work fine.
Below is the way I used it.
In 'on mouseDown' I do the following:
Code: Select all
put the layer of me into mylayer
set the relayerGroupedControls to TRUE
set the layer of me to top
set the relayerGroupedControls to FALSE
The wait and the 'set the visited of me to false' I use to show the visited icon for 1 second. Be aware that the position in the script of the wait and the visited command line are important (in my case at least because the buttons are grouped).
in 'on Mouseup' and 'on mouseRelease' i do the following:
Code: Select all
wait for 1 seconds
set the relayerGroupedControls to TRUE
set the layer of me to mylayer
set the relayerGroupedControls to FALSE
set the visited of me to false
Re: Moving button unwanted behaviour
Hey, you might look at "relayer" in the dictionary too. As far as "top" goes, its likely that while moving, you pull it out of the group, then you set it back to where it was, inside the group.
My method did the math to find the right layer number, but it looks like with relayer you can do..
relayer me after the owner of me.. GOing to have to explore relayer now. *sigh* So much to learn, so few brain cells to do it with.
My method did the math to find the right layer number, but it looks like with relayer you can do..
relayer me after the owner of me.. GOing to have to explore relayer now. *sigh* So much to learn, so few brain cells to do it with.
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Moving button unwanted behaviour
Even when I know all the layer numbers of all buttons (which is not to difficult to do), when I set the layer of the button I am moving above the highest layer number, don't I place the button out of the group by doing this? And if I do'not make it the highest layer number of all buttons there will always be one button it will slide under.
Am i correct here or not?
So what layer number do I need to set the button I am moving?
Am i correct here or not?
So what layer number do I need to set the button I am moving?
Re: Moving button unwanted behaviour
YOu set the layer to the highest layered control in the group. That way, it takes over that position, (still in the group) and the other controls shift downward to fill the vacated hole.
And if I understand what I read in the dictionary for "relayer" thats exactly what "relayer <control> after the owner of <control>" does to accomplish exactly the same thing.
And if I understand what I read in the dictionary for "relayer" thats exactly what "relayer <control> after the owner of <control>" does to accomplish exactly the same thing.
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Moving button unwanted behaviour
Ok,
So the the routine must do the following:
1) find out the highest layer and related button name of all objects (buttons) in the group
2) Set the layer of the button I want to move to the highest layer number.
Or when using relayer
2) relayer button "NameMovingButton" after button "NameButtonWithHighestLayernumber"
Thanks
I will try it and post the result.
So the the routine must do the following:
1) find out the highest layer and related button name of all objects (buttons) in the group
2) Set the layer of the button I want to move to the highest layer number.
Or when using relayer
2) relayer button "NameMovingButton" after button "NameButtonWithHighestLayernumber"
Thanks
I will try it and post the result.
Re: Moving button unwanted behaviour
Yep. Relayer is interesting. I've never needed to relayer, so its all new to me.
you can relayer before, relayer after, or front, or back or..
you can relayer before, relayer after, or front, or back or..
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Moving button unwanted behaviour
Found a strange issue when I tried to get all the button names from the button group using the code below.
In a group I have three buttons named button1 , button2 and button3. The first line of this script does find three buttons so that is ok.
However in the ButtonsString at the end of this script i see the following 'button1,button2,button5' . There is no button5 anywhere to be found !!!! That should be button3.
Any idea's or suggestion for a more reliable routine?
This routine e.g. could be used to find out the (highest or lowest) layers of all the button objects in a group.
Regards,
Paul
In a group I have three buttons named button1 , button2 and button3. The first line of this script does find three buttons so that is ok.
However in the ButtonsString at the end of this script i see the following 'button1,button2,button5' . There is no button5 anywhere to be found !!!! That should be button3.
Code: Select all
put the number of buttons in the group "groupMenuButtons" of card "Menu" into NumberOfButtons
repeat with x = 1 to NumberOfButtons
put the short name of button x & "," after ButtonsString
end repeat
if the last character of ButtonsString is "," then delete the last character of ButtonsString
This routine e.g. could be used to find out the (highest or lowest) layers of all the button objects in a group.
Regards,
Paul
Re: Moving button unwanted behaviour
Hi Paul,
this shold do:
Best
Klaus
this shold do:
Code: Select all
...
put the number of buttons OF group "groupMenuButtons" of card "Menu" into NumberOfButtons
repeat with x = 1 to NumberOfButtons
## You need the correct address of the objects, otherwise the engine presumes the "current" card!
put the short name of button x OF grp "groupMenuButtons" of card "Menu" & "," after ButtonsString
end repeat
## if the last character of ButtonsString is "," then delete the last character of ButtonsString
## REALLY no need for IF THEN here! ;-)
delete char -1 of ButtonsString
...
Klaus
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Moving button unwanted behaviour
Stupid mistake of myself .... should have seen that...
It works now.
The IF THEN I placed because there might be no buttons in the string..
Thanks....
It works now.
The IF THEN I placed because there might be no buttons in the string..
Thanks....
Re: Moving button unwanted behaviour
Even in that case (empty string!) deleting the last character will do no harm!mrcoollion wrote:The IF THEN I placed because there might be no buttons in the string...
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Moving button unwanted behaviour
Thanks for the info and support (again !)