Moving a line...

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

cmhjon
Posts: 175
Joined: Tue Aug 04, 2015 11:55 am

Re: Moving a line...

Post by cmhjon » Wed May 24, 2023 7:39 pm

Hi Craig,

I suppose that two line graphics could be placed in very close proximity to each other such they might overlap so I will deal with that if and when the time comes. For now, I am only going to offer my users either 0° or 90°angles.

Best regards,
Jon
dunbarx wrote:
Wed May 24, 2023 5:36 pm
Hi.

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?

Craig

cmhjon
Posts: 175
Joined: Tue Aug 04, 2015 11:55 am

Re: Moving a line...

Post by cmhjon » Wed May 24, 2023 7:41 pm

I tried your stack containing multiple graphics and I think that will work perfectly! :)

Thank you so much!
Jon :)
dunbarx wrote:
Wed May 24, 2023 6:22 pm
Try this stack.

Let me know when you find out the one little thing that may well become homework.

Craig

MoveGraphicsAround.livecode.zip

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Moving a line...

Post by dunbarx » Wed May 24, 2023 8:26 pm

@ Bernd.

Groups? Yuck.

@Jon

Try this. It does require that the user click near the center of a line graphic. It will not work well if too far from that point. This does your homework for you. Check out the card script.

Craig
MoveGraphicsAround2.livecode.zip
(1.12 KiB) Downloaded 59 times
Last edited by dunbarx on Wed May 24, 2023 8:39 pm, edited 2 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Moving a line...

Post by dunbarx » Wed May 24, 2023 8:34 pm

Bernd.

I looked at your handler but didm't try it out. But would not using the rect of a graphic cause issues if several lines were close together and their rects overlapped? Now the layers of those controls becomes a problem, no?

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Moving a line...

Post by bn » Wed May 24, 2023 8:53 pm

dunbarx wrote:
Wed May 24, 2023 8:34 pm
Bernd.
I looked at your handler but didm't try it out. But would not using the rect of a graphic cause issues if several lines were close together and their rects overlapped? Now the layers of those controls becomes a problem, no?
Craig
Overlap is a problem but that can be mitigated by setting the grabbed graphic to "top" and instead of having the repeat start at graphic 1 let it start at the number of graphics down to one so you grab the last moved graphic in case of overlap.
Groups? Yuck.
Groups are optional for horizontal or vertical lines that are hard to grab.

Here is a revised script. You might want to try it to find out if it is too cumbersome to use with your stack.

Code: Select all

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 = the number of graphics down to 1
      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
   if tGrouped then
      set the layer of the owner of graphic sGrcToMove to top
   else
      set the layer of graphic sGrcToMove to top
   end if
end mouseDown

on mouseUp
   put empty into sGrcToMove
end mouseUp
Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Moving a line...

Post by dunbarx » Wed May 24, 2023 9:36 pm

Bernd.

I like your script, mainly because it allow tracking to smoothly follow the cursor where the mouse goes down, not necessarily near the center. But It has an issue in that, as we discussed, using the rect will blanket a smaller graphic that lies very near a larger one.

Since mine does not use rects at all, it does not suffer from that.

I took a shortcut in using the loc to determine the proximity of, essentially, the clickLoc. A better solution would allow, without rects, the user to click anywhere near any portion of any graphic, and have that graphic track the mouseLoc from that point. And that without having the graphic snap to the moving mouseLoc.

One problem with line graphics is that theit points property consists of only two lines. That is all that is needed for LC to draw them. So there are no "intermediate" points, as there are, say, with a freeform graphic. With such an grc, one could loop through all its points, and determine the distance from any of them to the clickLoc. If any one of them were close enough, bingo.

So much fun...

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9286
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Moving a line...

Post by richmond62 » Thu May 25, 2023 10:34 am

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?
Sorry, been up to 'here' with non-LC matters for 2 days.

Indeed that seems to be the case: which stinks.

THIS does NOT use a group:
-
SShot 2023-05-25 at 12.42.50.png
-
It should work perfectly well with an image that is the same colour as the card.
Attachments
Line Mover #2.livecode.zip
Stack.
(23.4 KiB) Downloaded 56 times

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Moving a line...

Post by stam » Thu May 25, 2023 3:22 pm

cmhjon wrote:
Tue May 23, 2023 9:15 pm
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?

Thank you,
Jon :-)
Hi Jon,
some good suggestions here but may be less feasible in a wider project.

