Page 1 of 3
Can I get the name of an object at the clickloc?
Posted: Thu Apr 28, 2022 2:28 pm
by M-A Kuttner
Hi all. Nice to see you all at the conference and put some faces to names. My question: Is it possible to get the name of an object I click on just by clicking on it without that object having any code in it? Here's what I'm trying to do:
Code: Select all
on mouseUp
wait for the mouseclick
if the mouseclick is true then
get the backgroundcolor of the graphic at the clickloc
end if
end mouseUp
That's the gist of it. Any ideas? Thanks in advance!
Re: Can I get the name of an object at the clickloc?
Posted: Thu Apr 28, 2022 2:38 pm
by stam
I think maybe
the target is what you need?
ie
Code: Select all
get the backgroundColor of the target
Re: Can I get the name of an object at the clickloc?
Posted: Thu Apr 28, 2022 3:27 pm
by Klaus
What stam said!
Code: Select all
on mouseUp
wait for the mouseclick
if the mouseclick is true then
...
end mouseUp
Not sure what that may mean?
The "mouseup" message will only be sent if a "mouseclick" has in fact occured!
But you could also check for:
-> controlAtLoc(the mouseloc)
or
-> controlAtLoc(the clickloc)
Re: Can I get the name of an object at the clickloc?
Posted: Thu Apr 28, 2022 4:00 pm
by dunbarx
What all said about the "target", one of our most beloved functions.
Perhaps you are thinking about a second click when you check to see if the mouseClick is true? There is a method where it is useful. I find that the "mouseDoubleUp" message is often unreliable, and use this very old technique:
Code: Select all
on mouseUp
wait 20
if the mouseClick then beep 2 else beep 1
end mouseUp
You can use the mouseClick function to see if, er, the mouse was clicked.
Craig
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 7:55 pm
by M-A Kuttner
Thanks everyone! What Im trying to do is replicate a functionality similar to the eyedropper tool in Photoshop, so on mouseUp will switch the cursor from the pointer to my eyedropper cursor and then I want to wait until I roll over one of several graphics, each of which has a different backgroundcolor. When I click the second time, I want to put the backgroundcolor of the target graphic into a variable.
Right now, from what I'm seeing, the target is trapped as the thing I clicked on mouseUp, so when I click the second time (on one of my graphics), it releases the info on the target, but that info is from the the button that contained my original mouseUp instead of the graphic I'm currently clicking on.
So, is there a way to get rid of that mouseUp info and tell LC "Give me the info on the thing that's right under the cursor, right at this instant"?
Cheers,
M-A
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 8:27 pm
by stam
Hi M-A
I think the issue is that
a) you have the script running in a button when it should be in the card. When the button is clicked you act on that in the card script. You can't have logic in the button that will manipulate subsequent mouse clicks that aren't on the button
b) you need to keep track of whether you're sampling a colour or not.
for the latter just have a boolean script variable. If the variable is false and the name of the target is your button that kicks off the sampling then set the variable to true and when you next click it will give the background color of the control it's clicked on (the 'new' target)
edited to show the card script
Code: Select all
local sIsSampling
on mouseUp
if not sIsSampling and the short name of the target is "sample color" then
put true into sIsSampling
put empty into field "colour"
exit mouseUp
else if sIsSampling then
put the backgroundColor of the target into field "colour"
put false into sIsSampling
end if
end mouseUp
if you want to cancel the colour sampling after clicking the
sample color button you can trap the escape key in the card script:
Code: Select all
on escapeKey
# reset and stop it from sampling a colour
put false into sIsSampling
put empty into field "colour"
end escapeKey
I threw together a quick and very simple stack to illustrate - i hope this answers the question but do say if i've misunderstood your requirements...
regards
Stam
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 8:30 pm
by richmond62
Code: Select all
on mouseEnter
set the lockCursor to true
set the cursor to cross
end mouseEnter
on mouseLeave
set the cursor to empty
set the lockCursor to false
end mouseLeave
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 8:34 pm
by stam
The OP wants to
1. click a button to activate an 'eyedropper' color-sampling facility
2. move the mouse over graphics and when clicked a
second time to get the backgroundColor of the clicked object
Changing the cursor is nice, but it doesn't answer the OP
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 8:43 pm
by richmond62
on mouseUp will switch the cursor from the pointer to my eyedropper cursor
You have to start somewhere.
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 9:15 pm
by dunbarx
No sweat.
Make a graphic and color it any way you want. Make a field. Now make a button with this in its script:
Code: Select all
on mouseUp
set the cursor to cross
wait until the mouseClick
put the mouseColor into fld 1
end mouseUp
Craig
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 9:34 pm
by dunbarx
I just used the cross cursor because I like it. Know that you can use lots of things as cursors. If you already have your eyedropper, just mention its cursor identifier. This could take the form of setting the cursor property to the ID of an image, for example.
Craig
Re: Can I get the name of an object at the clickloc?
Posted: Fri Apr 29, 2022 11:04 pm
by M-A Kuttner
Fantastic! Thank you so much everyone! What a great community. Not only do I get a solution to my problem, but I also get a bunch of additional great info on how LC works and how to avoid rookie mistakes. You guys rock!
M-A
Re: Can I get the name of an object at the clickloc?
Posted: Sat Apr 30, 2022 6:40 pm
by jacque
I was going to suggest the mouseColor too, but note that you don't need to change the cursor for it to work. A single line in the mouseUp handler is all you need.
Edit: To be clear, set a custom cursor in the button that changes the tool to the eyedropper. In the card script put a mouseUp handler that checks for the cursor ID (you may have more than one type of cursor) and if it's the dropper then get the mouseColor.
Re: Can I get the name of an object at the clickloc?
Posted: Mon May 02, 2022 12:26 am
by dunbarx
The hard part is knowing what sort of gadgetry LiveCode offers when one is still learning.
So a great lesson here is this:
1- You wanted to get the underlying color when the mouse was clicked. "Color"and "Mouse" seem to be pertinent. Maybe even "Click".
2- You don't know, offhand, what LC has to offer in that regard.
3- You go to the dictionary and see that there are thousands of native words.
4- You are dismayed.
5- You think to yourself, "Oh hell, let's see what comes up when I enter the word 'color' in the search field".
6- Oh my, 80 or so entries where the word "color" appears directly in the entries, and these are at the top of the list.
7- Scroll down, disheartened, scanning, expecting nothing.
8- Wait, what's this??? "MouseColor??? Let's read about that...
9- YOW!!
You might have done the same thing by starting with "mouse" and would have had to deal with a list half as long. Not as logical, though.
That is the hard way to do it. The easy way was to ask here. But now and then you will have to do the hard way. After all, we don't know everything. Then you will appreciate those thousands of entries, because you will be optimistic that LC has a word for everything, pretty much, and you just have to find it.
Craig
Re: Can I get the name of an object at the clickloc?
Posted: Mon May 02, 2022 2:56 am
by stam
Assuming the premise is:
- the user clicks a button to activate an eyedropper tool
- the user clicks again to sample a colour, then the eyedropper tool deactivates
personally i would still do it the way i posted above - that is to say i'd run this in the
card script with a script local variable boolean to keep tabs on whether i'm sampling or not.
Whether you use
mouseColor or
backgroundColor of the target or whatever other data you want to collect is less important. 3 more words isn't even a drop in the verbose ocean of LiveCode
The main reason I'd do it this way is control: keeping the script in a button that will activate the eyedropper allows no easy is no way to cancel this action for example.
As a user, i would expect software to allow me to cancel an eyedropper tool by hitting the escape button.
Tougher to do in the button script where you are waiting for another mouseClick. Very simple in a card script
Also, wouldn't
lock the interface?
S.