Cornell Cocos
Cornell Extensions to Cocos2d
CUMultiTouchListener.h
1 //
2 // CUMultiTouchListener.h
3 // Cornell Extensions to Cocos2D
4 //
5 // Module provides a time sensitive listener for the touch input. This class simplifies
6 // a lot of the overhead for EventListenerTouchAllAtOnce. More importantly, it adds a
7 // timestamp to all of the callback functions so that the user can precisely time the
8 // callbacks.
9 //
10 // Author: Walker White
11 // Version: 12/5/15
12 //
13 #ifndef __CU_MULTITOUCH_LISTENER_H__
14 #define __CU_MULTITOUCH_LISTENER_H__
15 
16 #include <cocos2d.h>
17 #include "CUTimestamp.h"
18 
19 NS_CC_BEGIN
20 
21 #pragma mark -
22 #pragma mark Touch Listener
23 
39 class MultiTouchListener : public Ref {
40 private:
42  CC_DISALLOW_COPY_AND_ASSIGN(MultiTouchListener);
43 
44 protected:
46  EventDispatcher* _dispatcher;
48  EventListenerTouchAllAtOnce* _touchListener;
50  bool _active;
51 
52 
53 public:
54 #pragma mark Static Constructors
55 
61  static MultiTouchListener* create();
62 
71  static MultiTouchListener* create(EventDispatcher* dispatcher);
72 
73 
74 #pragma mark Event Handling
75 
82  void start(int priority);
83 
91  void start(Node* node);
92 
96  void stop();
97 
103  bool isActive() const { return _active; }
104 
113  std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> onTouchesBegan;
114 
124  std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> onTouchesMoved;
125 
132  std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> onTouchesEnded;
133 
143  std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> onTouchesCancelled;
144 
145 
146 #pragma mark Initializers
147 CC_CONSTRUCTOR_ACCESS:
151  MultiTouchListener() : _active(false) {}
152 
156  virtual ~MultiTouchListener();
157 
163  bool init() { return init(Director::getInstance()->getEventDispatcher()); }
164 
173  bool init(EventDispatcher* dispatcher);
174 
175 };
176 
177 NS_CC_END
178 #endif /* defined(__CU_MULTITOUCH_LISTENER_H__) */
bool _active
Definition: CUMultiTouchListener.h:50
std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesEnded
Definition: CUMultiTouchListener.h:132
EventListenerTouchAllAtOnce * _touchListener
Definition: CUMultiTouchListener.h:48
bool init()
Definition: CUMultiTouchListener.h:163
bool isActive() const
Definition: CUMultiTouchListener.h:103
void stop()
Definition: CUMultiTouchListener.cpp:86
EventDispatcher * _dispatcher
Definition: CUMultiTouchListener.h:46
std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesMoved
Definition: CUMultiTouchListener.h:124
Definition: CUMultiTouchListener.h:39
std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesBegan
Definition: CUMultiTouchListener.h:113
void start(int priority)
Definition: CUMultiTouchListener.cpp:64
static MultiTouchListener * create()
Definition: CUMultiTouchListener.cpp:26
std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesCancelled
Definition: CUMultiTouchListener.h:143