• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_PATTERN_SHAPE_CONTAINER_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SHAPE_CONTAINER_PAINT_METHOD_H
18 
19 #include "core/components_ng/pattern/shape/shape_container_paint_property.h"
20 #include "core/components_ng/render/node_paint_method.h"
21 #include "core/components_ng/pattern/shape/shape_container_modifier.h"
22 
23 namespace OHOS::Ace::NG {
24 class ACE_EXPORT ShapeContainerPaintMethod : public NodePaintMethod {
25     DECLARE_ACE_TYPE(ShapeContainerPaintMethod, NodePaintMethod);
26 public:
27     ShapeContainerPaintMethod() = delete;
28     ~ShapeContainerPaintMethod() override = default;
ShapeContainerPaintMethod(const RefPtr<class ShapeContainerModifier> & modifier)29     explicit ShapeContainerPaintMethod(const RefPtr<class ShapeContainerModifier>& modifier)
30         : shapeContainerModifier_(modifier)
31     {}
32 
UpdateContentModifier(PaintWrapper * paintWrapper)33     void UpdateContentModifier(PaintWrapper* paintWrapper) override
34     {
35         CHECK_NULL_VOID(shapeContainerModifier_);
36         CHECK_NULL_VOID(paintWrapper);
37         auto paintProperty = DynamicCast<ShapeContainerPaintProperty>(paintWrapper->GetPaintProperty());
38         CHECK_NULL_VOID(paintProperty);
39         auto mesh = paintProperty->GetImageMeshValue(ImageMesh());
40         shapeContainerModifier_->SetColumn(mesh.GetColumn());
41         shapeContainerModifier_->SetRow(mesh.GetRow());
42         const auto& meshVector = mesh.GetMesh();
43         auto linearMesh = LinearVector<float>();
44         for (const float& value : meshVector) {
45             linearMesh.emplace_back(value);
46         }
47         shapeContainerModifier_->SetMesh(linearMesh);
48         auto pixelMapInfo = paintProperty->GetPixelMapInfoValue(ImageSourceInfo());
49         shapeContainerModifier_->UpdatePixelMap(pixelMapInfo.GetPixmap());
50     }
51 
GetContentModifier(PaintWrapper *)52     RefPtr<Modifier> GetContentModifier(PaintWrapper* /* paintWrapper */) override
53     {
54         return shapeContainerModifier_;
55     }
56 
57 private:
58     RefPtr<ShapeContainerModifier> shapeContainerModifier_;
59     ACE_DISALLOW_COPY_AND_MOVE(ShapeContainerPaintMethod);
60 };
61 } // namespace OHOS::Ace::NG
62 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SHAPE_CONTAINER_PAINT_METHOD_H
63