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_PATTERN_MODEL_MODEL_POSITION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_POSITION_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/geometry/animatable_float.h"
21 
22 namespace OHOS::Ace::NG {
23 class ModelPosition : public virtual AceType {
24     DECLARE_ACE_TYPE(ModelPosition, AceType)
25 public:
26     ModelPosition() = default;
27     ~ModelPosition() override = default;
28 
ModelPosition(const ModelPosition & src)29     ModelPosition(const ModelPosition& src)
30     {
31         pos_ = Vec3(src.GetX(), src.GetY(), src.GetZ(), src.GetPosition().GetAnimationOption());
32         distance_ = src.GetDistance();
33         isAngular_ = src.GetIsAngular();
34     }
35 
36     using RenderNodeAnimationCallback = std::function<void()>;
SetContextAndCallbacks(const WeakPtr<PipelineBase> & context,RenderNodeAnimationCallback && callback)37     void SetContextAndCallbacks(
38         const WeakPtr<PipelineBase>& context,
39         RenderNodeAnimationCallback&& callback)
40     {
41         pos_.SetContextAndCallbacks(context, std::forward<RenderNodeAnimationCallback>(callback));
42         distance_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback));
43     }
44 
Set(const Vec3 & pos,AnimatableFloat distance,bool isAngular)45     void Set(const Vec3& pos, AnimatableFloat distance, bool isAngular)
46     {
47         pos_ = pos;
48         distance_ = distance;
49         isAngular_ = isAngular;
50     }
51 
SetPosition(const Vec3 & pos)52     void SetPosition(const Vec3& pos)
53     {
54         pos_ = pos;
55     }
56 
SetDistance(const AnimatableFloat & distance)57     void SetDistance(const AnimatableFloat& distance)
58     {
59         distance_ = distance;
60     }
61 
SetIsAngular(bool isAngular)62     void SetIsAngular(bool isAngular)
63     {
64         isAngular_ = isAngular;
65     }
66 
GetPosition()67     const Vec3& GetPosition() const
68     {
69         return pos_;
70     }
71 
GetX()72     float GetX() const
73     {
74         return pos_.GetX();
75     }
76 
GetY()77     float GetY() const
78     {
79         return pos_.GetY();
80     }
81 
GetZ()82     float GetZ() const
83     {
84         return pos_.GetZ();
85     }
86 
GetDistance()87     const AnimatableFloat& GetDistance() const
88     {
89         return distance_;
90     }
91 
GetIsAngular()92     bool GetIsAngular() const
93     {
94         return isAngular_;
95     }
96 
97 private:
98     Vec3 pos_ { 0.0f, 0.0f, 4.0f };
99     AnimatableFloat distance_ { std::numeric_limits<float>::max() };
100     bool isAngular_ = false;
101 };
102 } // namespace OHOS::Ace::NG
103 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_POSITION_H
104