Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2012 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef _ANDROIDFW_VELOCITY_CONTROL_H |
michael@0 | 18 | #define _ANDROIDFW_VELOCITY_CONTROL_H |
michael@0 | 19 | |
michael@0 | 20 | #include "Input.h" |
michael@0 | 21 | #include "VelocityTracker.h" |
michael@0 | 22 | #include <utils/Timers.h> |
michael@0 | 23 | |
michael@0 | 24 | namespace android { |
michael@0 | 25 | |
michael@0 | 26 | /* |
michael@0 | 27 | * Specifies parameters that govern pointer or wheel acceleration. |
michael@0 | 28 | */ |
michael@0 | 29 | struct VelocityControlParameters { |
michael@0 | 30 | // A scale factor that is multiplied with the raw velocity deltas |
michael@0 | 31 | // prior to applying any other velocity control factors. The scale |
michael@0 | 32 | // factor should be used to adapt the input device resolution |
michael@0 | 33 | // (eg. counts per inch) to the output device resolution (eg. pixels per inch). |
michael@0 | 34 | // |
michael@0 | 35 | // Must be a positive value. |
michael@0 | 36 | // Default is 1.0 (no scaling). |
michael@0 | 37 | float scale; |
michael@0 | 38 | |
michael@0 | 39 | // The scaled speed at which acceleration begins to be applied. |
michael@0 | 40 | // This value establishes the upper bound of a low speed regime for |
michael@0 | 41 | // small precise motions that are performed without any acceleration. |
michael@0 | 42 | // |
michael@0 | 43 | // Must be a non-negative value. |
michael@0 | 44 | // Default is 0.0 (no low threshold). |
michael@0 | 45 | float lowThreshold; |
michael@0 | 46 | |
michael@0 | 47 | // The scaled speed at which maximum acceleration is applied. |
michael@0 | 48 | // The difference between highThreshold and lowThreshold controls |
michael@0 | 49 | // the range of speeds over which the acceleration factor is interpolated. |
michael@0 | 50 | // The wider the range, the smoother the acceleration. |
michael@0 | 51 | // |
michael@0 | 52 | // Must be a non-negative value greater than or equal to lowThreshold. |
michael@0 | 53 | // Default is 0.0 (no high threshold). |
michael@0 | 54 | float highThreshold; |
michael@0 | 55 | |
michael@0 | 56 | // The acceleration factor. |
michael@0 | 57 | // When the speed is above the low speed threshold, the velocity will scaled |
michael@0 | 58 | // by an interpolated value between 1.0 and this amount. |
michael@0 | 59 | // |
michael@0 | 60 | // Must be a positive greater than or equal to 1.0. |
michael@0 | 61 | // Default is 1.0 (no acceleration). |
michael@0 | 62 | float acceleration; |
michael@0 | 63 | |
michael@0 | 64 | VelocityControlParameters() : |
michael@0 | 65 | scale(1.0f), lowThreshold(0.0f), highThreshold(0.0f), acceleration(1.0f) { |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | VelocityControlParameters(float scale, float lowThreshold, |
michael@0 | 69 | float highThreshold, float acceleration) : |
michael@0 | 70 | scale(scale), lowThreshold(lowThreshold), |
michael@0 | 71 | highThreshold(highThreshold), acceleration(acceleration) { |
michael@0 | 72 | } |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | /* |
michael@0 | 76 | * Implements mouse pointer and wheel speed control and acceleration. |
michael@0 | 77 | */ |
michael@0 | 78 | class VelocityControl { |
michael@0 | 79 | public: |
michael@0 | 80 | VelocityControl(); |
michael@0 | 81 | |
michael@0 | 82 | /* Sets the various parameters. */ |
michael@0 | 83 | void setParameters(const VelocityControlParameters& parameters); |
michael@0 | 84 | |
michael@0 | 85 | /* Resets the current movement counters to zero. |
michael@0 | 86 | * This has the effect of nullifying any acceleration. */ |
michael@0 | 87 | void reset(); |
michael@0 | 88 | |
michael@0 | 89 | /* Translates a raw movement delta into an appropriately |
michael@0 | 90 | * scaled / accelerated delta based on the current velocity. */ |
michael@0 | 91 | void move(nsecs_t eventTime, float* deltaX, float* deltaY); |
michael@0 | 92 | |
michael@0 | 93 | private: |
michael@0 | 94 | // If no movements are received within this amount of time, |
michael@0 | 95 | // we assume the movement has stopped and reset the movement counters. |
michael@0 | 96 | static const nsecs_t STOP_TIME = 500 * 1000000; // 500 ms |
michael@0 | 97 | |
michael@0 | 98 | VelocityControlParameters mParameters; |
michael@0 | 99 | |
michael@0 | 100 | nsecs_t mLastMovementTime; |
michael@0 | 101 | VelocityTracker::Position mRawPosition; |
michael@0 | 102 | VelocityTracker mVelocityTracker; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | } // namespace android |
michael@0 | 106 | |
michael@0 | 107 | #endif // _ANDROIDFW_VELOCITY_CONTROL_H |