tooltipview.lzx
<library>
<resource name="tooltip_ptr_rsc">
<frame src="resources/tooltip_pointer_up.png"/>
<frame src="resources/tooltip_pointer_dn.png"/>
</resource>
<view name="tooltipview" options="ignorelayout" id="tp" bgcolor="0x252525" width="${tiptext.width + 6}" height="17" visible="false">
<view bgcolor="black" opacity=".3" x="${parent.width}" y="2" width="2" height="15"/>
<view bgcolor="black" opacity=".3" x="2" y="${parent.height}" width="100%" height="2"/>
<view bgcolor="0xFAFECD" x="1" y="1" width="${parent.width - 2}" height="${parent.height - 2}"/>
<view name="pointer" resource="tooltip_ptr_rsc"/>
<text x="3" name="tiptext" fgcolor="0x1D1D1D" fontsize="10" resize="true">test</text>
<attribute name="checkdel" value="null
"/>
<attribute name="outdel" value="null
"/>
<attribute name="clickdel" value="null
"/>
<attribute name="lastmousex" value="0
"/>
<attribute name="lastmousey" value="0
"/>
<attribute name="tooltip" value="null
"/>
<setter name="tooltip" args="tt">
if ( !isinited ) return;
this.tooltip = tt;
if (tt) {
this.lastmousex = canvas.getMouse('x');
this.lastmousey = canvas.getMouse('y');
if (!this.checkdel) this.checkdel = new lz.Delegate(this, "checkTip");
// Come back in 500ms to see if the mouse is still in the same place
lz.Timer.resetTimer(this.checkdel, 500);
}
</setter>
<method name="checkTip" args="ignore">
var tt = this.tooltip;
if (tt) {
var newmousex = canvas.getMouse('x');
var newmousey = canvas.getMouse('y');
// See if the mouse has not moved
if ((this.lastmousex == newmousex) &&
(this.lastmousey == newmousey)) {
// It has not, show the tooltip
this.showTip();
} else {
// If the mouse is still in the tooltip parent view,
// try again later, otherwise, just stop
var ttp = tt.parent;
if (ttp.containsPt(ttp.getMouse('x'), ttp.getMouse('y'))) {
this.lastmousex = newmousex;
this.lastmousey = newmousey;
lz.Timer.resetTimer(this.checkdel, 500);
}
}
}
</method>
<method name="checkOut" args="ignore">
var tt = this.tooltip;
if (tt) {
var ttp = tt.parent;
if (ttp.containsPt(ttp.getMouse('x'), ttp.getMouse('y'))) {
return;
}
this.hideTip();
}
</method>
<method name="hideTip" args="ignore=null">
// Cancel any mousein event handler
if (this.checkdel) { this.checkdel.unregisterAll(); }
// Hide the tip
this.setAttribute('visible', false );
// Remove these handlers, they have done their job
if (this.outdel) { this.outdel.unregisterAll(); }
if (this.clickdel) { this.clickdel.unregisterAll(); }
</method>
<method name="showTip">
var tt = this.tooltip;
var ttp = tt.parent;
// Set up to hide...
if (! this.outdel) { this.outdel = new lz.Delegate(this, "checkOut"); }
this.outdel.register(lz.GlobalMouse, "onmousemove");
if (! this.clickdel) { this.clickdel = new lz.Delegate(this, "hideTip"); }
this.clickdel.register(ttp, "onclick");
tiptext.setAttribute('text', tt.text);
var tipx = canvas.width;
if ( tt.tipalign == 'right' ) {
tipx = ttp.getAttributeRelative( 'x', canvas ) + ttp.width;
}
tipx = Math.min(tipx - this.width - 10, this.lastmousex - 5);
var yoff = tt.yoffset;
var tipy = this.lastmousey + yoff;
var pointerontop;
switch (tt.tipvalign) {
case "above":
tipy = this.lastmousey - yoff;
pointerontop = false;
break;
case "below":
tipy = this.lastmousey + yoff;
pointerontop = true;
break;
default:
if (tipy > canvas.height - (yoff + 5)) {
tipy = this.lastmousey - yoff;
pointerontop = false;
} else {
tipy = this.lastmousey + yoff;
pointerontop = true;
}
}
this.setAttribute('x', tipx );
this.setAttribute('y', tipy );
this.setPointerX( this.lastmousex, pointerontop );
this.bringToFront( );
this.setAttribute('visible', true );
</method>
<method name="setPointerX" args="mx, isontop ">
var nx = Math.min( mx - x, width - 12)
var tp = this.pointer;
tp.setAttribute('x', nx );
if ( isontop ) {
tp.setAttribute( 'frame', 1 );
tp.setAttribute('y', 1 - tp.height);
} else {
tp.setAttribute( 'frame', 2 );
tp.setAttribute('y', height - 1);
}
</method>
</view>
</library>
Cross References
Resources
Named Instances