| 41 | } |
| 42 | |
| 43 | void animate::TimeLine::OnUpdate() { |
| 44 | auto currTime = CurrentTimestampAtMM(); |
| 45 | if(animInfos_.empty()) { |
| 46 | this->Stop(); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | std::for_each(animInfos_.begin(), animInfos_.end(), [&](AnimInfo &animInfo) -> void { |
| 51 | if(currTime < animInfo.startTime || animInfo.hasEnded) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if(animInfo.shape == nullptr || animInfo.shape->IsDestroyed()) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if(currTime >= animInfo.startTime && !animInfo.hasStarted) { |
| 60 | animInfo.hasStarted = true; |
| 61 | // add callback |
| 62 | } |
| 63 | |
| 64 | double t = (currTime - animInfo.startTime) / static_cast<double>(animInfo.duration); |
| 65 | t = fmax(0, fmin(t, 1.)); |
| 66 | t = erasing::DoErasing(animInfo.erasing, t); |
| 67 | |
| 68 | { |
| 69 | // OnFrame |
| 70 | if(animInfo.shape != nullptr) { |
| 71 | if(animInfo.interpolate.matrix != nullptr && animInfo.interpolate.matrix.get() != nullptr) { |
| 72 | util::Matrix value; |
| 73 | util::MatrixUtil::Reset(&value); |
| 74 | animInfo.interpolate.matrix->interval(&value, t); |
| 75 | animInfo.shape->SetMatrix(value); |
| 76 | |
| 77 | } else if(animInfo.interpolate.points != nullptr) { |
| 78 | // TODO points |
| 79 | } else if(!animInfo.interpolate.attrs.empty()) { |
| 80 | // other number attribute. |
| 81 | for(auto it = animInfo.interpolate.attrs.begin(); it != animInfo.interpolate.attrs.end(); it++) { |
| 82 | std::string attrName = it->first; |
| 83 | double v; |
| 84 | it->second->interval(&v, t); |
| 85 | animInfo.shape->UpdateAttribute(attrName, v); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if(currTime >= animInfo.endTime && !animInfo.hasEnded) { |
| 92 | std::function<void()> cb = animInfo.onEnd; |
| 93 | cb(); |
| 94 | animInfo.hasEnded = true; |
| 95 | } |
| 96 | }); |
| 97 | |
| 98 | chart_->Redraw(); |
| 99 | time_ = CurrentTimestampAtMM(); |
| 100 |
no test coverage detected