Cursor during image movement?

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

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Cursor during image movement?

Post by Zax » Mon Nov 14, 2022 2:42 pm

I'm trying to move an image based on the mouse, as long as it's "down". I cannot use the Grab command because the image to be moved is not at the mouse location.
The following script works but I would like the cursor to be a cross during the movement, and it does not work: the cursor blinks from time to time during the movement but remains mainly in arrow.
Any idea?

Code: Select all

global PXCROP_ISMOVING
local gDeltaH, gDeltaV

on mouseDown
   put true into PXCROP_ISMOVING
   set cursor to cross ////////
   show img "ImgToMove"
   put (item 1 of the loc of img "ImgToMove") - the mouseH into gDeltaH
   put (item 2 of the loc of img "ImgToMove") - the mouseV into gDeltaV
end mouseDown

on mouseUp
   movePPend
end mouseUp

on mouseMove
   if (PXCROP_ISMOVING) then
      if (the mouseLoc is within the rect of group "GpeViewer") then
  	 set cursor to cross ////////
         set the loc of img "ImgToMove" to (the mouseH + gDeltaH) & comma & (the mouseV + gDeltaV)
      else movePPend
   end if
end mouseMove

on movePPend
   global PXCROP_ISMOVING
   put false into PXCROP_ISMOVING
end movePPend

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Cursor during image movement?

Post by Klaus » Mon Nov 14, 2022 3:18 pm

Hi Zax,

you need to UN-/LOCK the cursor!

Code: Select all

on mouseDown
   put true into PXCROP_ISMOVING
   LOCK CURSOR
   set cursor to cross ////////
   show img "ImgToMove"
...

on mouseUp
   UNlock cursor
   movePPend
end mouseUp
Best

Klaus

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

Re: Cursor during image movement?

Post by dunbarx » Mon Nov 14, 2022 3:23 pm

Would it not be easier to simply:

Code: Select all

on mouseMove
 if the mouse is down then set the loc of  img "ImgToMove" to the mouseLoc
  end mousemove
Craig

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

Re: Cursor during image movement?

Post by dunbarx » Mon Nov 14, 2022 3:28 pm

It occurs to me that you may need to filter that handler a little. Is there no other scenario where if you move the cursor while the mouse is down that you do NOT want that image to move? It seems unlikely that such a common action would work properly. I suggest that you consider something a little different:

Code: Select all

on mouseMove
 if the optionKey is down then set the loc of img "ImgToMove" to the mouseLoc
  end mousemove
Here it does not matter if the mouse is down or not, though you can also combine those two states.

Craig

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

Re: Cursor during image movement?

Post by dunbarx » Mon Nov 14, 2022 3:34 pm

Rereading yet again I see you want to:

Code: Select all

on mouseMove
   if the mouse is down then
      set the cursor to cross
      lock cursor
      set the loc of img "ImgToMove" to the mouseLoc
      end if
end mousemove

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: Cursor during image movement?

Post by Zax » Mon Nov 14, 2022 3:45 pm

Thanks Klaus and Craig :)
It works fine, and easier to read.

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

Re: Cursor during image movement?

Post by dunbarx » Mon Nov 14, 2022 8:24 pm

Zax.

Always good to hear of success.

What did you finally use to make it happen?

Craig

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: Cursor during image movement?

Post by Zax » Tue Nov 15, 2022 9:40 am

Craig,

I tried your elegant solution but:
1 - I need to do some stuff at the beginning of the movement
2 - the image to move is not at the mouse location (that's why I have deltaH and deltaV variables)
3 - I have some time consuming process to perform at the end of the movement
So I prefered my initial way, though it's a bit complicated.

Oh, and 4 - It's a weird project so I try different things but I don't know if the whole project is viable, or at least convenient for my use!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Cursor during image movement?

Post by richmond62 » Tue Nov 15, 2022 10:04 am

2 - the image to move is not at the mouse location
Do you want the image, at the point you move the mouse, to be at the mouseLoc?

2 possibilities:

Code: Select all

on mouseDown
set the loc of img "ImgToMove" to the mouseLoc
end mouseDown

on mouseMove
   if the mouse is down then
      set the cursor to cross
      lock cursor
      set the loc of img "ImgToMove" to the mouseLoc
      end if
end mouseMove
that will centre the image on the mouseLoc BEFORE you move the mouse.

Code: Select all

on mouseDown
set the topleft of img "ImgToMove" to the mouseLoc
end mouseDown

on mouseMove
   if the mouse is down then
      set the cursor to cross
      lock cursor
      set the topleft of img "ImgToMove" to the mouseLoc
      end if
end mouseMove
that will make the mouse appear to grab the image by the topleft and set the topleft to the mouseLoc BEFORE you move the mouse. If you move the mouse the image will continue to keep its topleft at the mouseLoc.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Cursor during image movement?

Post by richmond62 » Tue Nov 15, 2022 12:05 pm

How did you spend your lunch hour?
-
Screen Shot 2022-11-15 at 1.05.43 PM.png
-
The ONLY snag about this is that you have to click on a card to select it.
Attachments
Grabbit.livecode.zip
Stack.
(117.72 KiB) Downloaded 112 times

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: Cursor during image movement?

Post by Zax » Tue Nov 15, 2022 12:49 pm

Haha, thanks Richmond :)

My movements scripts are OK, just look at the modified version of your stack:

Grabbit_Modified.livecode.zip
(83.43 KiB) Downloaded 125 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Cursor during image movement?

Post by richmond62 » Tue Nov 15, 2022 2:04 pm

That is alright IFF you ONLY have a single card,
ORR you can always click on a card rather than somewhere else.

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

Re: Cursor during image movement?

Post by dunbarx » Tue Nov 15, 2022 3:11 pm

Jax.

Anything that works is already just fine.

But you said:
the image to move is not at the mouse location (that's why I have deltaH and deltaV variables)
I just want to make sure I understand. My handler pops the image at the mouseLoc directly. What do you need beyond that?

Craig

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

Re: Cursor during image movement?

Post by Zax » Tue Nov 15, 2022 3:34 pm

dunbarx wrote:
Tue Nov 15, 2022 3:11 pm
Anything that works is already just fine.
Rather wise :)

Please DL the modified version of Richmond's stack I posted and you will understand what I needed - much better than with my poor words!

@Richmond: this time, I'm not trying to move playing cards, but... a hole. A real hole in the card that shows what is below (using a png image and the stack decorations).

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

Re: Cursor during image movement?

Post by dunbarx » Tue Nov 15, 2022 7:16 pm

Ah, OK, I read your first post:
I cannot use the Grab command because the image to be moved is not at the mouse location.
as having the image track the mouseLoc. Not a problem, the offset solution is straightforward.

When you say "move a hole" do you mean that this moving hole uncovers, to the extent of the hole itself, a portion of an image that sits below a blank white image or control? That the "hole" is a moving window "through" that white image?

If so I can think of a way to do that, but not directly, that is, that the hole somehow makes the round area it subtends transparent.

Craig

Post Reply