widget/gonk/libui/VelocityControl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/libui/VelocityControl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +/*
     1.5 + * Copyright (C) 2012 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef _ANDROIDFW_VELOCITY_CONTROL_H
    1.21 +#define _ANDROIDFW_VELOCITY_CONTROL_H
    1.22 +
    1.23 +#include "Input.h"
    1.24 +#include "VelocityTracker.h"
    1.25 +#include <utils/Timers.h>
    1.26 +
    1.27 +namespace android {
    1.28 +
    1.29 +/*
    1.30 + * Specifies parameters that govern pointer or wheel acceleration.
    1.31 + */
    1.32 +struct VelocityControlParameters {
    1.33 +    // A scale factor that is multiplied with the raw velocity deltas
    1.34 +    // prior to applying any other velocity control factors.  The scale
    1.35 +    // factor should be used to adapt the input device resolution
    1.36 +    // (eg. counts per inch) to the output device resolution (eg. pixels per inch).
    1.37 +    //
    1.38 +    // Must be a positive value.
    1.39 +    // Default is 1.0 (no scaling).
    1.40 +    float scale;
    1.41 +
    1.42 +    // The scaled speed at which acceleration begins to be applied.
    1.43 +    // This value establishes the upper bound of a low speed regime for
    1.44 +    // small precise motions that are performed without any acceleration.
    1.45 +    //
    1.46 +    // Must be a non-negative value.
    1.47 +    // Default is 0.0 (no low threshold).
    1.48 +    float lowThreshold;
    1.49 +
    1.50 +    // The scaled speed at which maximum acceleration is applied.
    1.51 +    // The difference between highThreshold and lowThreshold controls
    1.52 +    // the range of speeds over which the acceleration factor is interpolated.
    1.53 +    // The wider the range, the smoother the acceleration.
    1.54 +    //
    1.55 +    // Must be a non-negative value greater than or equal to lowThreshold.
    1.56 +    // Default is 0.0 (no high threshold).
    1.57 +    float highThreshold;
    1.58 +
    1.59 +    // The acceleration factor.
    1.60 +    // When the speed is above the low speed threshold, the velocity will scaled
    1.61 +    // by an interpolated value between 1.0 and this amount.
    1.62 +    //
    1.63 +    // Must be a positive greater than or equal to 1.0.
    1.64 +    // Default is 1.0 (no acceleration).
    1.65 +    float acceleration;
    1.66 +
    1.67 +    VelocityControlParameters() :
    1.68 +            scale(1.0f), lowThreshold(0.0f), highThreshold(0.0f), acceleration(1.0f) {
    1.69 +    }
    1.70 +
    1.71 +    VelocityControlParameters(float scale, float lowThreshold,
    1.72 +            float highThreshold, float acceleration) :
    1.73 +            scale(scale), lowThreshold(lowThreshold),
    1.74 +            highThreshold(highThreshold), acceleration(acceleration) {
    1.75 +    }
    1.76 +};
    1.77 +
    1.78 +/*
    1.79 + * Implements mouse pointer and wheel speed control and acceleration.
    1.80 + */
    1.81 +class VelocityControl {
    1.82 +public:
    1.83 +    VelocityControl();
    1.84 +
    1.85 +    /* Sets the various parameters. */
    1.86 +    void setParameters(const VelocityControlParameters& parameters);
    1.87 +
    1.88 +    /* Resets the current movement counters to zero.
    1.89 +     * This has the effect of nullifying any acceleration. */
    1.90 +    void reset();
    1.91 +
    1.92 +    /* Translates a raw movement delta into an appropriately
    1.93 +     * scaled / accelerated delta based on the current velocity. */
    1.94 +    void move(nsecs_t eventTime, float* deltaX, float* deltaY);
    1.95 +
    1.96 +private:
    1.97 +    // If no movements are received within this amount of time,
    1.98 +    // we assume the movement has stopped and reset the movement counters.
    1.99 +    static const nsecs_t STOP_TIME = 500 * 1000000; // 500 ms
   1.100 +
   1.101 +    VelocityControlParameters mParameters;
   1.102 +
   1.103 +    nsecs_t mLastMovementTime;
   1.104 +    VelocityTracker::Position mRawPosition;
   1.105 +    VelocityTracker mVelocityTracker;
   1.106 +};
   1.107 +
   1.108 +} // namespace android
   1.109 +
   1.110 +#endif // _ANDROIDFW_VELOCITY_CONTROL_H

mercurial