CCEventMouse.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /****************************************************************************
  2. Copyright (c) 2013-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #include "base/CCEventMouse.h"
  22. #include "base/CCDirector.h"
  23. NS_CC_BEGIN
  24. EventMouse::EventMouse(MouseEventType mouseEventCode)
  25. : Event(Type::MOUSE)
  26. , _mouseEventType(mouseEventCode)
  27. , _mouseButton(MouseButton::BUTTON_UNSET)
  28. , _x(0.0f)
  29. , _y(0.0f)
  30. , _scrollX(0.0f)
  31. , _scrollY(0.0f)
  32. , _startPointCaptured(false)
  33. {
  34. };
  35. // returns the current touch location in screen coordinates
  36. Vec2 EventMouse::getLocationInView() const
  37. {
  38. return _point;
  39. }
  40. // returns the previous touch location in screen coordinates
  41. Vec2 EventMouse::getPreviousLocationInView() const
  42. {
  43. return _prevPoint;
  44. }
  45. // returns the start touch location in screen coordinates
  46. Vec2 EventMouse::getStartLocationInView() const
  47. {
  48. return _startPoint;
  49. }
  50. // returns the current touch location in OpenGL coordinates
  51. Vec2 EventMouse::getLocation() const
  52. {
  53. return Director::getInstance()->convertToGL(_point);
  54. }
  55. // returns the previous touch location in OpenGL coordinates
  56. Vec2 EventMouse::getPreviousLocation() const
  57. {
  58. return Director::getInstance()->convertToGL(_prevPoint);
  59. }
  60. // returns the start touch location in OpenGL coordinates
  61. Vec2 EventMouse::getStartLocation() const
  62. {
  63. return Director::getInstance()->convertToGL(_startPoint);
  64. }
  65. // returns the delta position between the current location and the previous location in OpenGL coordinates
  66. Vec2 EventMouse::getDelta() const
  67. {
  68. return getLocation() - getPreviousLocation();
  69. }
  70. NS_CC_END