12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // 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<bool()> query) {
- _query = query;
- }
- void SwitchBtn::setCallbackWhileSwitched(std::function<void(bool)> 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
|