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!
I want to be able to move a line (while NOT in edit mode) simply by clicking and holding the mouse and dragging it to a desired position. I have implemented a script to do this which was easy enough:
on mouseStillDown
set the loc of me to the mouseLoc
end mouseStillDown
The question I have is that since the line thickness is only one pixel thick which makes it a tad more difficult to move requiring the user to correctly position the cursor over the line in order to move it, is there a way to somehow add "padding" around the line to make it easier to click on and move?
It was a revelation to me that you can actually just use pointer tool even in standalone apps (just set the cantSelect of the interface elements you don’t want the user to move to true), making moving/resizing easier, so that’s something to consider, but possibly doesn’t fulfil your use case.
As to moving lines - that’s a pain. I don’t know if grouping the line may help, as it adds a 4 px margin - maybe move your code into the line’s group?
I know some just don’t use lines at all and just use a rect with real narrow width or height, so again that may help…
I tried creating a group and adding the line to it. As you said, it had a 4px margin. I also added the aforementioned script to the group element but it won't move. I tried making the group opaque but that didn't help.
This is either homework for you or homework for me. I vote for you.
On a new card make a vertical graphic. Vertical, because we are going to demonstrate a principle. The homework comes later, when this principle has to be made more universal.
I downloaded your stack. When I put the cursor in the red area, the object will not move. I have to the put the hotspot of the cursor right on the line to get it to move. Am I missing something?
Thanks,
Jon
P.S. was my reply my homework?
richmond62 wrote: Wed May 24, 2023 11:33 am
SShot 2023-05-24 at 13.31.09.png
-
While the line is only 2 pixels thick, I have set the width of the group to 20 pixels, and 'stained' it red for demonstration purposes only.
A moronically simple solution that works.
-
Just grab it and 'run'.
I tried your script and it worked! As there could be more than one line added, will need to figure out how to get the script to account for the number of graphics already present so that only the one that is clicked moves and not any others.
This is either homework for you or homework for me. I vote for you.
On a new card make a vertical graphic. Vertical, because we are going to demonstrate a principle. The homework comes later, when this principle has to be made more universal.
So now it matters how sloppy you will tolerate the distance between the graphic and the cursor. It now may matter how many other graphics there are and how close they might be to each other.
May I assume that these graphics will have varying angles?
local myTool
on mouseenter
put the tool into myTool
if myTool is "browse tool" then
select me
choose pointer
end if
end mouseenter
on mouseLeave
if myTool = "browse tool" then
select empty
choose browse
end if
end mouseLeave
Then set the behavior of each line to that button.
dunbarx wrote: Wed May 24, 2023 6:22 pm
Let me know when you find out the one little thing that may well become homework.
Craig,
here is my assignment. It also solves the problems with lines since it uses the rect of a graphic.
For horizontal lines and vertial lines you could group those and it will increase the "hot" area for mouseDown to make it easer to grab the line.
Using your stack and applying this code to the card script:
local sGrcToMove
local sDiffX, sDiffY
on mouseMove pX, pY
if sGrcToMove <> "" and the mouse is down then
set the loc of grc sGrcToMove to pX + sDiffX, pY + sDiffY
end if
end mouseMove
on mouseDown
put the mouseLoc into tMLoc
put empty into sGrcToMove
repeat with i = 1 to the number of graphics
if the owner of grc i begins with "group" then
put true into tGrouped
put the rect of the owner of grc i into tOwnerRect
else
put false into tGrouped
put empty into tOwnerRect
end if
if (tMLoc is within the rect of grc i) or (tGrouped and tMLoc is within tOwnerRect) then
put the name of grc i into sGrcToMove
exit repeat
end if
end repeat
if sGrcToMove is empty then exit mouseDown
put the loc of grc sGrcToMove into tGLoc
put item 1 of tGLoc - item 1 of tMLoc into sDiffX
put item 2 of tGLoc - item 2 of tMLoc into sDiffY
end mouseDown
on mouseUp
put empty into sGrcToMove
end mouseUp