Drawing a Line Graphic

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

Post Reply
Xero
Posts: 152
Joined: Sat Jun 23, 2018 2:22 pm

Drawing a Line Graphic

Post by Xero » Wed Jul 04, 2018 2:23 pm

OK...
I feel a little stupid asking this...
I am trying to write a part of an app that draws a line on the card.
It should be simple, and there should be a thousand examples/ tutorials about it, but damned if I can find one!!!
Here's what I want to do:
Click on screen and hold down mouse, start drawing a line, move the mouse to a new location on screen, release mouse button and finish drawing the line.
Simples!
Damned if I can get the right handlers.
script should look something like this:

global tPointsList
on mousedown
put the mouseloc into tPointsList --find the startpoint
end mousedown
on mouseup
put the mouseloc after tPointsList --find the endpoint
set the points of graphic "Line01" to tPointsList --draw the line between startpoint and endpoint
end mouseup

There's obviously more to do to create the line, give it properties etc. but I have found and trested that script...
I gather that mousedown, mouseup doesn't work because I'm mixing/ splitting handlers etc.
DragStart, DragEnd doesn't work because that's a drag and drop thing.
I would be happy with some way of clicking and entering mouseloc into list, then clicking again, and adding to list, but can't work out how to track multiple mouse clicks.

Surely there's an easy way of doing this...

Assistance please?

XdM

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Drawing a Line Graphic

Post by Klaus » Wed Jul 04, 2018 2:53 pm

Hi Xero,

"the points of grc XYZ" is a CR delimited list of a pairs of numbers!
If in doubt, ALWAYS consult the dictionary! 8)

So this will do the trick, you need to already have a graphic name "Line01" on your card!
Put this into the crad script:

Code: Select all

## No need for a GLOBAL, LOCAL will do!
local tPointsList
on mousedown
   put the mouseloc into tPointsList --find the startpoint
end mousedown

on mouseup
   ## See above!
   put CR & the mouseloc after tPointsList --find the endpoint
   set the points of graphic "Line01" to tPointsList --draw the line between startpoint and endpoint
end mouseup
Tested and works!


Best

Klaus

Xero
Posts: 152
Joined: Sat Jun 23, 2018 2:22 pm

Re: Drawing a Line Graphic

Post by Xero » Wed Jul 04, 2018 3:07 pm

You're some sort of magickian Klaus.
I am sure I had something like that, but it wasn't working!!!
The dictionary is extremely difficult to use if you don't know exactly what you are looking for, and tutorials/ examples are the same... That's what's driving me insane...
I knew I had to create a list with the points in it and then assign that list to an object, but was having issues with the CR getting it on to second line...
I might write a tutorial on it and leave it here for others...
Thanks again.
You're a Godsend Klaus!
XdM

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Drawing a Line Graphic

Post by Klaus » Wed Jul 04, 2018 3:18 pm

Hi Xero,

you're welcome!

For further worshipping etc. please use this thread:
http://forums.livecode.com/viewtopic.php?f=5&t=31001
:D

Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”