2013-10-05 01:07:39 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2013-10-05 01:07:39 +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 __cocos2d_libs__CCMouseEvent__
|
|
|
|
#define __cocos2d_libs__CCMouseEvent__
|
|
|
|
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCEvent.h"
|
2021-10-23 23:27:14 +08:00
|
|
|
#include "math/CCMath.h"
|
2013-10-05 01:07:39 +08:00
|
|
|
|
2015-03-24 18:22:52 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup base
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-10-05 01:07:39 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-03-23 18:39:27 +08:00
|
|
|
/** @class EventMouse
|
|
|
|
* @brief The mouse event.
|
|
|
|
*/
|
2014-07-15 12:00:31 +08:00
|
|
|
class CC_DLL EventMouse : public Event
|
2013-10-05 01:07:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2015-03-23 18:39:27 +08:00
|
|
|
* MouseEventType Different types of MouseEvent.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js NA
|
2013-10-05 01:07:39 +08:00
|
|
|
*/
|
|
|
|
enum class MouseEventType
|
|
|
|
{
|
|
|
|
MOUSE_NONE,
|
2013-10-05 07:14:52 +08:00
|
|
|
MOUSE_DOWN,
|
|
|
|
MOUSE_UP,
|
|
|
|
MOUSE_MOVE,
|
2013-10-05 01:07:39 +08:00
|
|
|
MOUSE_SCROLL,
|
|
|
|
};
|
|
|
|
|
2017-03-02 13:39:33 +08:00
|
|
|
enum class MouseButton
|
|
|
|
{
|
|
|
|
BUTTON_UNSET = -1,
|
|
|
|
BUTTON_LEFT = 0,
|
|
|
|
BUTTON_RIGHT = 1,
|
|
|
|
BUTTON_MIDDLE = 2,
|
|
|
|
BUTTON_4 = 3,
|
|
|
|
BUTTON_5 = 4,
|
|
|
|
BUTTON_6 = 5,
|
|
|
|
BUTTON_7 = 6,
|
|
|
|
BUTTON_8 = 7
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Constructor.
|
|
|
|
*
|
|
|
|
* @param mouseEventCode A given mouse event type.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js ctor
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2013-10-31 14:19:36 +08:00
|
|
|
EventMouse(MouseEventType mouseEventCode);
|
2013-10-05 01:07:39 +08:00
|
|
|
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Set mouse scroll data.
|
|
|
|
*
|
|
|
|
* @param scrollX The scroll data of x axis.
|
|
|
|
* @param scrollY The scroll data of y axis.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setScrollData(float scrollX, float scrollY) { _scrollX = scrollX; _scrollY = scrollY; }
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Get mouse scroll data of x axis.
|
|
|
|
*
|
|
|
|
* @return The scroll data of x axis.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getScrollX() const { return _scrollX; }
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Get mouse scroll data of y axis.
|
|
|
|
*
|
|
|
|
* @return The scroll data of y axis.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getScrollY() const { return _scrollY; }
|
2013-10-05 01:07:39 +08:00
|
|
|
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Set the cursor position.
|
|
|
|
*
|
|
|
|
* @param x The x coordinate of cursor position.
|
|
|
|
* @param y The y coordinate of cursor position.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js setLocation
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setCursorPosition(float x, float y) {
|
2014-08-01 17:37:30 +08:00
|
|
|
_x = x;
|
|
|
|
_y = y;
|
|
|
|
_prevPoint = _point;
|
|
|
|
_point.x = x;
|
|
|
|
_point.y = y;
|
|
|
|
if (!_startPointCaptured)
|
|
|
|
{
|
|
|
|
_startPoint = _point;
|
|
|
|
_startPointCaptured = true;
|
|
|
|
}
|
|
|
|
}
|
2014-07-28 10:39:35 +08:00
|
|
|
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Set mouse button.
|
|
|
|
*
|
|
|
|
* @param button a given mouse button.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js setButton
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2017-03-02 13:39:33 +08:00
|
|
|
void setMouseButton(MouseButton button) { _mouseButton = button; }
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Get mouse button.
|
|
|
|
*
|
|
|
|
* @return The mouse button.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js getButton
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2017-03-02 13:39:33 +08:00
|
|
|
MouseButton getMouseButton() const { return _mouseButton; }
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Get the cursor position of x axis.
|
|
|
|
*
|
|
|
|
* @return The x coordinate of cursor position.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js getLocationX
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getCursorX() const { return _x; }
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Get the cursor position of y axis.
|
|
|
|
*
|
|
|
|
* @return The y coordinate of cursor position.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js getLocationY
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getCursorY() const { return _y; }
|
2013-10-05 07:14:52 +08:00
|
|
|
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Returns the current touch location in OpenGL coordinates.
|
|
|
|
*
|
|
|
|
* @return The current touch location in OpenGL coordinates.
|
|
|
|
*/
|
2014-07-28 10:39:35 +08:00
|
|
|
Vec2 getLocation() const;
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Returns the previous touch location in OpenGL coordinates.
|
|
|
|
*
|
|
|
|
* @return The previous touch location in OpenGL coordinates.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js NA
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2014-07-28 10:39:35 +08:00
|
|
|
Vec2 getPreviousLocation() const;
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Returns the start touch location in OpenGL coordinates.
|
|
|
|
*
|
|
|
|
* @return The start touch location in OpenGL coordinates.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js NA
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2014-07-28 10:39:35 +08:00
|
|
|
Vec2 getStartLocation() const;
|
2015-03-23 18:39:27 +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-07-28 10:39:35 +08:00
|
|
|
Vec2 getDelta() const;
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Returns the current touch location in screen coordinates.
|
|
|
|
*
|
|
|
|
* @return The current touch location in screen coordinates.
|
|
|
|
*/
|
2014-07-28 10:39:35 +08:00
|
|
|
Vec2 getLocationInView() const;
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Returns the previous touch location in screen coordinates.
|
|
|
|
*
|
|
|
|
* @return The previous touch location in screen coordinates.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js NA
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2014-07-28 10:39:35 +08:00
|
|
|
Vec2 getPreviousLocationInView() const;
|
2015-03-23 18:39:27 +08:00
|
|
|
/** Returns the start touch location in screen coordinates.
|
|
|
|
*
|
|
|
|
* @return The start touch location in screen coordinates.
|
2015-03-24 16:37:09 +08:00
|
|
|
* @js NA
|
2015-03-23 18:39:27 +08:00
|
|
|
*/
|
2014-07-28 10:39:35 +08:00
|
|
|
Vec2 getStartLocationInView() const;
|
|
|
|
|
|
|
|
|
2013-10-05 01:07:39 +08:00
|
|
|
private:
|
|
|
|
MouseEventType _mouseEventType;
|
2017-03-02 13:39:33 +08:00
|
|
|
MouseButton _mouseButton;
|
2013-10-05 07:14:52 +08:00
|
|
|
float _x;
|
|
|
|
float _y;
|
2013-10-05 01:07:39 +08:00
|
|
|
float _scrollX;
|
|
|
|
float _scrollY;
|
|
|
|
|
2014-07-28 10:39:35 +08:00
|
|
|
bool _startPointCaptured;
|
|
|
|
Vec2 _startPoint;
|
|
|
|
Vec2 _point;
|
|
|
|
Vec2 _prevPoint;
|
|
|
|
|
2013-10-05 01:07:39 +08:00
|
|
|
friend class EventListenerMouse;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2015-03-24 18:22:52 +08:00
|
|
|
// end of base group
|
|
|
|
/// @}
|
|
|
|
|
2013-10-05 01:07:39 +08:00
|
|
|
#endif /* defined(__cocos2d_libs__CCMouseEvent__) */
|