34 #ifndef __CU_TOUCHSCREEN_H__
35 #define __CU_TOUCHSCREEN_H__
38 #include <cugl/math/CURect.h>
43 #define CU_INVALID_TOUCH -1
48 typedef Sint64 TouchID;
78 touch = finger; position = point; pressure = force; timestamp = stamp;
122 #pragma mark Listeners
183 typedef std::function<void(const TouchEvent& event, const Vec2& previous, bool focus)>
MotionListener;
198 #pragma mark Constructors
217 virtual void dispose()
override;
219 #pragma mark Data Polling
232 return _current.find(touch) != _current.end();
243 return (_current.find(touch) != _current.end() &&
244 _previous.find(touch) == _previous.end());
259 return (_current.find(touch) == _current.end() &&
260 _previous.find(touch) != _previous.end());
293 unsigned int touchCount()
const {
return (
unsigned int)_current.size(); }
300 const std::vector<TouchID>
touchSet()
const;
302 #pragma mark Listeners
455 #pragma mark Input Device
487 virtual void queryEvents(std::vector<Uint32>& eventset)
override;
Touchscreen()
Definition: CUTouchscreen.h:205
std::unordered_map< Uint32, MotionListener > _moveListeners
Definition: CUTouchscreen.h:196
virtual void clearState() override
bool addEndListener(Uint32 key, ContactListener listener)
virtual ~Touchscreen()
Definition: CUTouchscreen.h:210
Vec2 touchOffset(TouchID touch) const
bool isListener(Uint32 key) const
Definition: CUTimestamp.h:61
bool removeBeginListener(Uint32 key)
std::unordered_map< TouchID, Vec2 > _previous
Definition: CUTouchscreen.h:187
bool addMotionListener(Uint32 key, MotionListener listener)
Definition: CUTouchscreen.h:53
TouchEvent()
Definition: CUTouchscreen.h:67
float pressure
Definition: CUTouchscreen.h:62
std::function< void(const TouchEvent &event, bool focus)> ContactListener
Definition: CUTouchscreen.h:151
TouchID touch
Definition: CUTouchscreen.h:58
const std::vector< TouchID > touchSet() const
virtual void queryEvents(std::vector< Uint32 > &eventset) override
const ContactListener getEndListener(Uint32 key) const
virtual bool requestFocus(Uint32 key) override
virtual bool updateState(const SDL_Event &event, const Timestamp &stamp) override
Definition: CUTouchscreen.h:120
virtual void dispose() override
bool touchReleased(TouchID touch)
Definition: CUTouchscreen.h:258
const MotionListener getMotionListener(Uint32 key) const
Timestamp timestamp
Definition: CUTouchscreen.h:56
const ContactListener getBeginListener(Uint32 key) const
bool removeEndListener(Uint32 key)
std::function< void(const TouchEvent &event, const Vec2 &previous, bool focus)> MotionListener
Definition: CUTouchscreen.h:183
TouchEvent(TouchID finger, const Vec2 &point, float force, const Timestamp &stamp)
Definition: CUTouchscreen.h:77
std::unordered_map< TouchID, Vec2 > _current
Definition: CUTouchscreen.h:189
Definition: CUAction.h:51
Vec2 position
Definition: CUTouchscreen.h:60
bool removeMotionListener(Uint32 key)
bool touchPressed(TouchID touch) const
Definition: CUTouchscreen.h:242
Vec2 touchPosition(TouchID touch) const
std::unordered_map< Uint32, ContactListener > _finishListeners
Definition: CUTouchscreen.h:194
bool addBeginListener(Uint32 key, ContactListener listener)
unsigned int touchCount() const
Definition: CUTouchscreen.h:293
std::unordered_map< Uint32, ContactListener > _beginListeners
Definition: CUTouchscreen.h:192
bool touchDown(TouchID touch) const
Definition: CUTouchscreen.h:231