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