Fix the local matrix dirty flags for transform components
[platform/core/uifw/dali-core.git] / dali / internal / update / gestures / gesture-properties.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_GESTURE_PROPERTIES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_GESTURE_PROPERTIES_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/event/common/property-input-impl.h>
24 #include <dali/public-api/object/property-types.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace SceneGraph
31 {
32 /**
33  * A template for a read only properties used by Gestures.
34  */
35 template<class T>
36 class GestureProperty : public PropertyInputImpl
37 {
38 public:
39   /**
40    * Create a read-only gesture property.
41    * @param [in] initialValue The initial value of the property.
42    */
43   GestureProperty(const T& initialValue)
44   : mValue(initialValue),
45     mInputChanged(false)
46   {
47   }
48
49   /**
50    * Create a read-only gesture property.
51    */
52   GestureProperty()
53   : mValue(),
54     mInputChanged(false)
55   {
56   }
57
58   /**
59    * Virtual destructor.
60    */
61   ~GestureProperty() override = default;
62
63   /**
64    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
65    */
66   Dali::Property::Type GetType() const override
67   {
68     return Dali::PropertyTypes::Get<T>();
69   }
70
71   /**
72    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
73    */
74   virtual bool IsClean() const
75   {
76     return !InputChanged();
77   }
78
79   /**
80    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
81    */
82   bool InputInitialized() const override
83   {
84     // A constraint cannot use the property until it has been inherited (at least once).
85     return true;
86   }
87
88   /**
89    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
90    * @note A constraint can only receive the inherited property from the previous frame.
91    */
92   bool InputChanged() const override
93   {
94     return mInputChanged;
95   }
96
97   /**
98    * @brief Resets mInputChanged back to false
99    */
100   void Reset()
101   {
102     mInputChanged = false;
103   }
104
105   /**
106    * Set the property value.
107    * @param[in] value The new property value.
108    */
109   void Set(const T& value)
110   {
111     mValue        = value;
112     mInputChanged = true;
113   }
114
115   /**
116    * Get the property value.
117    * @return The property value.
118    */
119   const T& Get() const
120   {
121     return mValue;
122   }
123
124 private:
125   // Undefined
126   GestureProperty(const GestureProperty& property);
127
128   // Undefined
129   GestureProperty& operator=(const GestureProperty& rhs);
130
131 protected:
132   T    mValue;            ///< The property value
133   bool mInputChanged : 1; ///< Whether the property has been modified
134 };
135
136 /**
137  * A read only Vector2 property used by Gestures.
138  */
139 class GesturePropertyVector2 : public GestureProperty<Vector2>
140 {
141 public:
142   /**
143    * Virtual destructor.
144    */
145   ~GesturePropertyVector2() override = default;
146
147   /**
148    * @copydoc Dali::PropertyInput::GetVector2()
149    */
150   const Vector2& GetVector2(BufferIndex bufferIndex) const override
151   {
152     return mValue;
153   }
154 };
155
156 /**
157  * A read only bool property used by Gestures.
158  */
159 class GesturePropertyBool : public GestureProperty<bool>
160 {
161 public:
162   /**
163    * Virtual destructor.
164    */
165   ~GesturePropertyBool() override = default;
166
167   /**
168    * @copydoc Dali::PropertyInput::GetBoolean()
169    */
170   const bool& GetBoolean(BufferIndex bufferIndex) const override
171   {
172     return mValue;
173   }
174 };
175
176 } // namespace SceneGraph
177
178 } // namespace Internal
179
180 } // namespace Dali
181
182 #endif // DALI_INTERNAL_SCENE_GRAPH_GESTURE_PROPERTIES_H