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 127 private: 128 void PaintHorizontalBubble(float vertexOffsetFromBlock, RSPath& path); 129 void PaintVerticalBubble(float vertexOffsetFromBlock, RSPath& path); 130 void PaintHorizontalBubbleSuitableAging(float vertexOffsetFromBlock, RSPath& path); 131 void PaintVerticalBubbleSuitableAging(float vertexOffsetFromBlock, RSPath& path); 132 void PaintText(DrawingContext& context); 133 void SetBubbleDisplayAnimation(); 134 void SetBubbleDisappearAnimation(); 135 void CreateParagraphAndLayout( 136 const TextStyle& textStyle, const std::string& content); 137 bool CreateParagraph(const TextStyle& textStyle, std::string content); 138 std::pair<OffsetF, float> GetBubbleVertex(); 139 140 private: 141 RefPtr<PropertyBool> tipFlag_; 142 RefPtr<PropertyOffsetF> contentOffset_; 143 RefPtr<PropertySizeF> contentSize_; 144 RefPtr<NG::Paragraph> paragraph_; 145 146 RefPtr<AnimatablePropertyFloat> sizeScale_; 147 RefPtr<AnimatablePropertyFloat> opacityScale_; 148 RefPtr<PropertyString> content_; 149 RefPtr<PropertyOffsetF> bubbleVertex_; 150 SizeF blockSize_; 151 SizeF bubbleSize_; 152 RefPtr<PropertyOffsetF> sliderGlobalOffset_; 153 OffsetF bubbleOffset_; 154 OffsetF textOffset_; 155 OffsetF vertex_; 156 bool isMask_ = false; 157 Axis axis_ = Axis::HORIZONTAL; 158 SliderModel::SliderMode sliderMode_ = SliderModelNG::SliderMode::OUTSET; 159 Color tipColor_ = Color::BLACK; 160 Color textColor_ = Color::TRANSPARENT; 161 Dimension textFontSize_; 162 std::function<std::pair<OffsetF, float>()> getBubbleVertexFunc_; 163 int32_t taskId_ = 0; 164 165 ACE_DISALLOW_COPY_AND_MOVE(SliderTipModifier); 166 }; 167 } // namespace OHOS::Ace::NG 168 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SLIDER_TIP_MODIFIER_H 169