[lively-kernel] changing the default behavior of a morph

Robert Krahn robert.krahn at gmail.com
Wed Feb 19 07:04:04 CET 2014


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())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hpi.uni-potsdam.de/archive/lively-kernel/attachments/20140218/a9709f85/attachment.html>


More information about the lively-kernel mailing list