64 lines
2.2 KiB
C++
64 lines
2.2 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
|
|
*
|
|
* Description: TjdPreZoomTransition.cpp
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2025-02-28
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdPreZoomTransition.h"
|
|
#include "TransitionManager.h"
|
|
#include "animator/easing_equation.h"
|
|
#include "components/root_view.h"
|
|
|
|
namespace OHOS {
|
|
static constexpr int16_t RANGE = 500;
|
|
REGIST_TRANSITION(TransitionType::TJD_TRANSITION_PRE_ZOOM, TjdPreZoomTransition, RANGE, true, true);
|
|
|
|
static int16_t g_endY = 0;
|
|
static int16_t g_targetSize = 0;
|
|
void TjdSetPreZoomParams(int16_t endY, int16_t targetSize)
|
|
{
|
|
g_endY = endY;
|
|
g_targetSize = targetSize;
|
|
}
|
|
|
|
void TjdPreZoomTransition::OnTransitionStart(UIImageView *current, UIImageView *target)
|
|
{
|
|
OHOS::RootView::GetInstance()->ClearBlurView(OHOS::RootView::GetInstance()->GetBlurView());
|
|
current_ = current;
|
|
target_ = target;
|
|
|
|
target_->SetStyle(OHOS::STYLE_IMAGE_OPA, 0);
|
|
target_->Invalidate();
|
|
RootView::GetInstance()->Remove(target);
|
|
RootView::GetInstance()->Insert(nullptr, target);
|
|
}
|
|
|
|
void TjdPreZoomTransition::TransitionAlg(uint32_t time)
|
|
{
|
|
if ((current_ == nullptr) || (target_ == nullptr)) {
|
|
return;
|
|
}
|
|
const uint32_t scaleDuration = duration_ * 2 / 3;
|
|
const uint32_t opaDuration = duration_ / 2;
|
|
float scale = EasingEquation::QuadEaseIn(466, g_targetSize, time, scaleDuration) / 466.0;
|
|
int16_t currentCenterX = current_->GetX() + current_->GetWidth() / 2;
|
|
int16_t currentCenterY = current_->GetY() + current_->GetHeight() / 2;
|
|
current_->Scale(Vector2<float>{scale, scale}, Vector2<float>{currentCenterX, currentCenterY});
|
|
|
|
int16_t moveY = EasingEquation::QuadEaseIn(0, g_endY, time, scaleDuration);
|
|
current_->SetY(moveY);
|
|
|
|
// 超过一半开始透明度变化
|
|
if (time > opaDuration) {
|
|
int16_t opa =
|
|
EasingEquation::QuadEaseIn(OHOS::OPA_TRANSPARENT, OHOS::OPA_OPAQUE, time - opaDuration, opaDuration);
|
|
target_->SetStyle(OHOS::STYLE_IMAGE_OPA, opa);
|
|
target_->Invalidate();
|
|
}
|
|
}
|
|
} // namespace OHOS
|