Get properties of object when in "pointer mode"

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

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm

Get properties of object when in "pointer mode"

Post by raugert » Thu Mar 08, 2018 3:24 am

I finally got the "Choose pointer tool" to work for moving and resizing object in runtime, but I think I ran into
the challenges of managing mixed tool modes
as mentioned by Richard in another post :wink: . I can't seem to obtain the properties of the "selected Object" when in that mode. For example, I would like to get the name, id and position of the object when I select it.

I tried using:

Code: Select all

put name of selectedObject into field "xxx"
      or
put the name of target into field "xxx"

but these commands don't work when in pointer mode. Is there another command that I can use ?
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

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

Re: Get properties of object when in "pointer mode"

Post by FourthWorld » Thu Mar 08, 2018 3:32 am

The target would be something else; the selectedObject works here. Can we see the handler that's failing?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm

Re: Get properties of object when in "pointer mode"

Post by raugert » Thu Mar 08, 2018 5:32 am

I was just putting the following code into the button, but I guess it doesn't work because it thinks I'm editing it, and doesn't send the selectedObject command to itself.

Code: Select all

on mouseDown pButtonNumber
   put the loc of selectedObject into field "test"
end mouseDown
However, if I put the same code into another button with it's property set to "cantSelect" so it becomes the handler button, it will recognize the previous "selectedObject" and actually put it's loc into the field.

Now that makes sense to me, but I just want to get the information of a button that I click (which is in pointer mode), to appear into a field... :?

Not sure if I'm explaining myself correctly..
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

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

Re: Get properties of object when in "pointer mode"

Post by FourthWorld » Thu Mar 08, 2018 5:41 am

Yes, that makes sense. The selectedObject is working, just not as quickly as mouseDown is fired. What would you like to do? Maybe we can come up with a good way to use the message path and sequence to your advantage.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Get properties of object when in "pointer mode"

Post by bogs » Thu Mar 08, 2018 5:45 am

Wonder if sticking the working code into a handler, then running the handler on mouseDown would resolve the issue.
Image

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm

Re: Get properties of object when in "pointer mode"

Post by raugert » Thu Mar 08, 2018 6:42 am

@bogs

I tried a few ways of running a separate handler on mouseDown, but it appears that the clicked button's mouseDown message path won't send the the scripted mouseDown message (not sure if that makes sense :shock: )..

Maybe Richard's idea of using the message path can be explored. (I'm not too sure how to do that)

Here's what I"m trying to do:

1. Set pointer mode so that the user can move and size a button (this works so far)
2. When a user then clicks on a button, it would display its location, id, etc., into individual fields (the info from these fields will then be added to a datagrid which will be used later to recall button parameters)

That's about it.
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Get properties of object when in "pointer mode"

Post by bogs » Thu Mar 08, 2018 2:12 pm

Did you confirm that by setting a break point at the line in the debugger and tracing out what happens after that?

Curious which vers. of Lc your using as well as the Os.
Image

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm

Re: Get properties of object when in "pointer mode"

Post by raugert » Thu Mar 08, 2018 5:37 pm

I set a breakpoint and confirmed that the mouseDown command is not sent when in pointer mode. Frankly, I'm not sure what command is actually sent when you click an object when in pointer mode.

Simply put, I just want to get the object's parameters when I click on it. Exactly what happens when you click an object and it's parameters appear in the "Property Inspector"

I'm using LC 9.0.0-dp-11 Indy, Mac OS 10.12.6
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Get properties of object when in "pointer mode"

Post by bogs » Thu Mar 08, 2018 5:42 pm

Hmm. We got snowed over today (about a foot), so I'll probably be too busy for a look today, but I will take a look if no one gets back to you.
Image

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

Re: Get properties of object when in "pointer mode"

Post by jacque » Thu Mar 08, 2018 6:10 pm

The IDE traps all editing functions so it can update its various stacks. Try hiding the IDE and see what works. That will simulate how a standalone will behave.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Get properties of object when in "pointer mode"

Post by bogs » Thu Mar 08, 2018 10:22 pm

raugert wrote:
Thu Mar 08, 2018 5:37 pm
Frankly, I'm not sure what command is actually sent when you click an object when in pointer mode.
This at least should be easier to find out. In the developer menu you should see 'message watcher', which will pretty much dispatch any messages you can tap into.

As for what your trying to accomplish, mind you, this isn't perfect, and I'm not even sure it is what you are asking about, nor is it polished in any way. I'm sure there are better ways to do it, as well.

I set this to the two separate mouse events, down and up. The code is all in the stack, which is ultimately where all messages go to die :D

