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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_OVER_INDICATOR_DOT_INDICATOR_PAINT_METHOD_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_OVER_INDICATOR_DOT_INDICATOR_PAINT_METHOD_H 18 19 #include "core/components_ng/pattern/swiper_indicator/dot_indicator/overlength_dot_indicator_modifier.h" 20 #include "core/components_ng/render/paint_wrapper.h" 21 #include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_paint_method.h" 22 namespace OHOS::Ace::NG { 23 constexpr int32_t DISPLAY_COUNT_MIN = 6; 24 constexpr int32_t DISPLAY_COUNT_MAX = 9; 25 constexpr int32_t NUMBER_ONE = 1; 26 class ACE_EXPORT OverlengthDotIndicatorPaintMethod : public DotIndicatorPaintMethod { DECLARE_ACE_TYPE(OverlengthDotIndicatorPaintMethod,DotIndicatorPaintMethod)27 DECLARE_ACE_TYPE(OverlengthDotIndicatorPaintMethod, DotIndicatorPaintMethod) 28 public: 29 explicit OverlengthDotIndicatorPaintMethod(const RefPtr<OverlengthDotIndicatorModifier>& dotIndicatorModifier) 30 : dotIndicatorModifier_(dotIndicatorModifier) 31 {} 32 ~OverlengthDotIndicatorPaintMethod() override = default; 33 GetContentModifier(PaintWrapper * paintWrapper)34 RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override 35 { 36 CHECK_NULL_RETURN(dotIndicatorModifier_, nullptr); 37 return dotIndicatorModifier_; 38 } 39 40 void UpdateContentModifier(PaintWrapper* paintWrapper) override; 41 void PaintNormalIndicator(const PaintWrapper* paintWrapper) override; 42 std::pair<float, float> CalculatePointCenterX( 43 const LinearVector<float>& itemHalfSizes, float margin, float padding, float space, int32_t index) override; 44 SetMaxDisplayCount(int32_t maxDisplayCount)45 void SetMaxDisplayCount(int32_t maxDisplayCount) 46 { 47 if (maxDisplayCount >= DISPLAY_COUNT_MIN && maxDisplayCount <= DISPLAY_COUNT_MAX) { 48 maxDisplayCount_ = maxDisplayCount; 49 realItemCount_ = itemCount_; 50 itemCount_ = maxDisplayCount_ < itemCount_ ? maxDisplayCount_ + NUMBER_ONE : itemCount_; 51 } 52 } 53 SetAnimationStartIndex(int32_t animationStartIndex)54 void SetAnimationStartIndex(int32_t animationStartIndex) 55 { 56 animationStartIndex_ = animationStartIndex; 57 } 58 SetAnimationEndIndex(int32_t animationEndIndex)59 void SetAnimationEndIndex(int32_t animationEndIndex) 60 { 61 animationEndIndex_ = animationEndIndex; 62 } 63 SetKeepStatus(bool keepStatus)64 void SetKeepStatus(bool keepStatus) 65 { 66 keepStatus_ = keepStatus; 67 } 68 69 private: 70 std::pair<float, float> CalculatePointCenterX(const StarAndEndPointCenter& starAndEndPointCenter, 71 const LinearVector<float>& startVectorBlackPointCenterX, 72 const LinearVector<float>& endVectorBlackPointCenterX) override; 73 std::tuple<std::pair<float, float>, LinearVector<float>> CalculateLongPointCenterX( 74 const PaintWrapper* paintWrapper) override; 75 std::pair<float, float> ForwardCalculation( 76 const LinearVector<float>& itemHalfSizes, float startCenterX, 77 float endCenterX, float space, int32_t index) override; 78 void UpdateNormalIndicator(LinearVector<float>& itemHalfSizes, const PaintWrapper* paintWrapper) override; 79 void AnalysisIndexRange(int32_t& nposStation); 80 81 RefPtr<OverlengthDotIndicatorModifier> dotIndicatorModifier_; 82 LinearVector<float> vectorBlackPointBegCenterX_ = {}; 83 LinearVector<float> animationStartCenterX_ = {}; 84 LinearVector<float> animationEndCenterX_ = {}; 85 LinearVector<float> animationStartIndicatorWidth_ = {}; 86 LinearVector<float> animationEndIndicatorWidth_ = {}; 87 LinearVector<float> animationStartIndicatorHeight_ = {}; 88 LinearVector<float> animationEndIndicatorHeight_ = {}; 89 int32_t maxDisplayCount_ = 0; 90 int32_t realItemCount_ = 0; 91 int32_t animationStartIndex_ = 0; 92 int32_t animationEndIndex_ = 0; 93 bool keepStatus_ = false; 94 std::pair<float, float> overlongSelectedCenterX_ = { 0.0f, 0.0f}; 95 ACE_DISALLOW_COPY_AND_MOVE(OverlengthDotIndicatorPaintMethod); 96 }; 97 } // namespace OHOS::Ace::NG 98 99 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_OVER_INDICATOR_DOT_INDICATOR_PAINT_METHOD_H