custombutton.lzx
<library>
<resource name="transparent_button_rsc">
<frame src="resources/util/transparent.swf"/>
<frame src="resources/util/transparent.swf"/>
<frame src="resources/util/transparent.swf"/>
</resource>
<resource name="custombutton_small_left_rsc">
<frame src="resources/button/small/sm_btn_up_lft.png"/>
<frame src="resources/button/small/sm_btn_mo_lft.png"/>
<frame src="resources/button/small/sm_btn_dn_lft.png"/>
<frame src="resources/button/small/sm_btn_dsbl_lft.swf"/>
</resource>
<resource name="custombutton_small_right_rsc">
<frame src="resources/button/small/sm_btn_up_rt.png"/>
<frame src="resources/button/small/sm_btn_mo_rt.png"/>
<frame src="resources/button/small/sm_btn_dn_rt.png"/>
<frame src="resources/button/small/sm_btn_dsbl_rt.swf"/>
</resource>
<resource name="custombutton_small_middle_rsc">
<frame src="resources/button/small/sm_btn_up_mid.swf"/>
<frame src="resources/button/small/sm_btn_mo_mid.swf"/>
<frame src="resources/button/small/sm_btn_dn_mid.swf"/>
<frame src="resources/button/small/sm_btn_dsbl_mid.swf"/>
</resource>
<include href="base/basebutton.lzx"/>
<class name="custombutton" extends="basebutton" focusable="true" resourceviewcount="3" doesenter="true" styleable="true" height="18" fontsize="10">
<attribute name="text" value="
" type="html"/>
<attribute name="texty" value="0
"/>
<attribute name="iconname" value="
" type="string"/>
<attribute name="icony" value="null
"/>
<attribute name="iconspace" value="2
"/>
<attribute name="iconstretches" value="none
" type="string"/>
<attribute name="expandedWidth" value="$once{this.width}"/>
<attribute name="collapsedWidth" value="30
"/>
<attribute name="leftrsc" value="custombutton_small_left_rsc
" type="string"/>
<attribute name="middlersc" value="custombutton_small_middle_rsc
" type="string"/>
<attribute name="rightrsc" value="custombutton_small_right_rsc
" type="string"/>
<view name="left" resource="transparent_button_rsc" height="${parent.height}" x="0" stretches="height" visible="$once{classroot.leftrsc != ''}"/>
<view name="middle" resource="transparent_button_rsc" height="${parent.height}" x="${parent.left.width}" width="${parent.width-parent.left.width-parent.right.width}" stretches="both"/>
<view name="right" resource="transparent_button_rsc" height="${parent.height}" x="${parent.width-width}" stretches="height" visible="$once{classroot.rightrsc != ''}"/>
<view name="content" x="${Math.round((parent.width - width) / 2)}" height="${parent.height}">
<simplelayout name="contentlayout" axis="x" spacing="$once{classroot.iconspace}"/>
<view name="icon" x="0" y="${classroot.icony != null ? classroot.icony: Math.round((classroot.height - height )/2) }" resource="$once{classroot.iconname ? classroot.iconname + '_icon_rsc' : ''}" visible="$once{classroot.iconname != ''}" opacity="${classroot.enabled?1:0.4}">
<method name="init">
super.init();
if (classroot.iconstretches != "none")
{
this.setAttribute("stretches", classroot.iconstretches);
// scale the resource proportionally to the view height
this.setAttribute('width', Math.round(this.resourcewidth*height*1.0/this.resourceheight) );
}
// FIXME: [gse 2006-02-06] for some reason play="false" causes a hard loop on startup
// See http://www.openlaszlo.org/jira/browse/LPP-1577
this.stop(0);
</method>
</view>
<text name="txt" resize="true" text="${classroot.text}" visible="${this.text != ''}" y="${classroot.texty}" height="${parent.height}"/>
</view>
<method name="init">
super.init();
if ( leftrsc != "" )
{
// set resource. also need to set tint again.
this.left.setAttribute('resource', leftrsc);
if (this.style != null && this.style.basecolor != null)
this.setTint(this.left, this.style.basecolor);
}
if ( middlersc != "" )
{
this.middle.setAttribute('resource', middlersc);
this.setTint(this.middle, this.style.basecolor);
}
if ( rightrsc != "" )
{
this.right.setAttribute('resource', rightrsc);
this.setTint(this.right, this.style.basecolor);
}
</method>
<method name="doEnterDown">
if ( this._enabled) {
this.doShowDown();
}
</method>
<method name="doEnterUp">
if ( this._enabled) {
this.onclick.sendEvent();
this.doShowUp();
}
</method>
<method name="doShowOver">
super.showOver();
if (this.content.txt.visible)
this.content.txt.setAttribute('fgcolor', this.enabled ? this.style.texthilitecolor : this.style.textdisabledcolor );
</method>
<method name="doShowUp">
super.showUp();
if (this.content.txt.visible)
this.content.txt.setAttribute('fgcolor', this.enabled ? this.style.textcolor : this.style.textdisabledcolor );
</method>
<method name="doShowDown">
super.showDown();
if (this.content.txt.visible)
this.content.txt.setAttribute('fgcolor', this.enabled ? this.style.textselectedcolor : this.style.textdisabledcolor );
</method>
<method name="_applystyle" args="s">
if (s != null) {
// super._applystyle(s);
this.setTint(this.left, s.basecolor);
this.setTint(this.middle, s.basecolor);
this.setTint(this.right, s.basecolor);
var tc = s.textcolor*1;
//Debug.write("Button style .. s.textcolor,tc",s.textcolor, tc);
//this.content.txt.setAttribute("fgcolor", this.enabled ? tc : s.textdisabledcolor);
if (s['font']) this.content.txt.setAttribute("font", s.font);
if (s['fontsize']) this.content.txt.setAttribute("fontsize", s.fontsize);
}
</method>
<method name="iconPlay">
this.content.icon.play();
</method>
<method name="iconStop">
this.content.icon.stop(0);
</method>
</class>
</library>
Cross References
Includes
Resources
Classes