draglib.lzx
<library>
<class name="checkdragstate" extends="state">
<attribute name="draggername" value="dragimage
" type="string"/>
<attribute name="starty" value="$once{this.y}"/>
<attribute name="startx" value="$once{this.x}"/>
<attribute name="ydoffset" value="this.getMouse( 'y' )
" when="once"/>
<attribute name="xdoffset" value="this.getMouse( 'x' )
" when="once"/>
<attribute name="ydrag" value="${checkDragPos('y', this.immediateparent.getMouse( 'y' ))}"/>
<attribute name="xdrag" value="${checkDragPos('x', this.immediateparent.getMouse( 'x' ))}"/>
<attribute name="dragging" value="false
"/>
<attribute name="firsttime" value="true
"/>
<method name="checkDragPos" args="xory, mousepos">
if (this.firsttime) {
xdrag = this.x; ydrag = this.y;
this.firsttime = false;
}
var newpos = mousepos - this[xory + 'doffset'];
var diff = this[xory + 'drag'] - this['start' + xory];
if (Math.abs(diff) > 5 && !this.dragging) {
canvas[draggername].startdrag(this, xdoffset, ydoffset);
this.dragging = true;
}
return newpos;
</method>
</class>
<class name="basedragimage" options="ignorelayout" visible="false">
<attribute name="dropgroup" value="droptarget
" type="string"/>
<attribute name="source" value="null
"/>
<attribute name="startx" value="0
" type="number"/>
<attribute name="starty" value="0
" type="number"/>
<attribute name="dropped" value="false
"/>
<attribute name="xdoffset" value="null
"/>
<attribute name="ydoffset" value="null
"/>
<attribute name="_onstopdel" value="null
"/>
<method name="startdrag" args="src, xoffset, yoffset">
this.startx = src.getAttributeRelative('x', canvas);
this.starty = src.getAttributeRelative('y', canvas);
this.setAttribute('x', this.startx);
this.setAttribute('y', this.starty);
this.bringToFront();
this.setAttribute('visible', true);
this.source = src;
this.dropped = false;
// set up the offset from the source mouse offset
if (this.xdoffset == null) this.xdoffset = xoffset;
if (this.ydoffset == null) this.ydoffset = yoffset;
ds.setAttribute('applied', true);
lz.Track.activate(this.dropgroup);
</method>
<method name="stopdrag" args="ignore=null">
if (dropped) {
this.setAttribute('visible', false);
} else {
var anm = this.animate('x', startx, 200);
this.animate('y', starty, 200);
if ( !this._onstopdel ) this._onstopdel = new lz.Delegate( this, 'hideme' );
this._onstopdel.register( anm, 'onstop' );
}
ds.setAttribute('applied', false);
lz.Track.deactivate(this.dropgroup);
</method>
<method name="hideme" args="ignore=null">
setAttribute('visible', false);
</method>
<method name="dropcomplete" args="source">
this.dropped = true;
</method>
<state name="ds">
<attribute name="y" value="${this.immediateparent.getMouse( 'y' ) - this.ydoffset}"/>
<attribute name="x" value="${this.immediateparent.getMouse( 'x' ) - this.xdoffset}"/>
</state>
</class>
</library>