// // MySwitchBtn.cpp // CandyCpp // // Created by 杜家兑macbook on 16/8/23. // // #include "RUSwitchBtn.h" NS_RU_BEGIN SwitchBtn::SwitchBtn() { } SwitchBtn::~SwitchBtn() { } void SwitchBtn::setQueryFunc(std::function query) { _query = query; } void SwitchBtn::setCallbackWhileSwitched(std::function cb) { _cbWhileSwitched = cb; } void SwitchBtn::onEnter() { if (_query()) { playAnim("in_on"); _tapTL = "tap_off"; _releaseTL = "release_off"; } else { playAnim("in_off"); _tapTL = "tap_on"; _releaseTL = "release_on"; } coreClickButton = CC_CALLBACK_2(SwitchBtn::onClicked, this); QCoreLayer::onEnter(); } void SwitchBtn::onClicked(QCoreBtn* cl, int tag) { scheduleOnce([=](float) { if (_query()) { _cbWhileSwitched(false); _tapTL = "tap_on"; _releaseTL = "release_on"; } else { _cbWhileSwitched(true); _tapTL = "tap_off"; _releaseTL = "release_off"; } }, 0.05f, "SCH_Switched"); ResetButton(); } #pragma mark - NS_RU_END