Page 1 of 2

Cursor during image movement?

Posted: Mon Nov 14, 2022 2:42 pm
by Zax
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

Re: Cursor during image movement?

Posted: Mon Nov 14, 2022 3:18 pm
by Klaus
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

Re: Cursor during image movement?

Posted: Mon Nov 14, 2022 3:23 pm
by dunbarx
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

Re: Cursor during image movement?

Posted: Mon Nov 14, 2022 3:28 pm
by dunbarx
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

Re: Cursor during image movement?

Posted: Mon Nov 14, 2022 3:34 pm
by dunbarx
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

Re: Cursor during image movement?

Posted: Mon Nov 14, 2022 3:45 pm
by Zax
Thanks Klaus and Craig :)
It works fine, and easier to read.

Re: Cursor during image movement?

Posted: Mon Nov 14, 2022 8:24 pm
by dunbarx
Zax.

Always good to hear of success.

What did you finally use to make it happen?

Craig

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 9:40 am
by Zax
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!

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 10:04 am
by richmond62
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.

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 12:05 pm
by richmond62
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.

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 12:49 pm
by Zax
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

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 2:04 pm
by richmond62
That is alright IFF you ONLY have a single card,
ORR you can always click on a card rather than somewhere else.

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 3:11 pm
by dunbarx
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

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 3:34 pm
by Zax
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).

Re: Cursor during image movement?

Posted: Tue Nov 15, 2022 7:16 pm
by dunbarx
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