Login  Register

Re: changing the default behavior of a morph

Posted by Robert Krahn-4 on Feb 19, 2014; 6:04am
URL: https://forum.world.st/changing-the-default-behavior-of-a-morph-tp4744703p4744769.html

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