changing the default behavior of a morph

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

changing the default behavior of a morph

Rick McGeer
Quick question.  For left-click on a morph, the default behavior is Grab.  How do I change it to Transform ("T" on the Halo menu)?  After a half-hour of mousing around in an Inspector I got lost, and realized that the simplest thing to do is ask....I assume that it's simply setting the right event handler for the MouseDown event...

Thanks
Rick

_______________________________________________
lively-kernel mailing list
[hidden email]
http://lists.hpi.uni-potsdam.de/listinfo/lively-kernel
Reply | Threaded
Open this post in threaded view
|

Re: changing the default behavior of a morph

Robert Krahn-4
First, to disable the normal behavior the morph already provides an interface.
You can just call

morph.disableGrabbing();

to not pick up the morph when dragging on it.

Then, step 2, is to define the behavior of what to do instead. You can
overwrite the normal drag logic. First make sure dragging is enabled:

morph.enableDragging();

There are three dragging-related event handlers:

onDragStart
onDrag
onDragEnd

You need to implement the first two:

morph.addScript(function onDrag(evt) {
    var globalPosition = this.worldPoint(pt(0,0)),
        nowHandAngle = evt.getPosition().subPt(globalPosition).theta(),
        newRotation = this.startRotation + (nowHandAngle - this.startHandAngle);
    this.setRotation(newRotation);
});

morph.addScript(function onDragStart(evt) {
    var globalPosition = this.worldPoint(pt(0,0));
    this.startRotation = this.getRotation();
    this.startHandAngle = evt.getPosition().subPt(globalPosition).theta();
});

To make sure to rotate the center of the morph you probably want to set the
origin itself. You can do this when the morphs shows its halos by clicking and
dragging the little red dot around or programatically via

morph.setOrigin(morph.innerBounds().center())

_______________________________________________
lively-kernel mailing list
[hidden email]
http://lists.hpi.uni-potsdam.de/listinfo/lively-kernel