I’ve tried googling for this, but I’m not even sure what to call it. I’d like to do something similar to making connections in Interface Builder. That is, click and drag a line from an “anchor point” of one object to connect it to a second object. Is this something created from scratch with quartz or is the functionality within some class somewhere? Thanks in advance for any help.
I think someone else had asked about this recently. But it’s not a prebuilt “thing” you can use, it’s internal to XCode. You are going to have to write your own connection and drawing code for that.
That’s kind of what I was thinking. I just didn’t want to do all that work if there is already something pre-made :).
Well this has turned out to be a little harder than I thought it was going to be. I’ve finally got most of it worked out, but I’m stuck on one point. Here’s what I’ve got so far. I created a subclassed NSVew (myDrawngView) in the app’s main window. I’ve got myDrawingView using mouseDragged to draw a line from a click point to the moving cursor, and highlight rectangles are also drawn on myDrawingView when the cursor is over objects that can accept the end connection of the line.
Where I’m stuck at is how start the drawing of the connector line. What should happen is, like in interface builder, the user clicks down on an NSButtonCell in an NSTableView and then drags from there to create a line from the button to another object in the GUI. The problem is that the mouseDown on the button is used to tell the application to start drawing the connector line, but myDrawingView doesn’t see the mouseDown event so it doesn’t call mouseDragged which is where the drawing takes place.
I hope that make sense. Maybe I’m missing something obvious?? It seems like the mouseDown has to be "shared’ by the button cell and myDrawingView, or intercepted by the button cell and then passed on the the view??? I think maybe I need to have a better understanding of responders, but I’m not sure. Any help or pointers to guides for this would be greatly appreciated.
NSButtonCell is a subclass of NSCell; have a look at setContinuous: and sendActionOn:.
Thanks Shane. I’ll take a look.