HTwoStateButton.h 1.32 KB
//
//  HTwoStateButton.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 25.06.2017.
//
//

#ifndef HTwoStateButton_h
#define HTwoStateButton_h

#include "HalloweenSimpleButton.h"

class HTwoStateButton : public HalloweenSimpleButton
{
    public:
        static HTwoStateButton* create(const std::string& inactiveImagePath, const std::string& activeImagePath);
        bool init(const std::string& inactiveImagePath, const std::string& activeImagePath);
//        virtual void onEnter() override;
    
        bool isActive() {
            return _active;
        };
        void setActive(bool active);
    
        void setOnStateChangedCallback(std::function<void(bool state)> onStateChangedCallback){
            _onStateChangedCallback = onStateChangedCallback;
        };
    
        bool switchStates(){
            _active = !_active;
            return _active;
        };
    
        void addChild(cocos2d::Node* child) override;
    
    protected:
        bool _active;
        std::function<void(bool state)> _onStateChangedCallback;
        std::string _inactiveBgImagePath;
        std::string _activeBgImagePath;
        cocos2d::Sprite* _activeSprite;
        cocos2d::Sprite* _inactiveSprite;
    
        void configureTouchListeners() override;
        void adjustTextures();
};

#endif /* HTwoStateButton_h */