mirror of https://github.com/axmolengine/axmol.git
Add Feature #5633:EventMouse should support getDelta, getDeltaX, getDeltaY functions
This commit is contained in:
parent
6217748f1c
commit
bd5ca6a244
|
@ -39,7 +39,7 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
/** DrawNode
|
/** DrawNode
|
||||||
Node that draws dots, segments and polygons.
|
Node that draws dots, segments and polygons.
|
||||||
Faster than the "drawing primitives" since they it draws everything in one single batch.
|
Faster than the "drawing primitives" since they draws everything in one single batch.
|
||||||
|
|
||||||
@since v2.1
|
@since v2.1
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "base/CCEventMouse.h"
|
#include "base/CCEventMouse.h"
|
||||||
|
#include "base/CCDirector.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -38,4 +39,45 @@ EventMouse::EventMouse(MouseEventType mouseEventCode)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// returns the current touch location in screen coordinates
|
||||||
|
Vec2 EventMouse::getLocationInView() const
|
||||||
|
{
|
||||||
|
return _point;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the previous touch location in screen coordinates
|
||||||
|
Vec2 EventMouse::getPreviousLocationInView() const
|
||||||
|
{
|
||||||
|
return _prevPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the start touch location in screen coordinates
|
||||||
|
Vec2 EventMouse::getStartLocationInView() const
|
||||||
|
{
|
||||||
|
return _startPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the current touch location in OpenGL coordinates
|
||||||
|
Vec2 EventMouse::getLocation() const
|
||||||
|
{
|
||||||
|
return Director::getInstance()->convertToGL(_point);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the previous touch location in OpenGL coordinates
|
||||||
|
Vec2 EventMouse::getPreviousLocation() const
|
||||||
|
{
|
||||||
|
return Director::getInstance()->convertToGL(_prevPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the start touch location in OpenGL coordinates
|
||||||
|
Vec2 EventMouse::getStartLocation() const
|
||||||
|
{
|
||||||
|
return Director::getInstance()->convertToGL(_startPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the delta position between the current location and the previous location in OpenGL coordinates
|
||||||
|
Vec2 EventMouse::getDelta() const
|
||||||
|
{
|
||||||
|
return getLocation() - getPreviousLocation();
|
||||||
|
}
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#define __cocos2d_libs__CCMouseEvent__
|
#define __cocos2d_libs__CCMouseEvent__
|
||||||
|
|
||||||
#include "base/CCEvent.h"
|
#include "base/CCEvent.h"
|
||||||
|
#include "math/CCGeometry.h"
|
||||||
|
|
||||||
#define MOUSE_BUTTON_LEFT 0
|
#define MOUSE_BUTTON_LEFT 0
|
||||||
#define MOUSE_BUTTON_RIGHT 1
|
#define MOUSE_BUTTON_RIGHT 1
|
||||||
|
@ -61,12 +62,40 @@ public:
|
||||||
inline float getScrollX() { return _scrollX; };
|
inline float getScrollX() { return _scrollX; };
|
||||||
inline float getScrollY() { return _scrollY; };
|
inline float getScrollY() { return _scrollY; };
|
||||||
|
|
||||||
inline void setCursorPosition(float x, float y) { _x = x; _y = y; };
|
inline void setCursorPosition(float x, float y) {
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_prevPoint = _point;
|
||||||
|
_point.x = x;
|
||||||
|
_point.y = y;
|
||||||
|
if (!_startPointCaptured)
|
||||||
|
{
|
||||||
|
_startPoint = _point;
|
||||||
|
_startPointCaptured = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void setMouseButton(int button) { _mouseButton = button; };
|
inline void setMouseButton(int button) { _mouseButton = button; };
|
||||||
inline int getMouseButton() { return _mouseButton; };
|
inline int getMouseButton() { return _mouseButton; };
|
||||||
inline float getCursorX() { return _x; };
|
inline float getCursorX() { return _x; };
|
||||||
inline float getCursorY() { return _y; };
|
inline float getCursorY() { return _y; };
|
||||||
|
|
||||||
|
/** returns the current touch location in OpenGL coordinates */
|
||||||
|
Vec2 getLocation() const;
|
||||||
|
/** returns the previous touch location in OpenGL coordinates */
|
||||||
|
Vec2 getPreviousLocation() const;
|
||||||
|
/** returns the start touch location in OpenGL coordinates */
|
||||||
|
Vec2 getStartLocation() const;
|
||||||
|
/** returns the delta of 2 current touches locations in screen coordinates */
|
||||||
|
Vec2 getDelta() const;
|
||||||
|
/** returns the current touch location in screen coordinates */
|
||||||
|
Vec2 getLocationInView() const;
|
||||||
|
/** returns the previous touch location in screen coordinates */
|
||||||
|
Vec2 getPreviousLocationInView() const;
|
||||||
|
/** returns the start touch location in screen coordinates */
|
||||||
|
Vec2 getStartLocationInView() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MouseEventType _mouseEventType;
|
MouseEventType _mouseEventType;
|
||||||
int _mouseButton;
|
int _mouseButton;
|
||||||
|
@ -75,6 +104,11 @@ private:
|
||||||
float _scrollX;
|
float _scrollX;
|
||||||
float _scrollY;
|
float _scrollY;
|
||||||
|
|
||||||
|
bool _startPointCaptured;
|
||||||
|
Vec2 _startPoint;
|
||||||
|
Vec2 _point;
|
||||||
|
Vec2 _prevPoint;
|
||||||
|
|
||||||
friend class EventListenerMouse;
|
friend class EventListenerMouse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue