File: tween.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (172 lines) | stat: -rw-r--r-- 8,070 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_ANIMATION_TWEEN_H_
#define UI_GFX_ANIMATION_TWEEN_H_

#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/animation/animation_export.h"

namespace base {
class TimeTicks;
}

namespace gfx {

class Rect;
class RectF;
class Size;
class SizeF;
class Transform;
class TransformOperations;

class ANIMATION_EXPORT Tween {
 public:
  enum Type {
    LINEAR,       // Linear.
    EASE_OUT,     // Fast in, slow out (default).
    EASE_OUT_2,   // Variant of EASE_OUT that ends slower than EASE_OUT.
    EASE_OUT_3,   // Variant of EASE_OUT that ends slower than EASE_OUT_2.
    EASE_OUT_4,   // Variant of EASE_OUT that start slower than EASE_OUT_3,
                  // and ends faster. Best used to lead into a bounce
                  // animation.
    EASE_IN,      // Slow in, fast out.
    EASE_IN_2,    // Variant of EASE_IN that starts out slower than
                  // EASE_IN.
    EASE_IN_OUT,  // Slow in and out, fast in the middle.
    EASE_IN_OUT_EMPHASIZED,  // Variant of EASE_IN_OUT that starts slowly,
                             // speeds up shortly thereafter, and then ends
                             // slowly. This curve can be imagined as a steeper
                             // version of EASE_IN_OUT.
    EASE_IN_OUT_2,       // Variant of EASE_IN_OUT that starts and ends slower
                         // than EASE_IN_OUT.
    SMOOTH_IN_OUT,       // Smooth, consistent speeds in and out (sine wave).
    FAST_OUT_SLOW_IN,    // Variant of EASE_IN_OUT which should be used in most
                         // cases.
    FAST_OUT_SLOW_IN_2,  // Variant of FAST_OUT_SLOW_IN that starts out quicker.
    FAST_OUT_SLOW_IN_3,  // Variant of FAST_OUT_SLOW_IN that starts out quicker
                         // than FAST_OUT_SLOW_IN_2. Best used for rebound in
                         // bounce animation.
    LINEAR_OUT_SLOW_IN,  // Variant of EASE_OUT which should be used for
                         // fading in from 0% or motion when entering a scene.
    SLOW_OUT_LINEAR_IN,  // Reverse of LINEAR_OUT_SLOW_IN which should be used
                         // in reverse animation to create a rubberband effect.
    FAST_OUT_LINEAR_IN,  // Variant of EASE_IN which should should be used for
                         // fading out to 0% or motion when exiting a scene.
    ZERO,                // Returns a value of 0 always.

    // TODO(zxdan): New animation curve name convention will be used to resolve
    // the confusion caused by "IN" and "OUT".

