Click and/or drag ?

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Click and/or drag ?

Post by richmond62 » Sat Mar 02, 2024 9:32 am

Personally I'd be inclined to try INTERSECT . . .
-
Screenshot 2024-03-02 at 10.48.40.jpg
Attachments
INTERSECT GRABBABLES.livecode.zip
(37.42 KiB) Downloaded 20 times

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Click and/or drag ?

Post by Zax » Sat Mar 02, 2024 12:29 pm

Thanks richmon62, it works fine... But I forgot to specify that I would like a visual effect on (all) the possible destination areas.
So, in your example, I would like the pale blue circle to change visually when we can release the mouse to place the orange square on the target. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Click and/or drag ?

Post by richmond62 » Sat Mar 02, 2024 1:09 pm

Have a go with this:

Code: Select all

on mouseDown
   put empty into fld "f1"
   grab me
end mouseDown

on mouseUp
   if intersect(img"DRAGGER", img "t3", 5) then
      put "SUCCESS" into fld "f1"
      set the ink of img "t3" to blendExclusion
   end if
   if intersect(img"DRAGGER", img "t1", 5) then
      put "WRONG" into fld "f1"
      move img "DRAGGER" to 89, 86
   end if
   if intersect(img"DRAGGER", img "t2", 5) then
      put "WRONG" into fld "f1"
      move img "DRAGGER" to 89, 86
   end if
end mouseUp
Attachments
INTERSECT GRABBABLES_2.livecode.zip
(37.69 KiB) Downloaded 20 times

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Click and/or drag ?

Post by Zax » Sat Mar 02, 2024 1:40 pm

Sorry if I wasn't not accurate. I would like the visual effect to be shown before the mouse is released, in order to show that the dragged element can be dropped onto the target (here, the pale blue circle).

This could be done with a loop during grab but I'm afraid it would make the movement jerky - I currently have 96 possible targets on a card.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Click and/or drag ?

Post by Klaus » Sat Mar 02, 2024 1:46 pm

Maybe you can create and use a "on dragenter" behavior for your 96 objects?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Click and/or drag ?

Post by richmond62 » Sat Mar 02, 2024 3:18 pm

Well, I just put something in a mouseStillDown:

Code: Select all

on mouseDown
   put empty into fld "f1"
   grab me
end mouseDown

on mouseStillDown
   if intersect(img"DRAGGER", img "t3", 5) then
      set the ink of img "t3" to blendExclusion
   end if
end mouseStillDown

on mouseUp
   if intersect(img"DRAGGER", img "t3", 5) then
      put "SUCCESS" into fld "f1"
      set the ink of img "t3" to blendExclusion
   end if
   if intersect(img"DRAGGER", img "t1", 5) then
      put "WRONG" into fld "f1"
      move img "DRAGGER" to 89, 86
   end if
   if intersect(img"DRAGGER", img "t2", 5) then
      put "WRONG" into fld "f1"
      move img "DRAGGER" to 89, 86
   end if
end mouseUp
Admittedly if that is checking whether it overlaps 96 objets that might slow things down a bit.
Attachments
INTERSECT GRABBABLES_3.livecode.zip
(37.7 KiB) Downloaded 18 times

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Click and/or drag ?

Post by Zax » Sat Mar 02, 2024 3:40 pm

Klaus wrote:
Sat Mar 02, 2024 1:46 pm
Maybe you can create and use a "on dragenter" behavior for your 96 objects?
That's the problem: dragDrop and dragEnd built-in messages don't seem to be triggered when a LC control is dropped onto another LC control. Yet, according to the Dictionary, the fullDragData property has a "objects" key dedicated to LC objects.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Click and/or drag ?

Post by Klaus » Sat Mar 02, 2024 4:32 pm

Works fine here, but maybe a little different than what you think! :-)
See example stack...

EDIT: Removed the silly stack

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Click and/or drag ?

Post by Klaus » Sat Mar 02, 2024 5:14 pm

My stack is quite rudimentary, you should add a "dragimage" (screenshot of the control to be dragged).
Seems to be the only way of "faking" a LC "grab me" kind of action.

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Click and/or drag ?

Post by Zax » Sat Mar 02, 2024 5:16 pm

Cute design ;)
But nothing is draggable with LC 9.6.x... Am I missing something?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Click and/or drag ?

Post by richmond62 » Sat Mar 02, 2024 5:27 pm

No: you are NOT missing anything: as downloaded the stack (at least with LC 9.6.3) does NOT work).

If you add a line to the script of the "Drag me" button like this:

Code: Select all

on mouseDown 
   set the dragdata["text"] to the long ID of me
   grab me
end mouseDown
it can be dragged; but NOT far enough to land on any of the circles.

My stack works: well, at least for a few targets. 8)
Last edited by richmond62 on Sat Mar 02, 2024 5:29 pm, edited 1 time in total.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Click and/or drag ?

Post by Klaus » Sat Mar 02, 2024 5:28 pm

Drag the button on the topleft (just as its LABEL say) onto one of the colored graphics...
A dragimage might clarify this.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Click and/or drag ?

Post by richmond62 » Sat Mar 02, 2024 5:30 pm

Drag the button on the topleft (just as its LABEL say) onto one of the colored graphics...
Das funktioniert nicht. :?

Just tried a drag:
-
Screenshot 2024-03-02 at 18.31.22.png

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Click and/or drag ?

Post by Klaus » Sat Mar 02, 2024 5:44 pm

Here a really working stack, sorry for the others...
Attachments
drip_drop3.livecode.zip
(2.49 KiB) Downloaded 18 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Click and/or drag ?

Post by richmond62 » Sat Mar 02, 2024 5:47 pm

Indeed that works. 8)

The disadvantage with your stack is that the end-user gets visual feedback when s/he performs a drag, but the "drag image" does not remain on the target.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”