HalloweenSimpleButton.h 2.05 KB
//
//  HalloweenSimpleButton.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
//
//

#ifndef HalloweenSimpleButton_h
#define HalloweenSimpleButton_h

#include "HLayoutObject.h"
#include "ui/CocosGUI.h"

class HalloweenSimpleButton : public cocos2d::ui::Button, public HLayoutObject
{
    public:
    
        struct ButtonActionData {
            std::function<void()> onTouchBegan;
            std::function<void()> onTouchEnded;
            std::function<void()> onTouchCancelled;
        };
    
        static HalloweenSimpleButton* create();
    
        virtual bool init() override;
    
        virtual void loadPropertiesFromJSON(const rapidjson::Value& jsonValue, HLayoutViewInterface* scene = NULL, const std::string resFolder = "", const std::string altResFolder = "") override;
        virtual void prepareSize(const rapidjson::Value& jsonValue, float& width, float& height) override;
        virtual bool isWidget() override;

        virtual void setOnTouchBeganCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback) override;
        virtual void setOnTouchEndedCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback) override;
        virtual void setOnTouchCancelledCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback) override;

        virtual void setOriginalScale(float scale);
        virtual float getOriginalScale();
    
        virtual void imitateTouchDown();
        virtual void imitateTouchUp();

    protected:
    
        float _originalScale;
        bool _adjustScaleOnPress;
        std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> _touchBeganCallback;
        std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> _touchEndedCallback;
        std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> _touchCancelledCallback;
        ButtonActionData _buttonOwnTouchBehaviour;
    
        virtual void configureTouchListeners();
};

#endif /* HalloweenSimpleButton_h */