1 /* 2 * Copyright (c) 2022-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_PAINTS_TABS_TAB_BAR_PAINT_METHOD_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_TABS_TAB_BAR_PAINT_METHOD_H 18 19 #include "core/components_ng/pattern/tabs/tab_bar_modifier.h" 20 #include "core/components_ng/pattern/tabs/tabs_model.h" 21 #include "core/components_ng/render/node_paint_method.h" 22 23 namespace OHOS::Ace::NG { 24 25 class TabBarPaintMethod : public NodePaintMethod { DECLARE_ACE_TYPE(TabBarPaintMethod,NodePaintMethod)26 DECLARE_ACE_TYPE(TabBarPaintMethod, NodePaintMethod) 27 28 public: 29 TabBarPaintMethod(const RefPtr<TabBarModifier>& tabBarModifier, 30 const std::vector<bool>& gradientRegions, const Color& backgroundColor, 31 const IndicatorStyle& indicatorStyle, const OffsetF& indicatorOffset, bool hasIndicator) 32 : tabBarModifier_(tabBarModifier), gradientRegions_(gradientRegions), 33 backgroundColor_(backgroundColor), indicatorStyle_(indicatorStyle), 34 indicatorOffset_(indicatorOffset), hasIndicator_(hasIndicator) {} 35 ~TabBarPaintMethod() override = default; 36 37 CanvasDrawFunction GetForegroundDrawFunction(PaintWrapper* paintWrapper) override; 38 RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override; 39 void UpdateContentModifier(PaintWrapper* paintWrapper) override; 40 41 private: 42 static void PaintGradient(RSCanvas& canvas, const RectF& barRect, const Color& backgroundColor, 43 const std::vector<bool>& gradientRegions, const MarginPropertyF& padding); 44 static void PaintLeftGradient(RSCanvas& context, const RectF& barRect, const Color& backgroundColor, 45 float shadowMargin, float gradientWidth, float padding); 46 static void PaintRightGradient(RSCanvas& context, const RectF& barRect, const Color& backgroundColor, 47 float shadowMargin, float gradientWidth, float padding); 48 static void PaintTopGradient(RSCanvas& context, const RectF& barRect, const Color& backgroundColor, 49 float shadowMargin, float gradientWidth); 50 static void PaintBottomGradient(RSCanvas& context, const RectF& barRect, const Color& backgroundColor, 51 float shadowMargin, float gradientWidth); 52 static void PaintGradientRect(RSCanvas& context, const RSRect& gradientRect, const Color& backgroundColor, 53 const RSPoint& startPoint, const RSPoint& endPoint, float shadowMargin, float gradientWidth); 54 55 RefPtr<TabBarModifier> tabBarModifier_; 56 std::vector<bool> gradientRegions_; 57 Color backgroundColor_; 58 IndicatorStyle indicatorStyle_; 59 OffsetF indicatorOffset_; 60 bool hasIndicator_ = true; 61 ACE_DISALLOW_COPY_AND_MOVE(TabBarPaintMethod); 62 }; 63 } // namespace OHOS::Ace::NG 64 65 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_TABS_TAB_BAR_PAINT_METHOD_H 66