• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef UI_GFX_ANIMATION_TWEEN_H_
6 #define UI_GFX_ANIMATION_TWEEN_H_
7 
8 #include "base/basictypes.h"
9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/gfx/gfx_export.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/transform.h"
13 
14 namespace gfx {
15 
16 class GFX_EXPORT Tween {
17  public:
18   enum Type {
19     LINEAR,        // Linear.
20     EASE_OUT,      // Fast in, slow out (default).
21     EASE_IN,       // Slow in, fast out.
22     EASE_IN_2,     // Variant of EASE_IN that starts out slower.
23     EASE_IN_OUT,   // Slow in and out, fast in the middle.
24     FAST_IN_OUT,   // Fast in and out, slow in the middle.
25     EASE_OUT_SNAP, // Fast in, slow out, snap to final value.
26     SMOOTH_IN_OUT, // Smooth, consistent speeds in and out (sine wave).
27     ZERO,          // Returns a value of 0 always.
28   };
29 
30   // Returns the value based on the tween type. |state| is from 0-1.
31   static double CalculateValue(Type type, double state);
32 
33   // Conveniences for getting a value between a start and end point.
34   static SkColor ColorValueBetween(double value, SkColor start, SkColor target);
35   static double DoubleValueBetween(double value, double start, double target);
36   static float FloatValueBetween(double value, float start, float target);
37 
38   // Interpolated between start and target, with every integer in this range
39   // given equal weight.
40   static int IntValueBetween(double value, int start, int target);
41 
42   // Interpolates between start and target as real numbers, and rounds the
43   // result to the nearest integer, with ties broken by rounding towards
44   // positive infinity. This gives start and target half the weight of the
45   // other integers in the range. This is the integer interpolation approach
46   // specified by www.w3.org/TR/css3-transitions.
47   static int LinearIntValueBetween(double value, int start, int target);
48   static gfx::Rect RectValueBetween(double value,
49                                     const gfx::Rect& start_bounds,
50                                     const gfx::Rect& target_bounds);
51   static gfx::Transform TransformValueBetween(
52       double value,
53       const gfx::Transform& start_transform,
54       const gfx::Transform& target_transform);
55 
56  private:
57   Tween();
58   ~Tween();
59 
60   DISALLOW_COPY_AND_ASSIGN(Tween);
61 };
62 
63 }  // namespace gfx
64 
65 #endif  // UI_GFX_ANIMATION_TWEEN_H_
66