diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index 7a1a10b9bf..35a7835328 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -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 */ diff --git a/cocos/base/CCEventMouse.cpp b/cocos/base/CCEventMouse.cpp index 447862de49..5c90e1c1ee 100644 --- a/cocos/base/CCEventMouse.cpp +++ b/cocos/base/CCEventMouse.cpp @@ -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 diff --git a/cocos/base/CCEventMouse.h b/cocos/base/CCEventMouse.h index d5a9d2def3..acd576b583 100644 --- a/cocos/base/CCEventMouse.h +++ b/cocos/base/CCEventMouse.h @@ -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; };