#include #include displayitem str = null; persist(str); boolean value = false; persist(value); /******************************************************************** * dimensions */ #define MAR 8 float minwidth() { return preferredwidth(); } float minheight() { return preferredheight(); } float preferredwidth() { float W; gsave(); setfont(textfont); W = DIWidth(str) + MAR*2; grestore(); return preferredwidth = W; } float preferredheight() { return fontheight(textfont) + MAR; } /******************************************************************** * Action */ void action() { preview(); softpromote(/value,!value); Send Action(DIString(str),value); } void preview() { Send Preview(value); } /******************************************************************** * Painting */ void PaintLabel(displayitem str) { setfont(textfont); setcolor(FG); if (justification == /Centered) DIPaintCentered(str,MAR,2,w - MAR*2,OLButtonH-4); else DIPaintLeft(str,MAR,2,w - MAR*2,OLButtonH-4); } void PaintButton(boolean down) { setcolor((down ? !value : value) ? FG : BG); rectpath(0,0,w,h); fill(); setcolor(FG); rectpath(insetstroke(0,[0,0,w,h])); stroke(); PaintLabel(str); } /******************************************************************** * change parameters */ void setlabel(displayitem s) { unpromote(/preferredwidth); str = s; gexec(/Paint); } void setvalue(boolean val) { if (val != value) { softpromote(/value,val); gexec(/Paint); preview(); } } void flipvalue() { softpromote(/value,!value); gexec(/Paint); preview(); }