ui_texture_mapper.cpp 2.6 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "components/ui_texture_mapper.h"

namespace OHOS {
void UITextureMapper::TextureMapperAnimatorCallback::Callback(UIView* view)
{
    if (view == nullptr) {
        return;
    }
    UITextureMapper* mapper = static_cast<UITextureMapper*>(view);
    mapper->Callback();
}

void UITextureMapper::TextureMapperAnimatorCallback::OnStop(UIView& view)
{
    UITextureMapper& mapper = static_cast<UITextureMapper&>(view);
    if (mapper.listener_ != nullptr) {
        mapper.listener_->OnAnimatorStop(view);
    }
}

UITextureMapper::UITextureMapper()
    : animator_(&animatorCallback_, this, 0, false),
      listener_(nullptr),
      pivot_(0, 0),
      rotateCur_(0),
      rotateStart_(0),
      rotateEnd_(0),
      scaleCur_(SCALE_CONVERTION),
      scaleStart_(SCALE_CONVERTION),
      scaleEnd_(SCALE_CONVERTION),
      delayTime_(0),
      easingFunc_(EasingEquation::LinearEaseNone)
{
}

P
pssea 已提交
51
UITextureMapper::~UITextureMapper() {}
M
mamingshuai 已提交
52 53 54 55 56

void UITextureMapper::Start()
{
    rotateStart_ = rotateCur_;
    scaleStart_ = scaleCur_;
57 58 59
    float scale = static_cast<float>(scaleStart_) / SCALE_CONVERTION;
    Scale(Vector2<float>(scale, scale), pivot_);
    Rotate(rotateStart_, pivot_);
M
mamingshuai 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    animator_.Start();
}

void UITextureMapper::Cancel()
{
    animator_.Stop();
}

void UITextureMapper::Reset()
{
    Invalidate();
    ResetTransParameter();
    Invalidate();
}

void UITextureMapper::Callback()
{
    uint16_t curTime = animator_.GetRunTime();
    if (curTime >= delayTime_) {
        uint16_t actualTime = curTime - delayTime_;
        uint16_t durationTime = animator_.GetTime() - delayTime_;

        if (scaleStart_ != scaleEnd_) {
            scaleCur_ = easingFunc_(scaleStart_, scaleEnd_, actualTime, durationTime);
        }
        float scale = static_cast<float>(scaleCur_) / SCALE_CONVERTION;
        Scale(Vector2<float>(scale, scale), pivot_);

        if (rotateStart_ != rotateEnd_) {
            rotateCur_ = easingFunc_(rotateStart_, rotateEnd_, actualTime, durationTime);
        }
        Rotate(rotateCur_, pivot_);
    }
}
P
pssea 已提交
94
} // namespace OHOS