Page 1 of 1

A different target on mouse Down

Posted: Tue Mar 29, 2016 10:17 am
by trevix
Most mouse messages are not sent while the mouse is down and the "target" refers to the first clicked object (not the object under the mouse)
Using "grab" we all have to resort to something like this:

Code: Select all

on mouseDown
grab the target
end mouseDown

Code: Select all

on mouseMove
if the mouseLoc is within the rect of image "SomeImage" then 
# do stuff here
end if
end mouseMove
It would be nice to have a function like..."LocTarget" or something, that returns the name of the object under the mouse, even if the mouse is down, without having to check for every potential target inside your mouseMove handler.

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 12:53 pm
by jmburnod
Hi Trevix,
something, that returns the name of the object under the mouse
You can use mousecontrol()
Best regards
Jean-Marc

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 2:26 pm
by trevix
From the dictionary:
If the mouse button is down, the mouseControl function returns the control that was clicked, even if the mouse has moved to another control.
It doesn't work.
Look for example what a complex script Niggemann has to use in its "Connecting objects with movable lines" (in Sample Stacks form the LC menu)

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 6:33 pm
by richmond62
Simple stuff going down round here:
OVER.png

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 9:03 pm
by richmond62
While this sort of thing works:

on mouseMove
if the mouseLoc is within the rect of graphic "g1" then
put "It's the red square" into fld "OVER"
end if
end mouseMove

this sort of thing does NOT:

on mouseMove
if the mouseLoc is within the rect of graphic "g1" then
send "mouseDown" to graphic "g1"
end if

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 9:27 pm
by trevix
It all come to this:
Is there a logical, rational, impassable reason why in LC most mouse messages are not sent while the mouse is down ?
Wouldn't be handy an addition target function of some sort that does, while keeping the original target on mousedown?

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 9:39 pm
by FourthWorld
trevix wrote:It all come to this:
Is there a logical, rational, impassable reason why in LC most mouse messages are not sent while the mouse is down?
http://quality.livecode.com/show_bug.cgi?id=1832

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 9:56 pm
by richmond62
Is there a logical, rational, impassable reason why in LC most mouse messages are not sent while the mouse is down ?
Probably not.

But: have you ever considered the complexities of writing a programming language from the ground up?

I would be extremely surprised, given the complexities of computers, and the low-level languages a
high-level language has to go through (Assembler, anyone?), if anyone making a new (or, as in the case
of LiveCode: building 95% on top of the 5% inherited from HyperCard) language managed to cover all
possibilities . . .

That it is possible to trap moving one's mouse over other objects when one already has one's mouse down,
thus allowing scripts to "fire" should suffice for all but the most bizarre requirements.

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 10:13 pm
by richmond62
Another thing worth recalling from the Paleolithic age of RunRev 2 is the "do" command, as in

do fld "somethingToBeDone"

which is quite useful as one then doesn't have to store an enormously long script in one's card script or somesuch.

Therefore it should be quite reasonable to have something like this in one's card script:

on mouseMove
if the mouseLoc is within the rect of graphic "g1" then
do fld "f1"
end if
if the mouseLoc is within the rect of graphic "g2" then
do fld "f2"
end if
if the mouseLoc is within the rect of graphic "g3" then
do fld "f3"
end if
if the mouseLoc is within the rect of graphic "g4" then
do fld "f4"
end if
end mouseMove

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 10:30 pm
by trevix
In total humility I notice this:

- LC strong point is easiness of use
- dragging things on top of other things is a very common UI request
- drag action (start, end, etc) is quite complex (in my opinion) (and the only solution to drag things between windows).
- grab is great but to no use if you need to know where you place things.
- I always have to resort to the 4 handlers, as FourthWorld is saying.

To me it would be nice to know what is under the pointer, even if the mouse is down (specially since on mobile is alway down, no mouse move with the mouse up).

As for the mouseMove, I always find my self having to do a repeat loop inside it, trough all the controls, to find find out the "within the rect". I mean...is different if you want to know if the MouseLoc is on top of control X, or you want to know the name of the control under the MouseLoc

Re: A different target on mouse Down

Posted: Tue Mar 29, 2016 10:33 pm
by FourthWorld
trevix wrote:As for the mouseMove, I always find my self having to do a repeat loop inside it, trough all the controls, to find find out the "within the rect". I mean...is different if you want to know if the MouseLoc is on top of control X, or you want to know the name of the control under the MouseLoc
Try the mouseControl function.

Re: A different target on mouse Down

Posted: Wed Mar 30, 2016 5:51 pm
by jacque
Or controlAtLoc() might work. I think the mousecontrol will return the object being dragged.

Re: A different target on mouse Down

Posted: Wed Mar 30, 2016 6:49 pm
by trevix
Uuuuh.... Interesting controlAtLoc(), but still it doesn't work.
As for the MouseControl, if the mouse is down while you move, it report the control that you are moving.

If you put a flag on a control "ButtonDrag"

Code: Select all

global gStarted
on mouseDown
    put true into gStarted
end mouseDown

On MouseUp
    put false into gStarted
end MouseUp
and you put a MouseMove on the stack script

Code: Select all

global gStarted
On mouseMove newMouseH,newMouseV
    if   gStarted then
        set the loc of btn "ButtonDrag" to (newMouseH,newMouseV)
        get controlAtLoc((newMouseH,newMouseV)) 
        if it is not empty then
            put the short name of it into msg
        end if
    end if
end mouseMove
the controlAtLoc() report the "ButtonDrag", not some other control you hover.
Same if you use "grab me".
Am I missing something ?
Thanks for the help

Re: A different target on mouse Down

Posted: Wed Apr 06, 2016 11:11 pm
by trevix
In order for controlAtLoc to work, the clicked control must be sent to back, in respect to any other control you may hover.

The solution has been suggested by Mark on http://quality.livecode.com/show_bug.cgi?id=1832
In this way is possible to see what is under the mouse, even if it is moved around with the mouse down.
This idea should be quite popular.