• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_MODIFIER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_MODIFIER_H
18 
19 #include <vector>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/geometry/ng/offset_t.h"
23 #include "base/memory/ace_type.h"
24 #include "base/memory/referenced.h"
25 #include "core/components/common/properties/color.h"
26 #include "core/components_ng/base/modifier.h"
27 #include "core/components_ng/pattern/patternlock/patternlock_challenge.h"
28 #include "core/components_ng/pattern/progress/progress_date.h"
29 #include "core/components_ng/property/property.h"
30 #include "core/components_ng/render/animation_utils.h"
31 #include "core/components_ng/render/drawing.h"
32 #include "core/components_ng/render/paint_wrapper.h"
33 
34 namespace OHOS::Ace::NG {
35 class PatternLockCell {
36 public:
37     PatternLockCell(int32_t column, int32_t row);
38     ~PatternLockCell() = default;
GetColumn()39     int32_t GetColumn() const
40     {
41         return column_;
42     }
GetRow()43     int32_t GetRow() const
44     {
45         return row_;
46     }
GetCode()47     int32_t GetCode() const
48     {
49         return code_;
50     }
51 
52 private:
53     int32_t column_;
54     int32_t row_;
55     int32_t code_;
56 };
57 
58 class PatternLockModifier : public ContentModifier {
59     DECLARE_ACE_TYPE(PatternLockModifier, ContentModifier);
60 
61 public:
62     PatternLockModifier();
63 
64     ~PatternLockModifier() override = default;
65     void onDraw(DrawingContext& context) override;
66 
67     void SetSideLength(float sideLength);
68     void SetCircleRadius(float circleRadius);
69     void SetRegularColor(const Color& regularColor);
70     void SetSelectColor(const Color& selectedColor);
71     void SetActiveColor(const Color& activeColor);
72     void SetPathColor(const LinearColor& pathColor);
73     void SetHoverColor(const Color& hoverColor);
74     void SetWrongColor(const Color& wrongColor);
75     void SetCorrectColor(const Color& correctColor);
76     void SetPathStrokeWidth(float pathStrokeWidth);
77     void SetIsMoveEventValid(bool isMoveEventValid);
78     void SetIsHover(bool isHover);
79     void SetHoverIndex(int32_t hoverIndex);
80     void SetChallengeResult(std::optional<NG::PatternLockChallengeResult>& challengeResult);
81     void SetCellCenterOffset(const OffsetF& cellCenter);
82     void SetContentOffset(const OffsetF& offset);
83     void SetChoosePoint(const std::vector<PatternLockCell>& choosePoint);
GetChoosePointCount()84     size_t GetChoosePointCount()
85     {
86         return choosePoint_.size();
87     }
88     void SetActiveCircleRadiusScale(float scale);
89     void SetBackgroundCircleRadiusScale(float scale);
90     void SetLightRingRadiusStartScale(float scale);
91     void SetLightRingRadiusEndScale(float scale);
92     void SetHoverRadiusScale(float scale);
93     void StartConnectedCircleAnimate(int32_t x, int32_t y);
94     void StartConnectedLineAnimate(int32_t x, int32_t y);
95     void StartCanceledAnimate();
96     void Reset();
97     void SetIsTouchDown(bool isTouchDown);
98     void UpdateBoundsRect();
99     void SetActiveCircleColor(const LinearColor& activeCircleColor);
100     void SetActiveBackgroundRadius(float activeBackgroundRadius);
101     void SetEnableWaveEffect(bool enableWaveEffect);
102     void SetEnableForeground(bool enableForeground);
103 
104 private:
105     void DrawForApiNine(DrawingContext& context);
106     void PaintLockLineForApiNine(RSCanvas& canvas, const OffsetF& offset);
107     void PaintLockCircleForApiNine(RSCanvas& canvas, const OffsetF& offset, int32_t x, int32_t y);
108     void PaintLockLine(RSCanvas& canvas, const OffsetF& offset);
109     void PaintLockCircle(RSCanvas& canvas, const OffsetF& offset, int32_t x, int32_t y);
110     void PaintActiveCircle(RSCanvas& canvas, const OffsetF& offset);
111     void CheckIsHoverAndPaint(RSCanvas& canvas, float offsetX, float offsetY, float radius, int32_t index);
112     void PaintCircle(RSCanvas& canvas, float offsetX, float offsetY, float radius, const RSColor& circleColor);
113     void PaintLightRing(RSCanvas& canvas, float offsetX, float offsetY, float radius, float alphaF);
114     void AddConnectedLineToPath(RSPath& path, const OffsetF& offset);
115     void AddCanceledLineToPath(RSPath& path, const OffsetF& offset);
116     void SetConnectedLineTailPoint(int32_t x, int32_t y);
117     void SetCanceledLineTailPoint();
118     OffsetF GetConnectedLineTailPoint() const;
119     OffsetF GetCanceledLineTailPoint() const;
120     OffsetF GetPointEndByCellCenter() const;
121 
122     bool CheckChoosePoint(int32_t x, int32_t y) const;
123     bool CheckChoosePointIsLastIndex(int32_t x, int32_t y, int32_t index) const;
124     void SetBackgroundCircleRadius(int32_t index);
125     void SetActiveCircleRadius(int32_t index);
126     void SetLightRingCircleRadius(int32_t index);
127     void SetLightRingAlphaF(int32_t index);
128     float GetLightRingAlphaF(int32_t index) const;
129     float GetBackgroundCircleRadius(int32_t index) const;
130     float GetActiveCircleRadius(int32_t index) const;
131     float GetLightRingCircleRadius(int32_t index) const;
132 
133     OffsetF GetCircleCenterByXY(const OffsetF& offset, int32_t x, int32_t y);
134     void CreateProperties();
135     void AttachProperties();
136     void StartChallengeResultAnimate();
137     void SetCircleClip(RSCanvas& canvas);
138 
139     RefPtr<PropertyColor> regularColor_;
140     RefPtr<PropertyColor> selectedColor_;
141     RefPtr<PropertyColor> activeColor_;
142     RefPtr<PropertyColor> hoverColor_;
143     RefPtr<PropertyColor> wrongColor_;
144     RefPtr<PropertyColor> correctColor_;
145     RefPtr<AnimatablePropertyColor> pathColor_;
146     RefPtr<AnimatablePropertyColor> activeCircleColor_;
147     RefPtr<AnimatablePropertyOffsetF> connectedLineTailPoint_;
148     RefPtr<AnimatablePropertyOffsetF> canceledLineTailPoint_;
149     RefPtr<AnimatablePropertyColor> pointAnimateColor_;
150     RefPtr<PropertyOffsetF> offset_;
151     RefPtr<PropertyFloat> sideLength_;
152     RefPtr<PropertyFloat> circleRadius_;
153     RefPtr<PropertyFloat> pathStrokeWidth_;
154     RefPtr<PropertyFloat> activeBackgroundRadius_;
155     RefPtr<PropertyBool> isMoveEventValid_;
156     RefPtr<PropertyBool> isHover_;
157     RefPtr<PropertyBool> enableWaveEffect_;
158     RefPtr<PropertyBool> enableForeground_;
159     RefPtr<PropertyInt> hoverIndex_;
160     std::optional<NG::PatternLockChallengeResult> challengeResult_;
161     RefPtr<PropertyOffsetF> cellCenter_;
162     std::vector<RefPtr<AnimatablePropertyFloat>> backgroundCircleRadius_;
163     std::vector<RefPtr<AnimatablePropertyFloat>> activeCircleRadius_;
164     std::vector<RefPtr<AnimatablePropertyFloat>> lightRingRadius_;
165     std::vector<RefPtr<AnimatablePropertyFloat>> lightRingAlphaF_;
166     std::vector<PatternLockCell> choosePoint_;
167 
168     float scaleActiveCircleRadius_ = 1.0f;
169     float scaleBackgroundCircleRadius_ = 1.0f;
170     float scaleLightRingRadiusStart_ = 1.0f;
171     float scaleLightRingRadiusEnd_ = 1.0f;
172     float hoverRadiusScale_ = 1.0f;
173     bool isTouchDown_ = false;
174     bool needCanceledLine_ = false;
175 
176     ACE_DISALLOW_COPY_AND_MOVE(PatternLockModifier);
177 };
178 } // namespace OHOS::Ace::NG
179 
180 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_MODIFIER_H
181