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