Dragging objects around on canvas

Over the years, I’ve had a few ideas about some graphic programming projects that would involve ‘Draw’ -like features. Specifically, the ability to select some graphic object on a canvas, and then drag it to a new position, as in a Draw program. I can envisage the amount of work involved in doing it properly (a lot of work), but there could possibly be some simplifications to make things a bit easier at the expense of less functionality. Just wondering if anyone’s done anything like this, and if they have interesting advice to offer.

It actually is not difficult at all… over the years I have written (in RealBasic/Studio/Xojo), a MSPaint clone, a Visio like clone, and a iOS interface creator (similar in looks to what ‘Xojo for iOS’ does)… all of which entail exactly the type of thing you are talking about.

For the most part (with the exception of the MSPaint clone), each “object” is a class, which has properties that describe its shape, position, color etc, and a single canvas to display them all on.

If you click the mouse on the canvas within the bounds described by an object, you have “selected” that object, if you drag the mouse you simply alter the position properties of the object, and instruct the object to remove itself from its old postion, and redraw itself at the new postion (done right, you can handle hundreds of on screen objects at more than adequate frame rates)

This of course is a very high level description of one possible way to solve this kind of problem, and it would be up to you to decide if it might work for your situation, and how best to implement it.

Take a look at the CanvasDrawDrag example project that comes with Xojo.

@Dave S
Thanks for the encouraging comments. I guess that I sometimes assume things are going to be more difficult than they really are.

FYI, what prompted this discussion, is that I’m in the process of producing some documents that include various graphics objects—mostly X-Y graphs—created in LibreOffice. LibreOffice is pretty good for creating basic charts, but the bells and whistles take a lot of extra work. I need to add a few text annotations to them here and there. It would be nice to have a Xojo application where I could import the basic graphic and then add bits of text to it, slide them around as necessary and then export the whole thing to the final document. But if I’m going to do something like a draw program, I’d like to make things general enough that I could apply it to possible future projects that may be a bit more involved.

Thanks Tim. I’ll check it out.

Hi Robert,

Another option is there is a book on the Canvas that explains a way to setup dragging and dropping objects. Its available here: Canvas Book . Definitely try the resources that Tim and Dave mentioned.

I’ve had a look at this example now, and I think it should give me about 90% of what I need. Thanks.