blob: ab7879f1aa8d6a5858dc4cf7d4cc2f19579d3ccb [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
Harry Cuttsce86cc32022-12-14 20:36:33 +000019#include <gtest/gtest.h>
20
Harry Cuttsb57f1702022-11-28 15:34:22 +000021namespace android {
22
23void FakePointerController::setBounds(float minX, float minY, float maxX, float maxY) {
24 mHaveBounds = true;
25 mMinX = minX;
26 mMinY = minY;
27 mMaxX = maxX;
28 mMaxY = maxY;
29}
30
31const std::map<int32_t, std::vector<int32_t>>& FakePointerController::getSpots() {
32 return mSpotsByDisplay;
33}
34
35void FakePointerController::setPosition(float x, float y) {
36 mX = x;
37 mY = y;
38}
39
40void FakePointerController::setButtonState(int32_t buttonState) {
41 mButtonState = buttonState;
42}
43
44int32_t FakePointerController::getButtonState() const {
45 return mButtonState;
46}
47
48void FakePointerController::getPosition(float* outX, float* outY) const {
49 *outX = mX;
50 *outY = mY;
51}
52
53int32_t FakePointerController::getDisplayId() const {
54 return mDisplayId;
55}
56
57void FakePointerController::setDisplayViewport(const DisplayViewport& viewport) {
58 mDisplayId = viewport.displayId;
59}
60
Harry Cuttsce86cc32022-12-14 20:36:33 +000061void FakePointerController::assertPosition(float x, float y) {
62 float actualX, actualY;
63 getPosition(&actualX, &actualY);
64 ASSERT_NEAR(x, actualX, 1);
65 ASSERT_NEAR(y, actualY, 1);
66}
67
Harry Cuttsb57f1702022-11-28 15:34:22 +000068bool FakePointerController::getBounds(float* outMinX, float* outMinY, float* outMaxX,
69 float* outMaxY) const {
70 *outMinX = mMinX;
71 *outMinY = mMinY;
72 *outMaxX = mMaxX;
73 *outMaxY = mMaxY;
74 return mHaveBounds;
75}
76
77void FakePointerController::move(float deltaX, float deltaY) {
78 mX += deltaX;
79 if (mX < mMinX) mX = mMinX;
80 if (mX > mMaxX) mX = mMaxX;
81 mY += deltaY;
82 if (mY < mMinY) mY = mMinY;
83 if (mY > mMaxY) mY = mMaxY;
84}
85
86void FakePointerController::setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,
87 int32_t displayId) {
88 std::vector<int32_t> newSpots;
89 // Add spots for fingers that are down.
90 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
91 uint32_t id = idBits.clearFirstMarkedBit();
92 newSpots.push_back(id);
93 }
94
95 mSpotsByDisplay[displayId] = newSpots;
96}
97
98void FakePointerController::clearSpots() {
99 mSpotsByDisplay.clear();
100}
101
102} // namespace android