Code: Select all

on mouseDown
   if the first word of the target is not "card" then
      put "The loc is [" & the loc of the target & "], the height is " & the height of the target & ", the width is " & the width of the target into field "Field"
   end if   
end mouseDown

on mouseUp
   if the first word of the target is not "card" then
      if the mouseLoc is within the rect of the target then
         choose pointer tool
         select the target 
      else
// do nothing to change the cursor on a click / drag type motion...
      end if
   end if
end mouseUp
This won't give you information about fields, but pretty much anything else you click on aside from the card should report back. Hope it helps.

*Edit, don't forget to set a separate button to change your tool back to browse, or in a standalone you are pretty well stuck if you don't rig it somehow.

*Edit 2, this seemed to work, code stuck in your restoring buttons script -

Code: Select all

on mouseUp
   if the mouseLoc is within the rect of me then
      choose browse tool
   end if
end mouseUp
Image

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm

Re: Get properties of object when in "pointer mode"

Post by raugert » Fri Mar 09, 2018 4:13 am

Thanks bogs,

That's pretty well what I was playing with on my own, so I feel pretty good that you suggested it (being way more expert than me :) )

But I find that it's becoming pretty convoluted when switching the tool mode back and forth. Then I run into other issues, like trying to edit 2 object one after the other, without switching back to browse mode by using another button. It's just too much clicking around when editing multiple objects... Not ideal for my application.

For the moment, I think I'll take the path of less resistance and use a separate handler to move/size objects, rather than using the pointer tool's handler. Simpler for now.

I really do appreciate the pointers (pun intended :P) from ALL OF YOU on the forum ! I'm discovering a lot.
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Get properties of object when in "pointer mode"

Post by bogs » Fri Mar 09, 2018 5:36 am

Your welcome but -
raugert wrote:
Fri Mar 09, 2018 4:13 am
being way more expert than me :)
I wouldn't count on that being true HAH :mrgreen: I'm at best a 3rd rate hack. Jacque has pretty close been there since the start, longest legs of the names I know here anyway, and a few others.

I'm not sure what you meant by
I run into other issues, like trying to edit 2 object one after the other, without switching back to browse mode by using another button.
While I was playing with the code, I was able to select one object, then while in pointer mode select a completely different object and back again without ever going to browse mode, and the field updated to match the new object each time. Or did you mean something else? Just curious, as your other plan seems fine to me.
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Get properties of object when in "pointer mode"

Post by [-hh] » Fri Mar 09, 2018 6:40 am

If you really want to work with the pointer tool then you could simply make a check button "EDIT" with the following script.

Code: Select all

on mouseLeave
   if the hilite of me then choose pointer tool
   else choose browse tool
end mouseLeave

on mouseEnter
   choose browse tool
end mouseEnter
Check the button if you wish to have the pointer tool and do what you want with several objects. When done uncheck the button and you are back in browse mode.
shiftLock happens

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm

Re: Get properties of object when in "pointer mode"

Post by raugert » Fri Mar 09, 2018 7:42 am

Sorry bogs, The issue of switching back and forth wasn't really your code. Your code works good for getting the button parameters into a field, but then I can no longer move/size object. So I was trying to add some code to it.

I'm assuming it's because these mouseUp/Downs handlers replace the pointer tool's mouse handlers when in pointer mode. Then I was trying to switch the browse/pointer tool back and forth to see if I could come up with something that would let me select the object, get the data, allow for resizing and moving, then put the new data back in the field. Sounds like I'm asking for a lot, but I see this done in other applications that I'm pretty sure were done in Livecode. I don't think I'm allowed to mention the app on the forum... I was getting close but started going in circles... :roll:

In any case here's my solution I ended up with (to avoid tool selection issues):

Code: Select all

local resize

on mouseDown b
   if the first word of the target is not "card" then
      put "The loc is [" & the loc of the target & "], the height is " & the height of the target & ", the width is " & the width of the target into field "Field"
   end if   
   select target
   if item 1 of clickLoc() - item 3 of rect of target < -10 and the first word of the target is not "card" then
      grab target
   else
      put true into resize
   end if
end mouseDown

on mouseup
   put false into resize
end mouseup

on mouserelease
  put false into resize
end mouserelease

on mouseMove x, y
   if resize = true then
      put the top of target into myTop
      set the height of target to (the height of target - (the bottom of target -item 2 of mouseLoc() ))
      set the top of target to myTop
      put the left of target into myLeft
      set the width of target to (the width of target - (the right of target -item 1 of mouseLoc() ))
      set the left of target to myLeft
   end if
end mouseMove
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

Post Reply