When we use the Cocostudio tool, there are three states for Button control buttons, and we can set different pictures for three states individually. The method is then displayed in the program as a different state. 1. Initial state: normal state bool Widget::init () {if (Ccnode::init ()) {setbright (true); } return false;} 2,/*button Switch to disable state (forbidden State), _bright default is True, you can call Setbright (false) To switch button to disable state. */void widget::setbright (bool bright) {_bright = bright; if (_bright) {_brightstyle = Bright_none; Setbrightstyle (Bright_normal); } else {onpressstatechangedtodisabled (); }}3 、--Switch to the pressed state, i.e. press the status void widget::setfocused (bool fucos) {if (Fucos = = _focus) {return; } _focus = Fucos; if (_bright)//default is True {if (_focus) {///If True, Setbrightstyle function is called, Final call//onpressstatechangedtop The ressed method switches to the pressed state. Setbrightstyle (Bright_highlight); } else {Setbrightstyle (bright_normal); }} else {///if _bright is false, switch directly to the disabled state onpressstatechangedtodisabled (); }}void Widget::seTbrightstyle (Brightstyle style) {if (_brightstyle = = style) {return; } _brightstyle = style; Switch (_brightstyle) {case bright_normal:onpressstatechangedtonormal (); Break Case bright_highlight:onpressstatechangedtopressed (); Break Default:break; }}
Cocostudio:button Three state transitions