A different target on mouse Down

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

A different target on mouse Down

Post by trevix » Tue Mar 29, 2016 10:17 am

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.
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: A different target on mouse Down

Post by jmburnod » Tue Mar 29, 2016 12:53 pm

Hi Trevix,
something, that returns the name of the object under the mouse
You can use mousecontrol()
Best regards
Jean-Marc
https://alternatic.ch

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: A different target on mouse Down

Post by trevix » Tue Mar 29, 2016 2:26 pm

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)
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

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

Re: A different target on mouse Down

Post by richmond62 » Tue Mar 29, 2016 6:33 pm

Simple stuff going down round here:
OVER.png
Attachments
OVER.livecode.zip
Here's the stack to mess around with.
(108.39 KiB) Downloaded 180 times

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

Re: A different target on mouse Down

Post by richmond62 » Tue Mar 29, 2016 9:03 pm

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

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: A different target on mouse Down

Post by trevix » Tue Mar 29, 2016 9:27 pm

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?
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: A different target on mouse Down

Post by FourthWorld » Tue Mar 29, 2016 9:39 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: A different target on mouse Down

Post by richmond62 » Tue Mar 29, 2016 9:56 pm

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.

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

Re: A different target on mouse Down

Post by richmond62 » Tue Mar 29, 2016 10:13 pm

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

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: A different target on mouse Down

Post by trevix » Tue Mar 29, 2016 10:30 pm

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
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: A different target on mouse Down

Post by FourthWorld » Tue Mar 29, 2016 10:33 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: A different target on mouse Down

Post by jacque » Wed Mar 30, 2016 5:51 pm

Or controlAtLoc() might work. I think the mousecontrol will return the object being dragged.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: A different target on mouse Down

Post by trevix » Wed Mar 30, 2016 6:49 pm

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
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: A different target on mouse Down

Post by trevix » Wed Apr 06, 2016 11:11 pm

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.
Attachments
Test Drag Line.livecode.zip
Draw a line between controls and see the secondary targets
(2.04 KiB) Downloaded 182 times
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

Post Reply