KKGLabelButton.h
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
//  KKGLabelButton.h
//  SteveAndMaggieWorld
//
//  Created by Katarzyna Kalinowska-Górska on 08/12/2021.
//
#ifndef KKGLabelButton_h
#define KKGLabelButton_h
#include "ui/CocosGUI.h"
#include "cocos2d.h"
class KKGLabelButton : public cocos2d::ui::Button {
public:
    
    struct ButtonActionData {
        std::function<void()> onTouchBegan;
        std::function<void()> onTouchEnded;
        std::function<void()> onTouchCancelled;
    };
    
    static KKGLabelButton* create(const std::string& backgroundPath,
                                  const std::string& text,
                                  const std::string& fontFile,
                                  float fontSize,
                                  const cocos2d::Color4B& textColor
                                  );
    virtual bool init(const std::string& backgroundPath,
                      const std::string& text,
                      const std::string& fontFile,
                      float fontSize,
                      const cocos2d::Color4B& textColor);
// ui and interaction
    virtual void setOnTouchBeganCallback(std::function<void(KKGLabelButton*, cocos2d::ui::Widget::TouchEventType)> callback);
    virtual void setOnTouchEndedCallback(std::function<void(KKGLabelButton*, cocos2d::ui::Widget::TouchEventType)> callback);
    virtual void setOnTouchCancelledCallback(std::function<void(KKGLabelButton*, cocos2d::ui::Widget::TouchEventType)> callback);
    virtual void setOriginalScale(float scale);
    virtual float getOriginalScale();
    virtual void imitateTouchDown();
    virtual void imitateTouchUp();
    
    virtual cocos2d::Label* getLabel() { return m_textLabel; }
    
protected:
    
    // ui and interaction
    float _originalScale;
    bool _adjustScaleOnPress;
    std::function<void(KKGLabelButton*, cocos2d::ui::Widget::TouchEventType)> _touchBeganCallback;
    std::function<void(KKGLabelButton*, cocos2d::ui::Widget::TouchEventType)> _touchEndedCallback;
    std::function<void(KKGLabelButton*, cocos2d::ui::Widget::TouchEventType)> _touchCancelledCallback;
    ButtonActionData _buttonOwnTouchBehaviour;
    cocos2d::Label* m_textLabel { nullptr };
    
    virtual void configureTouchListeners();
};
#endif /* KKGLabelButton_h */
