Drawing on the slate -- Behaviors

The interactors we have seen so far have only moved the pictures. What about changing their shape, and stuff like that? This functionality is provided not by the interactor, but by the picture itself.

Each picture has a configuration option called behavior. This option must be set to a command prefix on that object; the default is ``move.'' An interactor calls three ``action'' methods in the picture: click, drag, and release; all these methods do is append the behavior option, the action name, and (for the first two) the current coordinates.

For example, dragging some picture $picture might produce the sequence of calls:

$picture move click 100 100
$picture move drag 100 105
$picture move drag 102 109
$picture move release
The behavior option can be set to several other values. Firstly, the click mode always accepts the -ghost flag; to see the effect, let's change the behavior of the frame:
$frame configure -behavior {move -ghost}
Now try moving the frame (with the middle button). Another common behavior is deform. Try this:
$frame configure -behavior {deform ne}
In this case, the argument is the name of the aspect to be deformed. The deform operation will also accept the -ghost option.

Although this is sort-of cute, it's not really all that useful: usually, you have other pictures that act as grab handles -- grapples, I call them -- so that you can move the picture. Because of this, the shape classes provide their pictures with the necessary support for adding grab handles. All that is required is to ask the picture to create these handles:

$frame configure -behavior move
$frame grapple $follower
What I have done here is to a) change the behavior of the frame so that it will move (since the grapples are going to do the deforming) and b) asked it to create a set of grapples, using the follower interactor to move them.

To remove the grab handles, provide a null value as the argument:

$frame grapple {}
The grapple method accepts the -ghost flag. To move and deform the arrow with ghosting:
$arrow configure -behavior {move -ghost}
$arrow grapple $follower -ghost
Try grappling other pictures with different interactors.

Next