180 lines
6.7 KiB
C++
180 lines
6.7 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: huangshuyi
|
|
*
|
|
* Create: 2024-8
|
|
*--------------------------------------------------------------------------*/
|
|
#include "common/screen.h"
|
|
#include "dfx/dfx_dom_dump.h"
|
|
#include "TjdUiAppCenterZoomEffect.h"
|
|
|
|
using namespace OHOS;
|
|
|
|
namespace TJD {
|
|
static constexpr float scale_max = 1.0;//middle diff
|
|
static constexpr float scale_min = 0.01;//middle diff
|
|
|
|
void TjdUiAppCenterZoomEffect::OnSwipe(UISwipeView& view)
|
|
{
|
|
//printf("OnSwipe\n");
|
|
if (preLeftCard) {
|
|
container_->UIViewGroup::Remove(screenshotViewL_);
|
|
if (preLeftCard->GetViewType() != UI_IMAGE_VIEW) {
|
|
ImageCacheFree(screenshotInfoL_);
|
|
}
|
|
delete screenshotViewL_;
|
|
screenshotViewL_ = nullptr;
|
|
preLeftCard->SetVisible(true);
|
|
preLeftCard->Invalidate();
|
|
preLeftCard->ResetTransParameter();
|
|
preLeftCard = nullptr;
|
|
}
|
|
|
|
if (preRightCard != nullptr) {
|
|
container_->UIViewGroup::Remove(screenshotViewR_);
|
|
if (preLeftCard->GetViewType() != UI_IMAGE_VIEW) {
|
|
ImageCacheFree(screenshotInfoR_);
|
|
}
|
|
delete screenshotViewR_;
|
|
screenshotViewR_ = nullptr;
|
|
preRightCard->SetVisible(true);
|
|
preRightCard->Invalidate();
|
|
preRightCard->ResetTransParameter();
|
|
preRightCard = nullptr;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppCenterZoomEffect::CommonAlg(UIView* leftCard, UIView* rightCard, int16_t xOffset)
|
|
{
|
|
#if 1
|
|
if (xOffset == 0) {
|
|
leftCard->ResetTransParameter();
|
|
rightCard->ResetTransParameter();
|
|
leftCard->SetVisible(true);
|
|
rightCard->SetVisible(true);
|
|
preLeftCard = nullptr;
|
|
preRightCard = nullptr;
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
int16_t width = Screen::GetInstance().GetWidth();
|
|
int16_t height = Screen::GetInstance().GetHeight();
|
|
int16_t middleWidth = width / 2;
|
|
int16_t middleHeight = height / 2;
|
|
if (preLeftCard != leftCard && preRightCard != rightCard) {
|
|
if (preLeftCard != nullptr) {
|
|
preLeftCard->ResetTransParameter();
|
|
}
|
|
if (preRightCard != nullptr) {
|
|
preRightCard->ResetTransParameter();
|
|
}
|
|
preLeftCard = leftCard;
|
|
preRightCard = rightCard;
|
|
|
|
if (leftCard->GetViewType() == UI_IMAGE_VIEW) {
|
|
screenshotInfoR_ = *(static_cast<UIImageView *>(rightCard)->GetImageInfo());
|
|
screenshotInfoL_ = *(static_cast<UIImageView *>(leftCard)->GetImageInfo());
|
|
} else {
|
|
rightCard->GetBitmap(screenshotInfoR_);
|
|
leftCard->GetBitmap(screenshotInfoL_);
|
|
}
|
|
|
|
if (screenshotViewR_ == nullptr) {
|
|
screenshotViewR_ = new UIImageView();
|
|
}
|
|
screenshotViewR_->SetPosition(0, 0, Screen::GetInstance().GetHeight(), Screen::GetInstance().GetWidth());
|
|
rightCard->SetVisible(false);
|
|
screenshotViewR_->SetSrc(&screenshotInfoR_);
|
|
container_->UIViewGroup::Insert(nullptr, screenshotViewR_);
|
|
|
|
if (screenshotViewL_ == nullptr) {
|
|
screenshotViewL_ = new UIImageView();
|
|
}
|
|
screenshotViewL_->SetPosition(0, 0, Screen::GetInstance().GetHeight(), Screen::GetInstance().GetWidth());
|
|
screenshotViewL_->SetSrc(&screenshotInfoL_);
|
|
leftCard->SetVisible(false);
|
|
container_->UIViewGroup::Insert(nullptr, screenshotViewL_);
|
|
|
|
}
|
|
|
|
float angle_in = 0; // 90: quarter cycle degrees
|
|
float angle_out = 0; // 90: quarter cycle degrees
|
|
|
|
float scale = 0; // 0.5: base scale value
|
|
float scaleIn = 0; // 0.5: base scale value (scale < 0)
|
|
float scaleOut = 1 + scale;
|
|
if(xOffset >= 0){
|
|
if(xOffset > middleWidth)
|
|
{
|
|
scaleIn = scale_min + (scale_max - scale_min) * (xOffset - middleWidth) / middleWidth; // 0.5: base scale value
|
|
scaleOut = 0;
|
|
}else{
|
|
scaleIn = 0; // 0.5: base scale value
|
|
scaleOut = scale_max - (scale_max - scale_min) * xOffset / middleWidth;
|
|
}
|
|
}
|
|
else{
|
|
int16_t xOffset_abs = abs(xOffset);
|
|
if(xOffset_abs > middleWidth)
|
|
{
|
|
scaleIn = scale_min + (scale_max - scale_min) * (xOffset_abs - middleWidth) / middleWidth; // 0.5: base scale value
|
|
scaleOut = 0;
|
|
}else{
|
|
scaleIn = 0; // 0.5: base scale value
|
|
scaleOut = scale_max - (scale_max - scale_min) * xOffset_abs / middleWidth;
|
|
}
|
|
}
|
|
Vector2<float> leftScaleCenter;
|
|
Vector2<float> rightScaleCenter;
|
|
leftScaleCenter.x_ = middleWidth;
|
|
//leftScaleCenter.x_ = leftCard->GetX() + leftCard->GetWidth() / 2;
|
|
leftScaleCenter.y_ = middleHeight; // 2: middle
|
|
rightScaleCenter.x_ = middleWidth;
|
|
//rightScaleCenter.x_ = rightCard->GetX() + leftCard->GetWidth() / 2;
|
|
rightScaleCenter.y_ = middleHeight; // 2: middle
|
|
// printf("middleWidth - middleHeight:%d-%d\n", middleWidth, middleHeight);
|
|
#if 0
|
|
if (xOffset > 0) {
|
|
leftCard->Scale(Vector2<float>(scaleIn, (scaleIn)), leftScaleCenter);
|
|
rightCard->Scale(Vector2<float>(scaleOut, (scaleOut)), rightScaleCenter);
|
|
// printf("xOffset:%d,angle:%f-%f\n", xOffset, angle_in, angle_out);
|
|
// printf("scale:%f-%f\n", scaleIn, scaleOut);
|
|
} else {
|
|
leftCard->Scale(Vector2<float>(scaleOut, (scaleOut)), leftScaleCenter);
|
|
rightCard->Scale(Vector2<float>(scaleIn, (scaleIn)), rightScaleCenter);
|
|
// printf("xOffset:%d,angle:%f-%f\n", xOffset, angle_in, angle_out);
|
|
// printf("scale:%f-%f\n", scaleIn, scaleOut);
|
|
}
|
|
#else
|
|
if (xOffset > 0) {
|
|
screenshotViewL_->Scale(Vector2<float>(scaleIn, (scaleIn)), leftScaleCenter);
|
|
screenshotViewR_->Scale(Vector2<float>(scaleOut, (scaleOut)), rightScaleCenter);
|
|
// printf("xOffset:%d,angle:%f-%f\n", xOffset, angle_in, angle_out);
|
|
// printf("scale:%f-%f\n", scaleIn, scaleOut);
|
|
} else {
|
|
screenshotViewL_->Scale(Vector2<float>(scaleOut, (scaleOut)), leftScaleCenter);
|
|
screenshotViewR_->Scale(Vector2<float>(scaleIn, (scaleIn)), rightScaleCenter);
|
|
// printf("xOffset:%d,angle:%f-%f\n", xOffset, angle_in, angle_out);
|
|
// printf("scale:%f-%f\n", scaleIn, scaleOut);
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
void TjdUiAppCenterZoomEffect::CardSwipeAlg(UICardPage* leftCard, UICardPage* rightCard, int16_t xOffset)
|
|
{
|
|
// printf("using no jietu style,leftCard:%s,rightCard:%s,xOffset:%d\n", leftCard->GetViewId(), rightCard->GetViewId(), xOffset);
|
|
CommonAlg(leftCard, rightCard, xOffset);
|
|
}
|
|
|
|
void TjdUiAppCenterZoomEffect::CardSwipeAlg(UIImageView* leftCard, UIImageView* rightCard, int16_t xOffset)
|
|
{
|
|
// printf("using jietu style:UIImageView\n");
|
|
CommonAlg(leftCard, rightCard, xOffset);
|
|
}
|
|
}
|