• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_LAYERS_GRADIENT_LAYER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_LAYERS_GRADIENT_LAYER_H
18 
19 #include "base/geometry/point.h"
20 #include "base/geometry/rect.h"
21 #include "core/components/common/properties/color.h"
22 #include "core/pipeline/layers/offset_layer.h"
23 #include "core/pipeline/layers/scene_builder.h"
24 
25 namespace OHOS::Ace::Flutter {
26 
27 class GradientLayer : public OffsetLayer {
28     DECLARE_ACE_TYPE(GradientLayer, OffsetLayer)
29 public:
30     GradientLayer() = default;
31     ~GradientLayer() override = default;
32 
33     void AddToScene(SceneBuilder& builder, double x, double y) override;
34 
35 
SetGradientRect(Rect rect)36     void SetGradientRect(Rect rect)
37     {
38         rect_ = rect;
39     }
40 
SetPoints(const std::vector<Point> & points)41     void SetPoints(const std::vector<Point>& points)
42     {
43         if (points.empty()) {
44             return;
45         }
46         points_.clear();
47         points_.insert(points_.begin(), points.begin(), points.end());
48     }
49 
SetColors(const std::vector<Color> & colors)50     void SetColors(const std::vector<Color>& colors)
51     {
52         if (colors.empty()) {
53             return;
54         }
55         colors_.clear();
56         colors_.insert(colors_.begin(), colors.begin(), colors.end());
57     }
58 
SetBlendMode(SkBlendMode blendMode)59     void SetBlendMode(SkBlendMode blendMode)
60     {
61         blendMode_ = blendMode;
62     }
63 
SetAlpha(uint8_t value)64     void SetAlpha(uint8_t value)
65     {
66         alpha_ = value;
67     }
68 
69 protected:
70     uint8_t alpha_ = 255; // default 255 that means no transparent.
71     std::vector<Point> points_;
72     std::vector<Color> colors_;
73     SkBlendMode blendMode_ = SkBlendMode::kDstIn;
74     Rect rect_;
75 };
76 
77 } // namespace OHOS::Ace::Flutter
78 
79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_LAYERS_GRADIENT_LAYER_H
80