Harry Cutts | b57f170 | 2022-11-28 15:34:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "FakePointerController.h" |
| 18 | |
| 19 | namespace android { |
| 20 | |
| 21 | void FakePointerController::setBounds(float minX, float minY, float maxX, float maxY) { |
| 22 | mHaveBounds = true; |
| 23 | mMinX = minX; |
| 24 | mMinY = minY; |
| 25 | mMaxX = maxX; |
| 26 | mMaxY = maxY; |
| 27 | } |
| 28 | |
| 29 | const std::map<int32_t, std::vector<int32_t>>& FakePointerController::getSpots() { |
| 30 | return mSpotsByDisplay; |
| 31 | } |
| 32 | |
| 33 | void FakePointerController::setPosition(float x, float y) { |
| 34 | mX = x; |
| 35 | mY = y; |
| 36 | } |
| 37 | |
| 38 | void FakePointerController::setButtonState(int32_t buttonState) { |
| 39 | mButtonState = buttonState; |
| 40 | } |
| 41 | |
| 42 | int32_t FakePointerController::getButtonState() const { |
| 43 | return mButtonState; |
| 44 | } |
| 45 | |
| 46 | void FakePointerController::getPosition(float* outX, float* outY) const { |
| 47 | *outX = mX; |
| 48 | *outY = mY; |
| 49 | } |
| 50 | |
| 51 | int32_t FakePointerController::getDisplayId() const { |
| 52 | return mDisplayId; |
| 53 | } |
| 54 | |
| 55 | void FakePointerController::setDisplayViewport(const DisplayViewport& viewport) { |
| 56 | mDisplayId = viewport.displayId; |
| 57 | } |
| 58 | |
| 59 | bool FakePointerController::getBounds(float* outMinX, float* outMinY, float* outMaxX, |
| 60 | float* outMaxY) const { |
| 61 | *outMinX = mMinX; |
| 62 | *outMinY = mMinY; |
| 63 | *outMaxX = mMaxX; |
| 64 | *outMaxY = mMaxY; |
| 65 | return mHaveBounds; |
| 66 | } |
| 67 | |
| 68 | void FakePointerController::move(float deltaX, float deltaY) { |
| 69 | mX += deltaX; |
| 70 | if (mX < mMinX) mX = mMinX; |
| 71 | if (mX > mMaxX) mX = mMaxX; |
| 72 | mY += deltaY; |
| 73 | if (mY < mMinY) mY = mMinY; |
| 74 | if (mY > mMaxY) mY = mMaxY; |
| 75 | } |
| 76 | |
| 77 | void FakePointerController::setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits, |
| 78 | int32_t displayId) { |
| 79 | std::vector<int32_t> newSpots; |
| 80 | // Add spots for fingers that are down. |
| 81 | for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) { |
| 82 | uint32_t id = idBits.clearFirstMarkedBit(); |
| 83 | newSpots.push_back(id); |
| 84 | } |
| 85 | |
| 86 | mSpotsByDisplay[displayId] = newSpots; |
| 87 | } |
| 88 | |
| 89 | void FakePointerController::clearSpots() { |
| 90 | mSpotsByDisplay.clear(); |
| 91 | } |
| 92 | |
| 93 | } // namespace android |