Creating a line object for canvas draggable object

Hi,

I have a project where I can select different items that are images that then become draggable objects on the canvas. All is good with that. Now what I want to do is add the option to draw a line, maybe like line object in the IDE, then have the line become an image for a draggable object.

Ideally I would like to select the draw line option and then be able to draw it vertically or horizontally or diagonally at the length need. Then have it become a draggable object. It won’t need to be edited, that is be able to adjust the length once set.

I’m not sure on how to go about doing this.

Hope this makes sense.

Thanks.

Assuming you have a tool palette where the user would click a button to begin their line drawing:

  1. Store the coordinates of the location of MouseDown as the start (dragStart as Xojo.Point, for example) and set a flag to denote the current operation (self.isDragging = True)
  2. Store the coordinates of the location of the cursor and refresh in MouseDrag (dragCurrent as Xojo.Point, for example)
  3. Draw a line from the first set of coordinates to the second set of coordinates in the Paint event
if isDragging then
  g.DrawLine(dragStart.X, dragStart.Y, dragCurrent.X, dragCurrent.Y)
end if
  1. On MouseUp, create your new virtual Line object representing the sets of coordinates
if isDragging and currentTool = Tools.Line then
  myNewObject = new CanvasLineObject(dragStart, dragCurrent)
  allCanvasObjects.Add(myNewObject)
end if

This is all pseudocode to give you an idea of how to implement it. You won’t be able to just copy/paste.

2 Likes

yeah this gives me a starting point.

Thanks!