2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#ifndef __AX_TOUCH_H__
|
|
|
|
#define __AX_TOUCH_H__
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2021-10-23 23:27:14 +08:00
|
|
|
#include "math/CCMath.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2012-04-19 14:35:52 +08:00
|
|
|
|
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.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Touch : public Ref
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +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
|
|
|
|
*/
|
2021-12-25 10:04:45 +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
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
Touch() : _id(0), _startPointCaptured(false), _curForce(0.f), _maxForce(0.f) {}
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Returns the previous touch location in screen coordinates.
|
2015-03-21 18:02:56 +08:00
|
|
|
*
|
|
|
|
* @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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-12-02 11:02:27 +08:00
|
|
|
/** Set the touch information. It always used to monitor touch event.
|
|
|
|
*
|
|
|
|
* @param id A given id
|
|
|
|
* @param x A given x coordinate.
|
|
|
|
* @param y A given y coordinate.
|
|
|
|
*/
|
|
|
|
void setTouchInfo(int id, float x, float y)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_id = id;
|
2015-12-02 11:02:27 +08:00
|
|
|
_prevPoint = _point;
|
|
|
|
_point.x = x;
|
|
|
|
_point.y = y;
|
2021-12-25 10:04:45 +08:00
|
|
|
_curForce = 0.0f;
|
|
|
|
_maxForce = 0.0f;
|
2015-12-02 11:02:27 +08:00
|
|
|
if (!_startPointCaptured)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_startPoint = _point;
|
2015-12-02 11:02:27 +08:00
|
|
|
_startPointCaptured = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
_prevPoint = _point;
|
2015-12-02 11:02:27 +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.
|
2015-12-01 13:02:53 +08:00
|
|
|
* @param force Current force for 3d touch.
|
2015-12-02 11:02:27 +08:00
|
|
|
* @param maxForce maximum possible force for 3d touch.
|
2015-03-21 18:02:56 +08:00
|
|
|
*/
|
2015-12-02 11:02:27 +08:00
|
|
|
void setTouchInfo(int id, float x, float y, float force, float maxForce)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_id = id;
|
2013-06-15 14:03:30 +08:00
|
|
|
_prevPoint = _point;
|
|
|
|
_point.x = x;
|
|
|
|
_point.y = y;
|
2021-12-25 10:04:45 +08:00
|
|
|
_curForce = force;
|
|
|
|
_maxForce = maxForce;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!_startPointCaptured)
|
2013-03-04 20:08:19 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_startPoint = _point;
|
2013-06-15 14:03:30 +08:00
|
|
|
_startPointCaptured = true;
|
2021-12-25 10:04:45 +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
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
int getID() const { return _id; }
|
2015-12-01 13:02:53 +08:00
|
|
|
/** Returns the current touch force for 3d touch.
|
|
|
|
*
|
|
|
|
* @return The current touch force for 3d touch.
|
|
|
|
*/
|
|
|
|
float getCurrentForce() const;
|
2015-12-02 11:02:27 +08:00
|
|
|
/** Returns the maximum touch force for 3d touch.
|
2015-12-01 13:02:53 +08:00
|
|
|
*
|
2015-12-02 11:02:27 +08:00
|
|
|
* @return The maximum touch force for 3d touch.
|
2015-12-01 13:02:53 +08:00
|
|
|
*/
|
|
|
|
float getMaxForce() const;
|
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;
|
2015-12-01 13:02:53 +08:00
|
|
|
float _curForce;
|
|
|
|
float _maxForce;
|
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
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
#endif // __PLATFORM_TOUCH_H__
|