2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CC_TOUCH_H__
|
|
|
|
#define __CC_TOUCH_H__
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "math/CCGeometry.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
2015-03-27 12:07:19 +08:00
|
|
|
* @addtogroup base
|
2012-06-20 18:09:11 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** @class Touch
|
|
|
|
* @brief Encapsulates the Touch information, such as touch point, id and so on,
|
|
|
|
and provides the methods that commonly used.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL Touch : public Ref
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-23 20:27:13 +08:00
|
|
|
/**
|
2015-09-22 16:08:23 +08:00
|
|
|
* Dispatch mode, how the touches are dispatched.
|
2015-03-23 20:27:13 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-26 07:27:24 +08:00
|
|
|
enum class DispatchMode {
|
2015-03-21 18:02:56 +08:00
|
|
|
ALL_AT_ONCE, /** All at once. */
|
|
|
|
ONE_BY_ONE, /** One by one. */
|
2013-07-26 07:27:24 +08:00
|
|
|
};
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Constructor.
|
2015-03-23 20:27:13 +08:00
|
|
|
* @js ctor
|
2015-03-21 18:02:56 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Touch()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _id(0),
|
|
|
|
_startPointCaptured(false)
|
2012-04-20 15:23:00 +08:00
|
|
|
{}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Returns the current touch location in OpenGL coordinates.
|
|
|
|
*
|
|
|
|
* @return The current touch location in OpenGL coordinates.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getLocation() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Returns the previous touch location in OpenGL coordinates.
|
|
|
|
*
|
|
|
|
* @return The previous touch location in OpenGL coordinates.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getPreviousLocation() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Returns the start touch location in OpenGL coordinates.
|
|
|
|
*
|
|
|
|
* @return The start touch location in OpenGL coordinates.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getStartLocation() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Returns the delta of 2 current touches locations in screen coordinates.
|
|
|
|
*
|
|
|
|
* @return The delta of 2 current touches locations in screen coordinates.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getDelta() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Returns the current touch location in screen coordinates.
|
|
|
|
*
|
|
|
|
* @return The current touch location in screen coordinates.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getLocationInView() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Returns the previous touch location in screen coordinates.
|
|
|
|
*
|
|
|
|
* @return The previous touch location in screen coordinates.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getPreviousLocationInView() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Returns the start touch location in screen coordinates.
|
|
|
|
*
|
|
|
|
* @return The start touch location in screen coordinates.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getStartLocationInView() const;
|
2012-07-31 17:41:53 +08:00
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
/** Set the touch information. It always used to monitor touch event.
|
2015-03-21 18:02:56 +08:00
|
|
|
*
|
|
|
|
* @param id A given id
|
|
|
|
* @param x A given x coordinate.
|
|
|
|
* @param y A given y coordinate.
|
|
|
|
*/
|
2012-05-24 17:47:46 +08:00
|
|
|
void setTouchInfo(int id, float x, float y)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_id = id;
|
|
|
|
_prevPoint = _point;
|
|
|
|
_point.x = x;
|
|
|
|
_point.y = y;
|
|
|
|
if (!_startPointCaptured)
|
2013-03-04 20:08:19 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startPoint = _point;
|
|
|
|
_startPointCaptured = true;
|
2014-07-01 14:23:21 +08:00
|
|
|
_prevPoint = _point;
|
2013-03-04 20:08:19 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Get touch id.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js getId
|
|
|
|
* @lua getId
|
2015-03-21 18:02:56 +08:00
|
|
|
*
|
|
|
|
* @return The id of touch.
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2012-04-20 15:23:00 +08:00
|
|
|
int getID() const
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _id;
|
2012-04-20 15:23:00 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
private:
|
2013-06-15 14:03:30 +08:00
|
|
|
int _id;
|
|
|
|
bool _startPointCaptured;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _startPoint;
|
|
|
|
Vec2 _point;
|
|
|
|
Vec2 _prevPoint;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2015-03-27 12:07:19 +08:00
|
|
|
// end of base group
|
2012-06-20 18:09:11 +08:00
|
|
|
/// @}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __PLATFORM_TOUCH_H__
|