BsLinuxMouse.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Input/BsMouse.h"
  4. #include "Input/BsInput.h"
  5. #include "Linux/BsLinuxPlatform.h"
  6. namespace bs
  7. {
  8. /** Contains private data for the Linux Mouse implementation. */
  9. struct Mouse::Pimpl
  10. {
  11. bool hasInputFocus;
  12. };
  13. Mouse::Mouse(const String& name, Input* owner)
  14. : mName(name), mOwner(owner)
  15. {
  16. m = bs_new<Pimpl>();
  17. m->hasInputFocus = true;
  18. }
  19. Mouse::~Mouse()
  20. {
  21. bs_delete(m);
  22. }
  23. void Mouse::capture()
  24. {
  25. Lock lock(LinuxPlatform::eventLock);
  26. if(m->hasInputFocus)
  27. {
  28. double deltaX = round(LinuxPlatform::mouseMotionEvent.deltaX);
  29. double deltaY = round(LinuxPlatform::mouseMotionEvent.deltaY);
  30. double deltaZ = round(LinuxPlatform::mouseMotionEvent.deltaZ);
  31. if (deltaX != 0 || deltaY != 0 || deltaZ != 0)
  32. mOwner->_notifyMouseMoved(deltaX, deltaY, deltaZ);
  33. LinuxPlatform::mouseMotionEvent.deltaX -= deltaX;
  34. LinuxPlatform::mouseMotionEvent.deltaY -= deltaY;
  35. LinuxPlatform::mouseMotionEvent.deltaZ -= deltaZ;
  36. }
  37. else
  38. {
  39. // Discard accumulated data
  40. LinuxPlatform::mouseMotionEvent.deltaX = 0;
  41. LinuxPlatform::mouseMotionEvent.deltaY = 0;
  42. LinuxPlatform::mouseMotionEvent.deltaZ = 0;
  43. }
  44. }
  45. void Mouse::changeCaptureContext(UINT64 windowHandle)
  46. {
  47. m->hasInputFocus = windowHandle != (UINT64)-1;
  48. }
  49. }