/*---------------------------------------------------------------------------- * 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 "TjdUiApp3dEffect.h" using namespace OHOS; namespace TJD { static constexpr int16_t CAMERA_DISTANCE = 200; static constexpr int16_t ROTATE_DEFAULT = 0; static constexpr int16_t ROTATE_RANGE_MAX = 70; static constexpr int16_t rotate_in_start = 70; static constexpr int16_t rotate_out_start = 0; static constexpr int16_t rotate_middle = 30;//middle diff static constexpr float SCALE_DEFAULT = 0.5; static constexpr float scale_start = 0.5; static constexpr float scale_end = 1.0; static constexpr float scale_max = 1.3;//middle diff void TjdUiApp3dEffect::OnSwipe(UISwipeView& view) { //printf("OnSwipe\n"); if (preLeftCard) { //preLeftCard->SetVisible(true); preLeftCard->Invalidate(); preLeftCard->ResetTransParameter(); preLeftCard = nullptr; } if (preRightCard != nullptr) { //preRightCard->SetVisible(true); preRightCard->Invalidate(); preRightCard->ResetTransParameter(); preRightCard = nullptr; } } void TjdUiApp3dEffect::CommonAlg(UIView* leftCard, UIView* rightCard, int16_t xOffset) { #if 1 if (xOffset == 0) { leftCard->ResetTransParameter(); rightCard->ResetTransParameter(); 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; leftCard->SetCameraPosition(Vector2(middleWidth, middleHeight)); leftCard->SetCameraDistance(CAMERA_DISTANCE); rightCard->SetCameraPosition(Vector2(middleWidth, middleHeight)); rightCard->SetCameraDistance(CAMERA_DISTANCE); } float angle = ROTATE_RANGE_MAX * xOffset / width; // 90: quarter cycle degrees float angle_in = 0; // 90: quarter cycle degrees float angle_out = 0; // 90: quarter cycle degrees float scale = SCALE_DEFAULT * xOffset / width; // 0.5: base scale value float scaleIn = SCALE_DEFAULT - scale; // 0.5: base scale value (scale < 0) float scaleOut = 1 + scale; if(xOffset>=0){ if(xOffset> middleWidth){ angle_in = -(rotate_middle - (rotate_middle)*(xOffset-middleWidth) / middleWidth); angle_out = (rotate_middle + (rotate_in_start - rotate_middle) *(xOffset-middleWidth) / middleWidth); }else{ angle_in = -(rotate_in_start - (rotate_in_start - rotate_middle) *(xOffset) / middleWidth); angle_out = (rotate_middle) *(xOffset) / middleWidth; } if(xOffset > middleWidth) { scaleIn = scale_max - (scale_max - scale_end) * (xOffset - middleWidth) / middleWidth; // 0.5: base scale value scaleOut = scale_max - (scale_max - scale_start) * (xOffset - middleWidth) / middleWidth; }else{ scaleIn = scale_start + (scale_max - scale_start) * xOffset / middleWidth; // 0.5: base scale value scaleOut = scale_end + (scale_max - scale_end) * xOffset / middleWidth; } } else{ int16_t xOffset_abs = abs(xOffset); if(xOffset_abs> middleWidth){ angle_in = rotate_middle - (rotate_middle)*(xOffset_abs-middleWidth) / middleWidth; angle_out = -(rotate_middle + (rotate_in_start - rotate_middle) *(xOffset_abs-middleWidth) / middleWidth); }else{ angle_in = rotate_in_start - (rotate_in_start - rotate_middle) *(xOffset_abs) / middleWidth; angle_out = -((rotate_middle) *(xOffset_abs) / middleWidth); } if(xOffset_abs > middleWidth) { scaleIn = scale_max - (scale_max - scale_end) * (xOffset_abs - middleWidth) / middleWidth; // 0.5: base scale value scaleOut = scale_max - (scale_max - scale_start) * (xOffset_abs - middleWidth) / middleWidth; }else{ scaleIn = scale_start + (scale_max - scale_start) * xOffset_abs / middleWidth; // 0.5: base scale value scaleOut = scale_end + (scale_max - scale_end) * xOffset_abs / middleWidth; } } Vector2 leftScaleCenter; Vector2 rightScaleCenter; leftScaleCenter.x_ = leftCard->GetX() + leftCard->GetWidth(); //leftScaleCenter.x_ = leftCard->GetX() + leftCard->GetWidth() / 2; leftScaleCenter.y_ = leftCard->GetY() + leftCard->GetHeight() / 2; // 2: middle rightScaleCenter.x_ = rightCard->GetX(); //rightScaleCenter.x_ = rightCard->GetX() + leftCard->GetWidth() / 2; rightScaleCenter.y_ = rightCard->GetY() + rightCard->GetHeight() / 2; // 2: middle Vector3 LeftRotateStart = {leftScaleCenter.x_, 0, 0}; Vector3 LeftRotateEnd = {leftScaleCenter.x_, 1, 0}; Vector3 RightRotateStart = {rightScaleCenter.x_, 0, 0}; Vector3 RightRotateEnd = {rightScaleCenter.x_, 1, 0}; if (xOffset > 0) { leftCard->Scale(Vector2(scaleIn, (scaleIn)), leftScaleCenter); rightCard->Scale(Vector2(scaleOut, (scaleOut)), rightScaleCenter); if(ROTATE_DEFAULT){ leftCard->Rotate(angle-ROTATE_RANGE_MAX, LeftRotateStart, LeftRotateEnd); rightCard->Rotate(angle, RightRotateStart, RightRotateEnd); }else{ leftCard->Rotate(angle_in, LeftRotateStart, LeftRotateEnd); rightCard->Rotate(angle_out, RightRotateStart, RightRotateEnd); } // printf("xOffset:%d,angle:%f-%f\n", xOffset, angle_in, angle_out); // printf("scale:%f-%f\n", scaleIn, scaleOut); } else { leftCard->Scale(Vector2(scaleOut, (scaleOut)), leftScaleCenter); rightCard->Scale(Vector2(scaleIn, (scaleIn)), rightScaleCenter); if(ROTATE_DEFAULT){ leftCard->Rotate(angle, LeftRotateStart, LeftRotateEnd); rightCard->Rotate(angle+ROTATE_RANGE_MAX, RightRotateStart, RightRotateEnd); }else{ leftCard->Rotate(angle_out, LeftRotateStart, LeftRotateEnd); rightCard->Rotate(angle_in, RightRotateStart, RightRotateEnd); } // printf("xOffset:%d,angle:%f-%f\n", xOffset, angle_in, angle_out); // printf("scale:%f-%f\n", scaleIn, scaleOut); } return; } void TjdUiApp3dEffect::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 TjdUiApp3dEffect::CardSwipeAlg(UIImageView* leftCard, UIImageView* rightCard, int16_t xOffset) { // printf("using jietu style:UIImageView\n"); CommonAlg(leftCard, rightCard, xOffset); } }