• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
27     DECLARE_ACE_TYPE(OverlengthDotIndicatorPaintMethod, DotIndicatorPaintMethod);
28 public:
OverlengthDotIndicatorPaintMethod(const RefPtr<OverlengthDotIndicatorModifier> & dotIndicatorModifier)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 
45     void CalculateNormalMargin(const LinearVector<float>& itemHalfSizes, const SizeF& frameSize,
46         const int32_t displayCount, const Dimension& indicatorDotItemSpace, bool ignoreSize) override;
SetMaxDisplayCount(int32_t maxDisplayCount)47     void SetMaxDisplayCount(int32_t maxDisplayCount)
48     {
49         if (maxDisplayCount >= DISPLAY_COUNT_MIN && maxDisplayCount <= DISPLAY_COUNT_MAX) {
50             maxDisplayCount_ = maxDisplayCount;
51             realItemCount_ = itemCount_;
52             itemCount_ = maxDisplayCount_ < itemCount_ ? maxDisplayCount_ + NUMBER_ONE : itemCount_;
53         }
54     }
55 
SetAnimationStartIndex(int32_t animationStartIndex)56     void SetAnimationStartIndex(int32_t animationStartIndex)
57     {
58         animationStartIndex_ = animationStartIndex;
59     }
60 
SetAnimationEndIndex(int32_t animationEndIndex)61     void SetAnimationEndIndex(int32_t animationEndIndex)
62     {
63         animationEndIndex_ = animationEndIndex;
64     }
65 
SetKeepStatus(bool keepStatus)66     void SetKeepStatus(bool keepStatus)
67     {
68         keepStatus_ = keepStatus;
69     }
70 
SetIsBindIndicator(bool isBindIndicator)71     void SetIsBindIndicator(bool isBindIndicator)
72     {
73         isBindIndicator_ = isBindIndicator;
74     }
75 
76 private:
77     std::pair<float, float> CalculatePointCenterX(const StarAndEndPointCenter& starAndEndPointCenter,
78         const LinearVector<float>& startVectorBlackPointCenterX,
79         const LinearVector<float>& endVectorBlackPointCenterX) override;
80     std::tuple<std::pair<float, float>, LinearVector<float>> CalculateLongPointCenterX(
81         const PaintWrapper* paintWrapper) override;
82     std::pair<float, float> ForwardCalculation(
83         const LinearVector<float>& itemHalfSizes, float startCenterX,
84         float endCenterX, float space, int32_t index) override;
85     void UpdateNormalIndicator(LinearVector<float>& itemHalfSizes, const PaintWrapper* paintWrapper) override;
86     void AnalysisIndexRange(int32_t& nposStation);
87 
88     RefPtr<OverlengthDotIndicatorModifier> dotIndicatorModifier_;
89     LinearVector<float> vectorBlackPointBegCenterX_ = {};
90     LinearVector<float> animationStartCenterX_ = {};
91     LinearVector<float> animationEndCenterX_ = {};
92     LinearVector<float> animationStartIndicatorWidth_ = {};
93     LinearVector<float> animationEndIndicatorWidth_ = {};
94     LinearVector<float> animationStartIndicatorHeight_ = {};
95     LinearVector<float> animationEndIndicatorHeight_ = {};
96     int32_t maxDisplayCount_ = 0;
97     int32_t realItemCount_ = 0;
98     int32_t animationStartIndex_ = 0;
99     int32_t animationEndIndex_ = 0;
100     bool keepStatus_ = false;
101     bool isBindIndicator_ = false;
102     std::pair<float, float> overlongSelectedCenterX_ = { 0.0f, 0.0f};
103     ACE_DISALLOW_COPY_AND_MOVE(OverlengthDotIndicatorPaintMethod);
104 };
105 } // namespace OHOS::Ace::NG
106 
107 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_OVER_INDICATOR_DOT_INDICATOR_PAINT_METHOD_H