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_PATTERNS_SLIDER_SLIDER_TIP_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SLIDER_SLIDER_TIP_MODIFIER_H 18 19 #include "core/components_ng/base/modifier.h" 20 #include "core/components_ng/pattern/slider/slider_content_modifier.h" 21 #include "core/components_ng/render/paragraph.h" 22 23 namespace OHOS::Ace::NG { 24 class SliderTipModifier : public OverlayModifier { 25 DECLARE_ACE_TYPE(SliderTipModifier, OverlayModifier); 26 27 public: 28 explicit SliderTipModifier(std::function<std::pair<OffsetF, float>()> getBubbleVertexFunc); 29 ~SliderTipModifier() override; 30 31 void PaintTip(DrawingContext& context); 32 void PaintBubble(DrawingContext& context); 33 34 void onDraw(DrawingContext& context) override; 35 SetParagraph(const RefPtr<NG::Paragraph> & paragraph)36 void SetParagraph(const RefPtr<NG::Paragraph>& paragraph) 37 { 38 paragraph_ = paragraph; 39 } 40 SetBubbleVertex(const OffsetF & bubbleVertex)41 void SetBubbleVertex(const OffsetF& bubbleVertex) 42 { 43 if (bubbleVertex_) { 44 bubbleVertex_->Set(bubbleVertex); 45 } 46 } 47 SetTextFont(const Dimension & fontSize)48 void SetTextFont(const Dimension& fontSize) 49 { 50 textFontSize_ = fontSize; 51 } 52 SetContent(const std::string & content)53 void SetContent(const std::string& content) 54 { 55 if (content_) { 56 content_->Set(content); 57 } 58 } 59 SetTextColor(const Color & textColor)60 void SetTextColor(const Color& textColor) 61 { 62 textColor_ = textColor; 63 } 64 SetDirection(const Axis & axis)65 void SetDirection(const Axis& axis) 66 { 67 axis_ = axis; 68 } 69 SetTipColor(const Color & color)70 void SetTipColor(const Color& color) 71 { 72 tipColor_ = color; 73 } 74 75 void SetTipFlag(bool flag); 76 SetContentOffset(const OffsetF & contentOffset)77 void SetContentOffset(const OffsetF& contentOffset) 78 { 79 if (contentOffset_) { 80 contentOffset_->Set(contentOffset); 81 } 82 } 83 SetContentSize(const SizeF & contentSize)84 void SetContentSize(const SizeF& contentSize) 85 { 86 if (contentSize_) { 87 contentSize_->Set(contentSize); 88 } 89 } 90 SetBubbleSize(const SizeF & bubbleSize)91 void SetBubbleSize(const SizeF& bubbleSize) 92 { 93 bubbleSize_ = bubbleSize; 94 } 95 SetSliderGlobalOffset(const OffsetF & sliderGlobalOffset)96 void SetSliderGlobalOffset(const OffsetF& sliderGlobalOffset) 97 { 98 if (sliderGlobalOffset_) { 99 sliderGlobalOffset_->Set(sliderGlobalOffset); 100 } 101 } 102 SetBubbleOffset(const OffsetF & bubbleOffset)103 void SetBubbleOffset(const OffsetF& bubbleOffset) 104 { 105 bubbleOffset_ = bubbleOffset; 106 } 107 SetTextOffset(const OffsetF & textOffset)108 void SetTextOffset(const OffsetF& textOffset) 109 { 110 textOffset_ = textOffset; 111 } 112 SetSliderMode(const SliderModel::SliderMode & sliderMode)113 void SetSliderMode(const SliderModel::SliderMode& sliderMode) 114 { 115 sliderMode_ = sliderMode; 116 } 117 SetBlockSize(const SizeF & blockSize)118 void SetBlockSize(const SizeF& blockSize) 119 { 120 blockSize_ = blockSize; 121 } 122 123 void BuildParagraph(); 124 void UpdateBubbleSize(); 125 bool UpdateOverlayRect(const SizeF& frameSize); 126 void UpdateThemeParams(const RefPtr<SliderTheme>& theme); 127 128 private: 129 void PaintHorizontalBubble(float vertexOffsetFromBlock, RSPath& path); 130 void PaintVerticalBubble(float vertexOffsetFromBlock, RSPath& path); 131 void PaintHorizontalBubbleSuitableAging(float vertexOffsetFromBlock, RSPath& path); 132 void PaintVerticalBubbleSuitableAging(float vertexOffsetFromBlock, RSPath& path); 133 void PaintText(DrawingContext& context); 134 void SetBubbleDisplayAnimation(); 135 void SetBubbleDisappearAnimation(); 136 void CreateParagraphAndLayout( 137 const TextStyle& textStyle, const std::string& content); 138 bool CreateParagraph(const TextStyle& textStyle, std::string content); 139 std::pair<OffsetF, float> GetBubbleVertex(); 140 141 private: 142 RefPtr<PropertyBool> tipFlag_; 143 RefPtr<PropertyOffsetF> contentOffset_; 144 RefPtr<PropertySizeF> contentSize_; 145 RefPtr<NG::Paragraph> paragraph_; 146 147 RefPtr<AnimatablePropertyFloat> sizeScale_; 148 RefPtr<AnimatablePropertyFloat> opacityScale_; 149 RefPtr<PropertyString> content_; 150 RefPtr<PropertyOffsetF> bubbleVertex_; 151 SizeF blockSize_; 152 SizeF bubbleSize_; 153 RefPtr<PropertyOffsetF> sliderGlobalOffset_; 154 OffsetF bubbleOffset_; 155 OffsetF textOffset_; 156 OffsetF vertex_; 157 bool isMask_ = false; 158 Axis axis_ = Axis::HORIZONTAL; 159 SliderModel::SliderMode sliderMode_ = SliderModelNG::SliderMode::OUTSET; 160 Color tipColor_ = Color::BLACK; 161 Color textColor_ = Color::TRANSPARENT; 162 Dimension textFontSize_; 163 std::function<std::pair<OffsetF, float>()> getBubbleVertexFunc_; 164 int32_t taskId_ = 0; 165 int32_t tipDelayTime_ = 0; 166 167 ACE_DISALLOW_COPY_AND_MOVE(SliderTipModifier); 168 }; 169 } // namespace OHOS::Ace::NG 170 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SLIDER_TIP_MODIFIER_H 171