| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
|---|---|
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #include "Input/BsMouse.h" |
| 4 | #include "Input/BsInput.h" |
| 5 | #include "Private/Linux/BsLinuxPlatform.h" |
| 6 | |
| 7 | namespace bs |
| 8 | { |
| 9 | /** Contains private data for the Linux Mouse implementation. */ |
| 10 | struct Mouse::Pimpl |
| 11 | { |
| 12 | bool hasInputFocus; |
| 13 | }; |
| 14 | |
| 15 | Mouse::Mouse(const String& name, Input* owner) |
| 16 | : mName(name), mOwner(owner) |
| 17 | { |
| 18 | m = bs_new<Pimpl>(); |
| 19 | m->hasInputFocus = true; |
| 20 | } |
| 21 | |
| 22 | Mouse::~Mouse() |
| 23 | { |
| 24 | bs_delete(m); |
| 25 | } |
| 26 | |
| 27 | void Mouse::capture() |
| 28 | { |
| 29 | Lock lock(LinuxPlatform::eventLock); |
| 30 | |
| 31 | if(m->hasInputFocus) |
| 32 | { |
| 33 | double deltaX = round(LinuxPlatform::mouseMotionEvent.deltaX); |
| 34 | double deltaY = round(LinuxPlatform::mouseMotionEvent.deltaY); |
| 35 | double deltaZ = round(LinuxPlatform::mouseMotionEvent.deltaZ); |
| 36 | |
| 37 | if (deltaX != 0 || deltaY != 0 || deltaZ != 0) |
| 38 | mOwner->_notifyMouseMoved(deltaX, deltaY, deltaZ); |
| 39 | |
| 40 | LinuxPlatform::mouseMotionEvent.deltaX -= deltaX; |
| 41 | LinuxPlatform::mouseMotionEvent.deltaY -= deltaY; |
| 42 | LinuxPlatform::mouseMotionEvent.deltaZ -= deltaZ; |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | // Discard accumulated data |
| 47 | LinuxPlatform::mouseMotionEvent.deltaX = 0; |
| 48 | LinuxPlatform::mouseMotionEvent.deltaY = 0; |
| 49 | LinuxPlatform::mouseMotionEvent.deltaZ = 0; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void Mouse::changeCaptureContext(UINT64 windowHandle) |
| 54 | { |
| 55 | m->hasInputFocus = windowHandle != (UINT64)-1; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 |