1/* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "components/ui_texture_mapper.h" 17 18namespace OHOS { 19void UITextureMapper::TextureMapperAnimatorCallback::Callback(UIView* view) 20{ 21 if (view == nullptr) { 22 return; 23 } 24 UITextureMapper* mapper = static_cast<UITextureMapper*>(view); 25 mapper->Callback(); 26} 27 28void UITextureMapper::TextureMapperAnimatorCallback::OnStop(UIView& view) 29{ 30 UITextureMapper& mapper = static_cast<UITextureMapper&>(view); 31 if (mapper.listener_ != nullptr) { 32 mapper.listener_->OnAnimatorStop(view); 33 } 34} 35 36UITextureMapper::UITextureMapper() 37 : animator_(&animatorCallback_, this, 0, false), 38 listener_(nullptr), 39 pivot_(0, 0), 40 rotateCur_(0), 41 rotateStart_(0), 42 rotateEnd_(0), 43 scaleCur_(SCALE_CONVERTION), 44 scaleStart_(SCALE_CONVERTION), 45 scaleEnd_(SCALE_CONVERTION), 46 delayTime_(0), 47 easingFunc_(EasingEquation::LinearEaseNone) 48{ 49} 50 51UITextureMapper::~UITextureMapper() {} 52 53void UITextureMapper::Start() 54{ 55 rotateStart_ = rotateCur_; 56 scaleStart_ = scaleCur_; 57 float scale = static_cast<float>(scaleStart_) / SCALE_CONVERTION; 58 Scale(Vector2<float>(scale, scale), pivot_); 59 Rotate(rotateStart_, pivot_); 60 animator_.Start(); 61} 62 63void UITextureMapper::Cancel() 64{ 65 animator_.Stop(); 66} 67 68void UITextureMapper::Reset() 69{ 70 Invalidate(); 71 ResetTransParameter(); 72 Invalidate(); 73} 74 75void UITextureMapper::Callback() 76{ 77 uint16_t curTime = animator_.GetRunTime(); 78 if (curTime >= delayTime_) { 79 uint16_t actualTime = curTime - delayTime_; 80 uint16_t durationTime = animator_.GetTime() - delayTime_; 81 82 if (scaleStart_ != scaleEnd_) { 83 scaleCur_ = easingFunc_(scaleStart_, scaleEnd_, actualTime, durationTime); 84 } 85 float scale = static_cast<float>(scaleCur_) / SCALE_CONVERTION; 86 Scale(Vector2<float>(scale, scale), pivot_); 87 88 if (rotateStart_ != rotateEnd_) { 89 rotateCur_ = easingFunc_(rotateStart_, rotateEnd_, actualTime, durationTime); 90 } 91 Rotate(rotateCur_, pivot_); 92 } 93} 94} // namespace OHOS 95