widget/gonk/libui/VelocityControl.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /*
     2  * Copyright (C) 2012 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  */
    17 #ifndef _ANDROIDFW_VELOCITY_CONTROL_H
    18 #define _ANDROIDFW_VELOCITY_CONTROL_H
    20 #include "Input.h"
    21 #include "VelocityTracker.h"
    22 #include <utils/Timers.h>
    24 namespace android {
    26 /*
    27  * Specifies parameters that govern pointer or wheel acceleration.
    28  */
    29 struct VelocityControlParameters {
    30     // A scale factor that is multiplied with the raw velocity deltas
    31     // prior to applying any other velocity control factors.  The scale
    32     // factor should be used to adapt the input device resolution
    33     // (eg. counts per inch) to the output device resolution (eg. pixels per inch).
    34     //
    35     // Must be a positive value.
    36     // Default is 1.0 (no scaling).
    37     float scale;
    39     // The scaled speed at which acceleration begins to be applied.
    40     // This value establishes the upper bound of a low speed regime for
    41     // small precise motions that are performed without any acceleration.
    42     //
    43     // Must be a non-negative value.
    44     // Default is 0.0 (no low threshold).
    45     float lowThreshold;
    47     // The scaled speed at which maximum acceleration is applied.
    48     // The difference between highThreshold and lowThreshold controls
    49     // the range of speeds over which the acceleration factor is interpolated.
    50     // The wider the range, the smoother the acceleration.
    51     //
    52     // Must be a non-negative value greater than or equal to lowThreshold.
    53     // Default is 0.0 (no high threshold).
    54     float highThreshold;
    56     // The acceleration factor.
    57     // When the speed is above the low speed threshold, the velocity will scaled
    58     // by an interpolated value between 1.0 and this amount.
    59     //
    60     // Must be a positive greater than or equal to 1.0.
    61     // Default is 1.0 (no acceleration).
    62     float acceleration;
    64     VelocityControlParameters() :
    65             scale(1.0f), lowThreshold(0.0f), highThreshold(0.0f), acceleration(1.0f) {
    66     }
    68     VelocityControlParameters(float scale, float lowThreshold,
    69             float highThreshold, float acceleration) :
    70             scale(scale), lowThreshold(lowThreshold),
    71             highThreshold(highThreshold), acceleration(acceleration) {
    72     }
    73 };
    75 /*
    76  * Implements mouse pointer and wheel speed control and acceleration.
    77  */
    78 class VelocityControl {
    79 public:
    80     VelocityControl();
    82     /* Sets the various parameters. */
    83     void setParameters(const VelocityControlParameters& parameters);
    85     /* Resets the current movement counters to zero.
    86      * This has the effect of nullifying any acceleration. */
    87     void reset();
    89     /* Translates a raw movement delta into an appropriately
    90      * scaled / accelerated delta based on the current velocity. */
    91     void move(nsecs_t eventTime, float* deltaX, float* deltaY);
    93 private:
    94     // If no movements are received within this amount of time,
    95     // we assume the movement has stopped and reset the movement counters.
    96     static const nsecs_t STOP_TIME = 500 * 1000000; // 500 ms
    98     VelocityControlParameters mParameters;
   100     nsecs_t mLastMovementTime;
   101     VelocityTracker::Position mRawPosition;
   102     VelocityTracker mVelocityTracker;
   103 };
   105 } // namespace android
   107 #endif // _ANDROIDFW_VELOCITY_CONTROL_H

mercurial