blob: 635366bff227e241e91466c1f1f1545c2550fa19 [file] [log] [blame]
Harry Cuttsb57f1702022-11-28 15:34:22 +00001/*
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
19namespace android {
20
21void 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
29const std::map<int32_t, std::vector<int32_t>>& FakePointerController::getSpots() {
30 return mSpotsByDisplay;
31}
32
33void FakePointerController::setPosition(float x, float y) {
34 mX = x;
35 mY = y;
36}
37
38void FakePointerController::setButtonState(int32_t buttonState) {
39 mButtonState = buttonState;
40}
41
42int32_t FakePointerController::getButtonState() const {
43 return mButtonState;
44}
45
46void FakePointerController::getPosition(float* outX, float* outY) const {
47 *outX = mX;
48 *outY = mY;
49}
50
51int32_t FakePointerController::getDisplayId() const {
52 return mDisplayId;
53}
54
55void FakePointerController::setDisplayViewport(const DisplayViewport& viewport) {
56 mDisplayId = viewport.displayId;
57}
58
59bool 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
68void 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
77void 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
89void FakePointerController::clearSpots() {
90 mSpotsByDisplay.clear();
91}
92
93} // namespace android