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 103 private: 104 void DrawForApiNine(DrawingContext& context); 105 void PaintLockLineForApiNine(RSCanvas& canvas, const OffsetF& offset); 106 void PaintLockCircleForApiNine(RSCanvas& canvas, const OffsetF& offset, int32_t x, int32_t y); 107 void PaintLockLine(RSCanvas& canvas, const OffsetF& offset); 108 void PaintLockCircle(RSCanvas& canvas, const OffsetF& offset, int32_t x, int32_t y); 109 void CheckIsHoverAndPaint(RSCanvas& canvas, float offsetX, float offsetY, float radius, int32_t index); 110 void PaintCircle(RSCanvas& canvas, float offsetX, float offsetY, float radius, const RSColor& circleColor); 111 void PaintLightRing(RSCanvas& canvas, float offsetX, float offsetY, float radius, float alphaF); 112 void AddConnectedLineToPath(RSPath& path, const OffsetF& offset); 113 void AddCanceledLineToPath(RSPath& path, const OffsetF& offset); 114 void SetConnectedLineTailPoint(int32_t x, int32_t y); 115 void SetCanceledLineTailPoint(); 116 OffsetF GetConnectedLineTailPoint() const; 117 OffsetF GetCanceledLineTailPoint() const; 118 OffsetF GetPointEndByCellCenter() const; 119 120 bool CheckChoosePoint(int32_t x, int32_t y) const; 121 bool CheckChoosePointIsLastIndex(int32_t x, int32_t y, int32_t index) const; 122 void SetBackgroundCircleRadius(int32_t index); 123 void SetActiveCircleRadius(int32_t index); 124 void SetLightRingCircleRadius(int32_t index); 125 void SetLightRingAlphaF(int32_t index); 126 float GetLightRingAlphaF(int32_t index) const; 127 float GetBackgroundCircleRadius(int32_t index) const; 128 float GetActiveCircleRadius(int32_t index) const; 129 float GetLightRingCircleRadius(int32_t index) const; 130 131 OffsetF GetCircleCenterByXY(const OffsetF& offset, int32_t x, int32_t y); 132 void CreateProperties(); 133 void AttachProperties(); 134 void StartChallengeResultAnimate(); 135 void SetCircleClip(RSCanvas& canvas); 136 137 RefPtr<PropertyColor> regularColor_; 138 RefPtr<PropertyColor> selectedColor_; 139 RefPtr<PropertyColor> activeColor_; 140 RefPtr<PropertyColor> hoverColor_; 141 RefPtr<PropertyColor> wrongColor_; 142 RefPtr<PropertyColor> correctColor_; 143 RefPtr<AnimatablePropertyColor> pathColor_; 144 RefPtr<AnimatablePropertyColor> activeCircleColor_; 145 RefPtr<AnimatablePropertyOffsetF> connectedLineTailPoint_; 146 RefPtr<AnimatablePropertyOffsetF> canceledLineTailPoint_; 147 RefPtr<AnimatablePropertyColor> pointAnimateColor_; 148 RefPtr<PropertyOffsetF> offset_; 149 RefPtr<PropertyFloat> sideLength_; 150 RefPtr<PropertyFloat> circleRadius_; 151 RefPtr<PropertyFloat> pathStrokeWidth_; 152 RefPtr<PropertyFloat> activeBackgroundRadius_; 153 RefPtr<PropertyBool> isMoveEventValid_; 154 RefPtr<PropertyBool> isHover_; 155 RefPtr<PropertyBool> enableWaveEffect_; 156 RefPtr<PropertyInt> hoverIndex_; 157 std::optional<NG::PatternLockChallengeResult> challengeResult_; 158 RefPtr<PropertyOffsetF> cellCenter_; 159 std::vector<RefPtr<AnimatablePropertyFloat>> backgroundCircleRadius_; 160 std::vector<RefPtr<AnimatablePropertyFloat>> activeCircleRadius_; 161 std::vector<RefPtr<AnimatablePropertyFloat>> lightRingRadius_; 162 std::vector<RefPtr<AnimatablePropertyFloat>> lightRingAlphaF_; 163 std::vector<PatternLockCell> choosePoint_; 164 165 float scaleActiveCircleRadius_ = 1.0f; 166 float scaleBackgroundCircleRadius_ = 1.0f; 167 float scaleLightRingRadiusStart_ = 1.0f; 168 float scaleLightRingRadiusEnd_ = 1.0f; 169 float hoverRadiusScale_ = 1.0f; 170 bool isTouchDown_ = false; 171 bool needCanceledLine_ = false; 172 173 ACE_DISALLOW_COPY_AND_MOVE(PatternLockModifier); 174 }; 175 } // namespace OHOS::Ace::NG 176 177 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_MODIFIER_H 178