lock objects from being dragged out of the screen
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: lock objects from being dragged out of the screen
thank u all of your help. hopfully i will be able to try those things out during the day.
one more thing thought - i've seen a soliter game ("klondike") on "example tutorials" which doesn't let the player drag the mouse out of the screen once he is grabbing something. it's not the kind of code which checks the location and set a new one for the object but more like a "wall" surrounding the card. unfortunatelly i didn't understand the code.
does someone have an idea of how can implement what i described?
thanks again for all your answers!
tomer
one more thing thought - i've seen a soliter game ("klondike") on "example tutorials" which doesn't let the player drag the mouse out of the screen once he is grabbing something. it's not the kind of code which checks the location and set a new one for the object but more like a "wall" surrounding the card. unfortunatelly i didn't understand the code.
does someone have an idea of how can implement what i described?
thanks again for all your answers!
tomer
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: lock objects from being dragged out of the screen
Какво? Аз не разбирам.a "wall" surrounding the card
Can you upload a picture of the game and/or an internet link to this game so it is
possible to play with it an ascertain its functionality?
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: lock objects from being dragged out of the screen
So still playing around, on a new card with one button, put this in the card script.
Assuming your btn is somewhere in the middle of the card you can drag all day until you try to go too far to the right. Pretty old-fashioned. I tried playing around with the "grab" command, but there is no "unGrab". And sending a "mouseUp" message to the grabbed object does not seem to release it. That was the "right"way to do this, and I might try again to see if I can "unGrab" somehow. Maybe someone else knows how to subvert the grab command while the mouse is still down.
You are stuck once you hit the right edge, so I put the mouseDown handler to allow you to click somewhere in the card to restart. This seems inelegant.
Anyway, this can be expanded to cover all four sides of the card.
Craig
Code: Select all
on mouseDown
set loc of btn 1 to the mouseLoc
end mouseDown
on mouseMove
if the mouse is down and the mouseLoc is within the rect of btn 1 and the right of btn 1< the right of this cd then then
set the loc of btn 1 to the mouseLoc
end if
end mouseMove
You are stuck once you hit the right edge, so I put the mouseDown handler to allow you to click somewhere in the card to restart. This seems inelegant.
Anyway, this can be expanded to cover all four sides of the card.
Craig
Last edited by dunbarx on Sun May 14, 2017 4:23 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: lock objects from being dragged out of the screen
Hi Tomer,
I take a look at her mousemove script.
She's clever than me is my first conclusion. I need time to examine it.
Here is a little stack that allows to move an object inside a rectangle.
It also use "mousemove" and check intersect between two controls.
I hope this help.
Best regards
Jean-Marc
Jaqueline is the authori've seen a soliter game ("klondike")
I take a look at her mousemove script.
She's clever than me is my first conclusion. I need time to examine it.
Here is a little stack that allows to move an object inside a rectangle.
It also use "mousemove" and check intersect between two controls.
I hope this help.
Best regards
Jean-Marc
- Attachments
-
- stMoveControlInsideRect001.livecode.zip
- Move a control inside a rect using mousemove
- (1.86 KiB) Downloaded 351 times
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 7229
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: lock objects from being dragged out of the screen
Do you mean this Klondike game?
http://livecodeshare.runrev.com/stack/226/Klondike
It does set the location of the dragged objects repeatedly during a move. The mouseMove message is trapped and if the mouseLoc is not within the bounds of the card it does nothing.
If that's the example you mean I can give you a shorter version of the code. The handlers in the Klondike game are complex because they must handle many different conditions. It is much simpler to drag only one object.
You cannot use the grab command, it doesn't provide enough feedback for this.
http://livecodeshare.runrev.com/stack/226/Klondike
It does set the location of the dragged objects repeatedly during a move. The mouseMove message is trapped and if the mouseLoc is not within the bounds of the card it does nothing.
If that's the example you mean I can give you a shorter version of the code. The handlers in the Klondike game are complex because they must handle many different conditions. It is much simpler to drag only one object.
You cannot use the grab command, it doesn't provide enough feedback for this.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 346
- Joined: Mon Mar 01, 2010 7:13 pm
- Location: London, UK
- Contact:
Re: lock objects from being dragged out of the screen
The sample stack helped a lot, thanks Jean-Marc!
(I do dearly wish it was as simple as SuperCard's grab [with message] [within rect]. I can see how this more complex mouseDown/mouseUp/mouseRelease/mouseMove setup can be really powerful, but surely there's room for something simpler (and in that sense more elegant) in the language as well?)
:-/ k
But still, great! This does the trick.
(I do dearly wish it was as simple as SuperCard's grab [with message] [within rect]. I can see how this more complex mouseDown/mouseUp/mouseRelease/mouseMove setup can be really powerful, but surely there's room for something simpler (and in that sense more elegant) in the language as well?)
:-/ k
But still, great! This does the trick.
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist
Re: lock objects from being dragged out of the screen
Mind you, I never read Jacque's code for that game, however the code for something like this can be as simple as what your talking about. Off the cuff, I wrote this (before seeing Jim post the link to here) in the bit of space inbetween my post and Jim's in the other thread, this is all in the button (or whatever object you choose for the slider*) -
Code: Select all
on mouseDown
// grab the bar/button in this case, could be any object...
grab me
end mouseDown
on mouseStillDown
// keeping the top of the bar/button in line with the top of the graphic...
if the top of me is not the top of graphic "Rectangle" then set the top of me to the top of graphic "Rectangle"
send mouseStillDown to me in 1 millisecond
end mouseStillDown
on mouseMove
// checking to make sure you haven't gone past the edge of the world...
if the left of me < the left of graphic "Rectangle" then
set the left of me to the left of graphic "Rectangle"
else if the right of me > the right of graphic "Rectangle" then
set the right of me to the right of graphic "Rectangle"
end if
end mouseMove
* I also forgot to ask why you wouldn't just use a slider, progress bar, or scroller for this since it is an already made control, and set north to whatever value you got from it?
*Edit - I also took the time this morning to check that 'within' actually works like its supposed to, changing the mouseMove code to this -
Code: Select all
on mouseMove
if the topLeft of me is not within the rect of grc "Rectangle" then
if the left of me < the left of of grc "Rectangle" then
set the left of me to the left of grc "Rectangle"
else if the right of me > the right of of grc "Rectangle" then
set the right of me to the right of grc "Rectangle"
end if
end if
end mouseMove
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: lock objects from being dragged out of the screen
Hi Bogs,
Yes. That seems simpler but I feel that is better to check that all corners are inside area BEFORE moving.
@ thatkeith
Best regards
Jean-Marc
Yes. That seems simpler but I feel that is better to check that all corners are inside area BEFORE moving.
@ thatkeith
Yes, after watching my script I think a function should be better than a large mousemove messagebut surely there's room for something simpler (and in that sense more elegant) in the language as well?)
Best regards
Jean-Marc
https://alternatic.ch
Re: lock objects from being dragged out of the screen
Heh, I absolutely agree with that sentiment, the above was a q&d version whipped up to test specifically what was asked about, in particular - "SuperCard's grab [with message] [within rect]. "
I definitely would not recommend using it without cleaning it up, as I said a few times, it only gets the job done, it is neither elegant nor even good
For one thing, you can see the button bobbing past the top of the rect momentarily at times (I suspect setting the "send to me in 0" would probably eliminate that), and for another it can be dragged past the edges (although it will snap back).
I still wonder why the slider, scrollbar, or progress bar wouldn't suffice for the description of the problem in this case though. Specifically, if I remember correctly**, he wanted the moving bar to align with north. Setting the value on any of those from 0-360 (I assume this is for that panoramic photo stuff) and then moving the picture opposite the value progress would be smoother and better looking.
** I was not too far off
Actually, I thought of an even simpler way, which I posted back in the other thread.thatkeith wrote: ↑Mon Dec 18, 2017 10:34 pmI'd like to have the user grab and drag a simple object across the card, but constrained to move in just one plane and also within a specific span. Specifically, a vertical line, dragged horizontally across an image, so the user can specify where North is in the image.
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: lock objects from being dragged out of the screen
Here are frame constraints . . .
I'll have a bash at single-plane constraint just as soon as I get myself a cup of coffee
I'll have a bash at single-plane constraint just as soon as I get myself a cup of coffee
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
-
- VIP Livecode Opensource Backer
- Posts: 7229
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: lock objects from being dragged out of the screen
@Richmond, have some pity and save people some time -- just paste the script into the forum. It will be easier to read, it can be copied and pasted, the user doesn't have to transcribe, and it will show up in the RSS feed along with the rest of the message. It's also less work for you than taking a snapshot and uploading an image.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: lock objects from being dragged out of the screen
What? Me?have some pity
Point taken . . . will bear that in mind in future.
Re: lock objects from being dragged out of the screen
Now I feel bad, since I often do that myself (of course, not knowing very much, the little code I post isn't as much to type in )richmond62 wrote: ↑Thu Dec 21, 2017 11:35 amPoint taken . . . will bear that in mind in future.have some pity
Re: lock objects from being dragged out of the screen
What I actually found eliminates that is -1, as in (from a remembered conversation with Jacque in a thread far away) -
Code: Select all
on mouseStillDown
if the top of me is not the top of graphic "Rectangle" then
set the top of me to the top of graphic "Rectangle"
end if
send mouseStillDown to me in -1
end mouseStillDown