How about this: instead of providing padding, just highlight the object with an outerGlow effect when the mouse is at the right spot -- this still requires accurate placement, but the user will be guided to where that placement is.

For example, in the card or stack script put this:

Code: Select all

command assignGlow pControlID
    set the outerglow of pControlID to setGlowParams()
end assignGlow

function setGlowParams
    local tGlow
    put "normal" into tGlow["blendmode"]
    put 221,46,62 into tGlow["color"]
    put "box3pass" into tGlow["filter"]
    put 186 into tGlow["opacity"]
    put 255 into tGlow["range"]
    put 7 into tGlow["size"]
    put 73 into tGlow["spread"]
    return tGlow
end setGlowParams
This code will assign the outerGlow as defined in setGlowParams(), I just put some random stuff in there to make it red-ish.

In the line's script put this:

Code: Select all

on mouseEnter
    assignGlow the long id of me
end mouseEnter

on mouseDown
    grab me
end mouseDown

on mouseLeave
    set the outerglow of me to empty
end mouseLeave
This has the effect of highlighting the line when the mouse is in the correct position; if the user then clicks they can drag it freely around. When the mouse leaves the rect of the line, the outerGlow goes away.
By using the script in card or stack, you can generalise this to any object that needs highlighing in this fashion...

HTH
S.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Moving a line...

Post by dunbarx » Thu May 25, 2023 4:13 pm

Stam.

Fun stuff.

Using the "grab" command is certainly simpler, but it does not give much wiggle room when targeting a graphic. I went off that idea early on, and went to a more kludgy method, which is more my style. :wink:

@Jon If you change the value of the "wiggle room" in the latest stack I posted, from the "15" already there to, say, 30 or 50. you can "grab" a graphic with fairly sloppy aim. But if you make that value too large, you may have trouble if certain graphics overlap or are otherwise too close to each other. A tradeoff, as most things are.

Anyway, definitely play with all of this; it is a pretty good LC lesson.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Moving a line...

Post by dunbarx » Thu May 25, 2023 4:23 pm

Stam.

The dictionary says:
You can only grab a control when the mouse pointer is within the control's rectangle at the time the mouse is clicked.
Is this a literary bug? The grab command does seem to work if the pointer is a couple of pixels off the actual line, either side, but no more than about three. It certainly does not work within "...the control's rectangle..."

Craig

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Moving a line...

Post by stam » Thu May 25, 2023 5:01 pm

Craig

dunbarx wrote:
Thu May 25, 2023 4:13 pm
but it does not give much wiggle room when targeting a graphic. I went off that idea early on, and went to a more kludgy method, which is more my style. :wink:
with what I propose, you do not 'target' a control/graphic. The graphic itself fires this off on mouseEnter, so no targeting needed. You could actually make this a behaviour and apply to any number/kind of controls.


dunbarx wrote:
Thu May 25, 2023 4:23 pm
The dictionary says:
You can only grab a control when the mouse pointer is within the control's rectangle at the time the mouse is clicked.
Is this a literary bug? The grab command does seem to work if the pointer is a couple of pixels off the actual line, either side, but no more than about three. It certainly does not work within "...the control's rectangle..."
Not sure this is a bug - you 'grab' when you're over the control. You cannot 'grab' when you're click on the other side of the card. Unless I'm misunderstanding you?

In any case, I tested the above - the line highlights as needed and if you click and drag while highlighted it moves the line. Certainly much easier to grab a line (works in both pointer tool and browser tool) -- I may just implement this as standard as clicking a line can be a pain!

S.

-------------------------------------------
EDIT: with respect to using 'grab' on a line - this is a special case I suspect as a line does not have a rect, in theory at least, so LC invents one. I still wouldn't call this a bug though ;)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Moving a line...

Post by jacque » Thu May 25, 2023 8:56 pm

Another option. Use this as a behavior for every line. One advantage is that it should show the user which line is affected. You'll probably want to add an offset/delta so the line doesn't snap to the mouseloc.

Code: Select all

local sLineSize, sDragging

on mouseEnter
  put the linesize of me into sLineSize
  set the linesize of me to 5
end mouseEnter

on mouseMove
  if sDragging then
    set the loc of me to the mouseloc
  end if
end mouseMove

on mouseDown
  put true into sDragging
end mouseDown

on mouseUp
  resetLine
end mouseUp

on mouseLeave
  resetLine
end mouseLeave

on resetLine
  put false into sDragging
  set the linesize of me to sLineSize
end resetLine
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”