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"
|
|
|
|
#include "base/CCGeometry.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup input
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL Touch : public Ref
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-26 07:27:24 +08:00
|
|
|
/** how the touches are dispathced */
|
|
|
|
enum class DispatchMode {
|
|
|
|
/** All at once */
|
|
|
|
ALL_AT_ONCE,
|
|
|
|
/** one by one */
|
|
|
|
ONE_BY_ONE,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2012-07-31 17:41:53 +08:00
|
|
|
/** returns the current touch location in OpenGL coordinates */
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 getLocation() const;
|
2012-07-31 17:41:53 +08:00
|
|
|
/** returns the previous touch location in OpenGL coordinates */
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 getPreviousLocation() const;
|
2013-03-04 20:08:19 +08:00
|
|
|
/** returns the start touch location in OpenGL coordinates */
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 getStartLocation() const;
|
2012-10-14 20:20:31 +08:00
|
|
|
/** returns the delta of 2 current touches locations in screen coordinates */
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 getDelta() const;
|
2012-07-31 17:41:53 +08:00
|
|
|
/** returns the current touch location in screen coordinates */
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 getLocationInView() const;
|
2012-07-31 17:41:53 +08:00
|
|
|
/** returns the previous touch location in screen coordinates */
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 getPreviousLocationInView() const;
|
2013-03-04 20:08:19 +08:00
|
|
|
/** returns the start touch location in screen coordinates */
|
2014-04-15 18:08:29 +08:00
|
|
|
Vector2 getStartLocationInView() const;
|
2012-07-31 17:41:53 +08:00
|
|
|
|
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;
|
2013-03-04 20:08:19 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js getId
|
|
|
|
* @lua getId
|
|
|
|
*/
|
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-04-15 18:08:29 +08:00
|
|
|
Vector2 _startPoint;
|
|
|
|
Vector2 _point;
|
|
|
|
Vector2 _prevPoint;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of input group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __PLATFORM_TOUCH_H__
|