• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "knuckle_glow_trace_system.h"
17 
18 #include "mmi_log.h"
19 
20 #undef MMI_LOG_TAG
21 #define MMI_LOG_TAG "KnuckleGlowTraceSystem"
22 
23 namespace OHOS {
24 namespace MMI {
25 namespace {
26 constexpr float BASIC_DISTANCE_BETWEEN_POINTS { 5.0f };
27 } // namespace
28 
KnuckleGlowTraceSystem(int32_t pointSize,std::shared_ptr<OHOS::Media::PixelMap> pixelMap,int32_t maxDivergenceNum)29 KnuckleGlowTraceSystem::KnuckleGlowTraceSystem(int32_t pointSize, std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
30     int32_t maxDivergenceNum) : maxDivergenceNum_(maxDivergenceNum)
31 {
32     CALL_DEBUG_ENTER;
33     CHKPV(pixelMap);
34     for (int32_t i = 0; i < pointSize; ++i) {
35         divergentPoints_.emplace_back(std::make_shared<KnuckleDivergentPoint>(pixelMap));
36         glowPoints_.emplace_back(std::make_shared<KnuckleGlowPoint>(pixelMap));
37     }
38 }
39 
Clear()40 void KnuckleGlowTraceSystem::Clear()
41 {
42     CALL_DEBUG_ENTER;
43     for (const auto &divergentPoint : divergentPoints_) {
44         CHKPC(divergentPoint);
45         divergentPoint->Clear();
46     }
47 }
48 
Update()49 void KnuckleGlowTraceSystem::Update()
50 {
51     CALL_DEBUG_ENTER;
52     for (size_t i = 0; i < glowPoints_.size(); i++) {
53         CHKPC(glowPoints_[i]);
54         CHKPC(divergentPoints_[i]);
55         glowPoints_[i]->Update();
56         divergentPoints_[i]->Update();
57     }
58 }
59 
Draw(Rosen::ExtendRecordingCanvas * canvas)60 void KnuckleGlowTraceSystem::Draw(Rosen::ExtendRecordingCanvas* canvas)
61 {
62     CALL_DEBUG_ENTER;
63     for (size_t i = 0; i < glowPoints_.size(); ++i) {
64         std::shared_ptr<KnuckleDivergentPoint> divergentPoint = divergentPoints_[i];
65         std::shared_ptr<KnuckleGlowPoint> glowPoint = glowPoints_[i];
66         if (divergentPoint != nullptr) {
67             divergentPoint->Draw(canvas);
68         }
69         if (glowPoint != nullptr) {
70             glowPoint->Draw(canvas);
71         }
72     }
73 }
74 
ResetDivergentPoints(double pointX,double pointY)75 void KnuckleGlowTraceSystem::ResetDivergentPoints(double pointX, double pointY)
76 {
77     CALL_DEBUG_ENTER;
78     int32_t divergenceNum = 0;
79     for (const auto &divergentPoint : divergentPoints_) {
80         CHKPC(divergentPoint);
81         if (divergentPoint->IsEnded() && divergenceNum < maxDivergenceNum_) {
82             divergenceNum++;
83             divergentPoint->Reset(pointX, pointY);
84         }
85     }
86 }
87 
AddGlowPoints(const Rosen::Drawing::Path & path,int64_t timeInterval)88 void KnuckleGlowTraceSystem::AddGlowPoints(const Rosen::Drawing::Path &path, int64_t timeInterval)
89 {
90     CALL_DEBUG_ENTER;
91     double pathlength = path.GetLength(false);
92     Rosen::Drawing::Point pathPoints;
93     Rosen::Drawing::Point tangent;
94     float distanceFromEnd = 0;
95     float lifespanOffset = timeInterval;
96     float splitRatio = static_cast<float>(std::ceil(pathlength / BASIC_DISTANCE_BETWEEN_POINTS));
97     float baseTime = timeInterval / splitRatio;
98     for (const auto &glowPoint : glowPoints_) {
99         if (glowPoint != nullptr && glowPoint->IsEnded() && distanceFromEnd <= pathlength) {
100             if (path.GetPositionAndTangent(distanceFromEnd, pathPoints, tangent, true)) {
101                 glowPoint->Reset(pathPoints.GetX(), pathPoints.GetY(), lifespanOffset);
102                 distanceFromEnd += BASIC_DISTANCE_BETWEEN_POINTS;
103                 lifespanOffset -= baseTime;
104             }
105         }
106     }
107 }
108 } // namespace MMI
109 } // namespace OHOS
110