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