OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/animation/tween.h" | 5 #include "ui/gfx/animation/tween.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <float.h> | 10 #include <float.h> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 case ZERO: | 64 case ZERO: |
65 return 0; | 65 return 0; |
66 } | 66 } |
67 | 67 |
68 NOTREACHED(); | 68 NOTREACHED(); |
69 return state; | 69 return state; |
70 } | 70 } |
71 | 71 |
72 namespace { | 72 namespace { |
73 uint8 FloatToColorByte(float f) { | 73 uint8 FloatToColorByte(float f) { |
74 return std::min(std::max(ToRoundedInt(f * 255.f), 0), 255); | 74 return static_cast<uint8>( |
75 std::min(std::max(ToRoundedInt(f * 255.f), 0), 255)); | |
75 } | 76 } |
76 | 77 |
77 uint8 BlendColorComponents(uint8 start, | 78 uint8 BlendColorComponents(uint8 start, |
78 uint8 target, | 79 uint8 target, |
79 float start_alpha, | 80 float start_alpha, |
80 float target_alpha, | 81 float target_alpha, |
81 float blended_alpha, | 82 float blended_alpha, |
82 double progress) { | 83 double progress) { |
83 // Since progress can be outside [0, 1], blending can produce a value outside | 84 // Since progress can be outside [0, 1], blending can produce a value outside |
84 // [0, 255]. | 85 // [0, 255]. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 delta++; | 143 delta++; |
143 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
144 return start + static_cast<int>(value * _nextafter(delta, 0)); | 145 return start + static_cast<int>(value * _nextafter(delta, 0)); |
145 #else | 146 #else |
146 return start + static_cast<int>(value * nextafter(delta, 0)); | 147 return start + static_cast<int>(value * nextafter(delta, 0)); |
147 #endif | 148 #endif |
148 } | 149 } |
149 | 150 |
150 //static | 151 //static |
151 int Tween::LinearIntValueBetween(double value, int start, int target) { | 152 int Tween::LinearIntValueBetween(double value, int start, int target) { |
152 return std::floor(0.5 + DoubleValueBetween(value, start, target)); | 153 return static_cast<int>( |
danakj
2014/10/18 18:40:06
Can you ToFlooredInt here instead of cast+std::flo
Peter Kasting
2014/10/20 23:38:56
I can do even better and use ToRoundedInt() to eli
| |
154 std::floor(0.5 + DoubleValueBetween(value, start, target))); | |
153 } | 155 } |
154 | 156 |
155 // static | 157 // static |
156 gfx::Rect Tween::RectValueBetween(double value, | 158 gfx::Rect Tween::RectValueBetween(double value, |
157 const gfx::Rect& start_bounds, | 159 const gfx::Rect& start_bounds, |
158 const gfx::Rect& target_bounds) { | 160 const gfx::Rect& target_bounds) { |
159 return gfx::Rect( | 161 return gfx::Rect( |
160 LinearIntValueBetween(value, start_bounds.x(), target_bounds.x()), | 162 LinearIntValueBetween(value, start_bounds.x(), target_bounds.x()), |
161 LinearIntValueBetween(value, start_bounds.y(), target_bounds.y()), | 163 LinearIntValueBetween(value, start_bounds.y(), target_bounds.y()), |
162 LinearIntValueBetween(value, start_bounds.width(), target_bounds.width()), | 164 LinearIntValueBetween(value, start_bounds.width(), target_bounds.width()), |
(...skipping 11 matching lines...) Expand all Loading... | |
174 if (value <= 0.0) | 176 if (value <= 0.0) |
175 return start_transform; | 177 return start_transform; |
176 | 178 |
177 gfx::Transform to_return = end_transform; | 179 gfx::Transform to_return = end_transform; |
178 to_return.Blend(start_transform, value); | 180 to_return.Blend(start_transform, value); |
179 | 181 |
180 return to_return; | 182 return to_return; |
181 } | 183 } |
182 | 184 |
183 } // namespace gfx | 185 } // namespace gfx |
OLD | NEW |