Add Feature #5633:EventMouse should support getDelta, getDeltaX, getDeltaY functions

This commit is contained in:
AppleJDay 2014-07-28 10:39:35 +08:00
parent 6217748f1c
commit bd5ca6a244
3 changed files with 78 additions and 2 deletions

View File

@ -39,7 +39,7 @@ NS_CC_BEGIN
/** DrawNode
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
*/

View File

@ -24,6 +24,7 @@
****************************************************************************/
#include "base/CCEventMouse.h"
#include "base/CCDirector.h"
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

View File

@ -27,6 +27,7 @@
#define __cocos2d_libs__CCMouseEvent__
#include "base/CCEvent.h"
#include "math/CCGeometry.h"
#define MOUSE_BUTTON_LEFT 0
#define MOUSE_BUTTON_RIGHT 1
@ -61,12 +62,40 @@ public:
inline float getScrollX() { return _scrollX; };
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 int getMouseButton() { return _mouseButton; };
inline float getCursorX() { return _x; };
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:
MouseEventType _mouseEventType;
int _mouseButton;
@ -75,6 +104,11 @@ private:
float _scrollX;
float _scrollY;
bool _startPointCaptured;
Vec2 _startPoint;
Vec2 _point;
Vec2 _prevPoint;
friend class EventListenerMouse;
};