34 #ifndef __CU_TOUCHSCREEN_H__
35 #define __CU_TOUCHSCREEN_H__
38 #include <cugl/math/CURect.h>
43 #define CU_INVALID_TOUCH -1
78 touch = finger; position = point; pressure = force; timestamp = stamp;
83 #pragma mark TouchListener
113 typedef std::function<void(const TouchEvent& event, bool focus)>
TouchListener;
116 #pragma mark TouchMotionListener
148 typedef std::function<void(const TouchEvent& event, const Vec2& previous, bool focus)>
TouchMotionListener;
219 virtual void dispose()
override;
221 #pragma mark Data Polling
234 return _current.find(touch) != _current.end();
245 return (_current.find(touch) != _current.end() &&
246 _previous.find(touch) == _previous.end());
261 return (_current.find(touch) == _current.end() &&
262 _previous.find(touch) != _previous.end());
295 unsigned int touchCount()
const {
return (
unsigned int)_current.size(); }
302 const std::vector<TouchID>
touchSet()
const;
304 #pragma mark Listeners
457 #pragma mark Input Device
489 virtual void queryEvents(std::vector<Uint32>& eventset)
override;
std::function< void(const TouchEvent &event, bool focus)> TouchListener
Definition: CUTouchscreen.h:113
Touchscreen()
Definition: CUTouchscreen.h:207
virtual void clearState() override
std::unordered_map< Uint32, TouchListener > _beginListeners
Definition: CUTouchscreen.h:195
virtual ~Touchscreen()
Definition: CUTouchscreen.h:212
Vec2 touchOffset(TouchID touch) const
bool isListener(Uint32 key) const
const TouchMotionListener getMotionListener(Uint32 key) const
Definition: CUTimestamp.h:61
bool removeBeginListener(Uint32 key)
std::unordered_map< TouchID, Vec2 > _previous
Definition: CUTouchscreen.h:190
const TouchListener getBeginListener(Uint32 key) const
Definition: CUTouchscreen.h:53
TouchEvent()
Definition: CUTouchscreen.h:67
std::function< void(const TouchEvent &event, const Vec2 &previous, bool focus)> TouchMotionListener
Definition: CUTouchscreen.h:148
float pressure
Definition: CUTouchscreen.h:62
const TouchListener getEndListener(Uint32 key) const
TouchID touch
Definition: CUTouchscreen.h:58
const std::vector< TouchID > touchSet() const
virtual void queryEvents(std::vector< Uint32 > &eventset) override
virtual bool requestFocus(Uint32 key) override
virtual bool updateState(const SDL_Event &event, const Timestamp &stamp) override
Definition: CUTouchscreen.h:187
Sint64 TouchID
Definition: CUTouchscreen.h:48
bool addEndListener(Uint32 key, TouchListener listener)
virtual void dispose() override
bool touchReleased(TouchID touch)
Definition: CUTouchscreen.h:260
Timestamp timestamp
Definition: CUTouchscreen.h:56
bool removeEndListener(Uint32 key)
bool addBeginListener(Uint32 key, TouchListener listener)
TouchEvent(TouchID finger, const Vec2 &point, float force, const Timestamp &stamp)
Definition: CUTouchscreen.h:77
std::unordered_map< TouchID, Vec2 > _current
Definition: CUTouchscreen.h:192
Definition: CUAnimationNode.h:52
Vec2 position
Definition: CUTouchscreen.h:60
bool removeMotionListener(Uint32 key)
bool touchPressed(TouchID touch) const
Definition: CUTouchscreen.h:244
Vec2 touchPosition(TouchID touch) const
unsigned int touchCount() const
Definition: CUTouchscreen.h:295
std::unordered_map< Uint32, TouchMotionListener > _moveListeners
Definition: CUTouchscreen.h:199
bool addMotionListener(Uint32 key, TouchMotionListener listener)
std::unordered_map< Uint32, TouchListener > _finishListeners
Definition: CUTouchscreen.h:197
bool touchDown(TouchID touch) const
Definition: CUTouchscreen.h:233