| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkTime.h" | 8 #include "SkTime.h" |
| 9 | 9 |
| 10 #ifndef SkAnimTimer_DEFINED | 10 #ifndef SkAnimTimer_DEFINED |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 * Returns 0 if the timer is stopped. | 97 * Returns 0 if the timer is stopped. |
| 98 */ | 98 */ |
| 99 SkScalar scaled(SkScalar speed, SkScalar period = 0) const { | 99 SkScalar scaled(SkScalar speed, SkScalar period = 0) const { |
| 100 double value = this->secs() * speed; | 100 double value = this->secs() * speed; |
| 101 if (period) { | 101 if (period) { |
| 102 value = ::fmod(value, SkScalarToDouble(period)); | 102 value = ::fmod(value, SkScalarToDouble(period)); |
| 103 } | 103 } |
| 104 return SkDoubleToScalar(value); | 104 return SkDoubleToScalar(value); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /** |
| 108 * Transitions from ends->mid->ends linearly over period seconds. The phase
specifies a phase |
| 109 * shift in seconds. |
| 110 */ |
| 111 SkScalar pingPong(SkScalar period, SkScalar phase, SkScalar ends, SkScalar m
id) const { |
| 112 return PingPong(this->secs(), period, phase, ends, mid); |
| 113 } |
| 114 |
| 115 /** Helper for computing a ping-pong value without a SkAnimTimer object. */ |
| 116 static SkScalar PingPong(double t, SkScalar period, SkScalar phase, SkScalar
ends, |
| 117 SkScalar mid) { |
| 118 double value = ::fmod(t + phase, period); |
| 119 double half = period / 2.0; |
| 120 double diff = ::fabs(value - half); |
| 121 return SkDoubleToScalar(ends + (1.0 - diff / half) * (mid - ends)); |
| 122 } |
| 123 |
| 107 private: | 124 private: |
| 108 double fBaseTimeNanos; | 125 double fBaseTimeNanos; |
| 109 double fCurrTimeNanos; | 126 double fCurrTimeNanos; |
| 110 State fState; | 127 State fState; |
| 111 | 128 |
| 112 void setState(State newState) { | 129 void setState(State newState) { |
| 113 switch (newState) { | 130 switch (newState) { |
| 114 case kStopped_State: | 131 case kStopped_State: |
| 115 fBaseTimeNanos = fCurrTimeNanos = 0; | 132 fBaseTimeNanos = fCurrTimeNanos = 0; |
| 116 fState = kStopped_State; | 133 fState = kStopped_State; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 133 case kRunning_State: | 150 case kRunning_State: |
| 134 break; | 151 break; |
| 135 } | 152 } |
| 136 fState = kRunning_State; | 153 fState = kRunning_State; |
| 137 break; | 154 break; |
| 138 } | 155 } |
| 139 } | 156 } |
| 140 }; | 157 }; |
| 141 | 158 |
| 142 #endif | 159 #endif |
| OLD | NEW |