AniGestureRecognizer.h 3.08 KB
//
//  AniGestureRecognizer.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 19.05.2017.
//
//

#ifndef AniGestureRecognizer_h
#define AniGestureRecognizer_h

#include "cocos2d.h"

class AniGestureRecognizer : public cocos2d::Ref
{
    public:
    typedef enum AniGestureRecognizerDirection {
        NONE,
        UP,
        DOWN,
        LEFT,
        RIGHT
    };
        
        static AniGestureRecognizerDirection mapXToDirection(float x);
        static AniGestureRecognizerDirection mapYToDirection(float y);
    
        AniGestureRecognizer(std::vector<cocos2d::EventListener::Type> handledEvents);
        virtual ~AniGestureRecognizer();
    
        virtual void install(cocos2d::Node* view);
        virtual void uninstall();
        virtual void setEnabled(bool enabled){_enabled = enabled;}
        virtual bool isEnabled(){return _enabled;}
        virtual void changeTouchListenerPriorityToFixed(int newPriority);
        virtual void changeTouchListenerPriorityToSceneGraphPriority();
        virtual void setSwallowsTouches(bool swallowsTouches);
    
        typedef struct TouchData {
            int touchId;
            cocos2d::Point currentTouchLocation;
            cocos2d::Point previousTouchLocation;
            cocos2d::Point initialTouchLocation;
            
            TouchData(){
                touchId = -1;
            };
            
            TouchData(int pTouchID, cocos2d::Point pCurrentTouchLocation, cocos2d::Point pPreviousTouchLocation, cocos2d::Point pInitialTouchLocation){
                touchId = pTouchID;
                currentTouchLocation = pCurrentTouchLocation;
                previousTouchLocation = pPreviousTouchLocation;
                initialTouchLocation = pInitialTouchLocation;
            };
            
        } TouchData;
    
    protected:
        std::vector<cocos2d::EventListener::Type> _handledEvents;
        cocos2d::Node* _view;
        bool _enabled;
    
        std::vector<TouchData> _rememberedTouches;
        cocos2d::EventListener* _eventListener;
    
        virtual bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
        virtual void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
        virtual void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
        virtual bool onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
        virtual void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
        virtual void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
    
        virtual void saveTouches(std::vector<TouchData>& rememberedTouches, const std::vector<cocos2d::Touch*>& touches);
        virtual void updateTouches(std::vector<TouchData>& rememberedTouches, const std::vector<cocos2d::Touch*>& touches);
        virtual void filterTouches(std::vector<TouchData>& rememberedTouches, const std::vector<cocos2d::Touch*>& touches);
        virtual cocos2d::Touch* findTouchWithID(const std::vector<cocos2d::Touch*>& touches, int touchId);
    
};


#endif /* AniGestureRecognizer_h */