    // The new name convention is below:
    // ACCEL_<1>_DECEL_<2> where <1> and <2> are used to express the
    // acceleration and deceleration speeds. The corresponding cubic bezier
    // curve parameters would be ( 0.01 * <1>, 0, 1 - 0.01 * <2>, 1 ). Note that
    // LIN means the speed is 0. For example,
    // ACCEL_20_DECEL_20 = (0.2, 0, 0.8, 1): https://cubic-bezier.com/#.2,0,.8,1
    // ACCEL_100_DECEL_100 = (1, 0, 0, 1): https://cubic-bezier.com/#1,0,0,1
    // ACCEL_LIN_DECEL_LIN = (0, 0, 1, 1): https://cubic-bezier.com/#0,0,1,1
    // ACCEL_40_DECEL_20 = (0.4, 0, 0.8, 1): https://cubic-bezier.com/#.4,0,.8,1
    // ACCEL_<1>_<2>_DECEL_<3>_<4> correspond to cubic bezier with curve
    // parameters (0.01 * <1>, 0.01 * <2>, 1 - 0.01 * <3>, 1 - 0.01 * <4>). For
    // example,
    // ACCEL_0_20_DECEL_100_10 = (0, 0.2, 0, 0.9):
    //     https://cubic-bezier.com/#0,.2,0,.9
    // ACCEL_40_DECEL_100_3 = (0.4, 0, 0,0.97):
    //     https://cubic-bezier.com/#.4,0,0,.97
    // ACCEL_LIN_DECEL_100_3 = (0, 0, 0, 0.97):
    //     https://cubic-bezier.com/#0,0,0,.97
    ACCEL_LIN_DECEL_60,   // Pulling a small to medium element into a place.
    ACCEL_LIN_DECEL_100,  // Pulling a small to medium element into a place that
                          // has very fast deceleration.
    // Starts with linear speed and soft deceleration. Use for elements that are
    // not visible at the beginning of a transition, but are visible at the end.
    ACCEL_LIN_DECEL_100_3,
    ACCEL_20_DECEL_60,  // Moving a small, low emphasis or responsive elements.
    ACCEL_20_DECEL_100,
    ACCEL_30_DECEL_20_85,
    ACCEL_40_DECEL_20,
    // Moderate acceleration and soft deceleration. Used for elements that are
    // visible at the beginning and end of a transition.
    ACCEL_40_DECEL_100_3,
    ACCEL_80_DECEL_20,     // Slow in and fast out with ease.
    ACCEL_0_40_DECEL_100,  // Specialized curve with an emphasized deceleration
                           // drift.
    ACCEL_0_80_DECEL_80,   // Variant of ACCEL_0_40_DECEL_100 which drops in
                           // value faster, but flattens out into the drift
                           // sooner.

    ACCEL_0_100_DECEL_80,  // Variant of ACCEL_0_80_DECEL_80 which drops in
                           // value even faster.

    ACCEL_5_70_DECEL_90,  // Start at peak velocity and very soft
                          // deceleration.
  };

  Tween(const Tween&) = delete;
  Tween& operator=(const Tween&) = delete;

  // Returns the value based on the tween type. |state| is from 0-1.
  static double CalculateValue(Type type, double state);

  // Conveniences for getting a value between a start and end point.
  static SkColor4f ColorValueBetween(double value,
                                     SkColor4f start,
                                     SkColor4f target);
  static SkColor ColorValueBetween(double value, SkColor start, SkColor target);
  static double DoubleValueBetween(double value, double start, double target);
  static float FloatValueBetween(double value, float start, float target);
  static float ClampedFloatValueBetween(const base::TimeTicks& time,
                                        const base::TimeTicks& start_time,
                                        float start,
                                        const base::TimeTicks& target_time,
                                        float target);

  // Interpolated between start and target, with every integer in this range
  // given equal weight.
  static int IntValueBetween(double value, int start, int target);

  // Interpolates between start and target as real numbers, and rounds the
  // result to the nearest integer, with ties broken by rounding towards
  // positive infinity. This gives start and target half the weight of the
  // other integers in the range. This is the integer interpolation approach
  // specified by www.w3.org/TR/css3-transitions.
  static int LinearIntValueBetween(double value, int start, int target);

  // Interpolates between |start| and |target| rects, animating the rect corners
  // (as opposed to animating the rect origin and size) to minimize rounding
  // error accumulation at intermediate stages.
  static gfx::Rect RectValueBetween(double value,
                                    const gfx::Rect& start,
                                    const gfx::Rect& target);

  static gfx::RectF RectFValueBetween(double value,
                                      const gfx::RectF& start,
                                      const gfx::RectF& target);

  static gfx::Transform TransformValueBetween(double value,
                                              const gfx::Transform& start,
                                              const gfx::Transform& target);

  static gfx::TransformOperations TransformOperationsValueBetween(
      double value,
      const gfx::TransformOperations& start,
      const gfx::TransformOperations& target);

  static gfx::Size SizeValueBetween(double value,
                                    const gfx::Size& start,
                                    const gfx::Size& target);

  static gfx::SizeF SizeFValueBetween(double value,
                                      const gfx::SizeF& start,
                                      const gfx::SizeF& target);

 private:
  Tween();
  ~Tween();
};

}  // namespace gfx

#endif  // UI_GFX_ANIMATION_TWEEN_H_