| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/multi_animation.h" | 5 #include "app/multi_animation.h" |
| 6 | 6 |
| 7 // Default interval, in ms. | 7 // Default interval, in ms. |
| 8 static const int kDefaultInterval = 20; | 8 static const int kDefaultInterval = 20; |
| 9 | 9 |
| 10 static int TotalTime(const MultiAnimation::Parts& parts) { | 10 static int TotalTime(const MultiAnimation::Parts& parts) { |
| 11 int time_ms = 0; | 11 int time_ms = 0; |
| 12 for (size_t i = 0; i < parts.size(); ++i) { | 12 for (size_t i = 0; i < parts.size(); ++i) { |
| 13 DCHECK(parts[i].end_time_ms - parts[i].start_time_ms >= parts[i].time_ms); | 13 DCHECK(parts[i].end_time_ms - parts[i].start_time_ms >= parts[i].time_ms); |
| 14 time_ms += parts[i].time_ms; | 14 time_ms += parts[i].time_ms; |
| 15 } | 15 } |
| 16 return time_ms; | 16 return time_ms; |
| 17 } | 17 } |
| 18 | 18 |
| 19 MultiAnimation::MultiAnimation(const Parts& parts) | 19 MultiAnimation::MultiAnimation(const Parts& parts) |
| 20 : Animation(base::TimeDelta::FromMilliseconds(kDefaultInterval)), | 20 : Animation(base::TimeDelta::FromMilliseconds(kDefaultInterval)), |
| 21 parts_(parts), | 21 parts_(parts), |
| 22 cycle_time_ms_(TotalTime(parts)), | 22 cycle_time_ms_(TotalTime(parts)), |
| 23 current_value_(0), | 23 current_value_(0), |
| 24 current_part_index_(0) { | 24 current_part_index_(0) { |
| 25 DCHECK(!parts_.empty()); | 25 DCHECK(!parts_.empty()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 MultiAnimation::~MultiAnimation() {} |
| 29 |
| 28 void MultiAnimation::Step(base::TimeTicks time_now) { | 30 void MultiAnimation::Step(base::TimeTicks time_now) { |
| 29 double last_value = current_value_; | 31 double last_value = current_value_; |
| 30 size_t last_index = current_part_index_; | 32 size_t last_index = current_part_index_; |
| 31 | 33 |
| 32 int delta = static_cast<int>((time_now - start_time()).InMilliseconds() % | 34 int delta = static_cast<int>((time_now - start_time()).InMilliseconds() % |
| 33 cycle_time_ms_); | 35 cycle_time_ms_); |
| 34 const Part& part = GetPart(&delta, ¤t_part_index_); | 36 const Part& part = GetPart(&delta, ¤t_part_index_); |
| 35 double percent = static_cast<double>(delta + part.start_time_ms) / | 37 double percent = static_cast<double>(delta + part.start_time_ms) / |
| 36 static_cast<double>(part.end_time_ms); | 38 static_cast<double>(part.end_time_ms); |
| 37 DCHECK(percent <= 1); | 39 DCHECK(percent <= 1); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 53 return parts_[i]; | 55 return parts_[i]; |
| 54 } | 56 } |
| 55 | 57 |
| 56 *time_ms -= parts_[i].time_ms; | 58 *time_ms -= parts_[i].time_ms; |
| 57 } | 59 } |
| 58 NOTREACHED(); | 60 NOTREACHED(); |
| 59 *time_ms = 0; | 61 *time_ms = 0; |
| 60 *part_index = 0; | 62 *part_index = 0; |
| 61 return parts_[0]; | 63 return parts_[0]; |
| 62 } | 64 } |
| OLD | NEW |