Merge "Clean up the code to build successfully on macOS" into devel/master
[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) 2019 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/public-api/object/property-types.h>
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/event/common/property-input-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 namespace SceneGraph
33 {
34
35 /**
36  * A template for a read only properties used by Gestures.
37  */
38 template < class T >
39 class GestureProperty : public PropertyInputImpl
40 {
41 public:
42
43   /**
44    * Create a read-only gesture property.
45    * @param [in] initialValue The initial value of the property.
46    */
47   GestureProperty( const T& initialValue )
48   : mValue( initialValue ),
49     mInputChanged( false )
50   {
51   }
52
53   /**
54    * Create a read-only gesture property.
55    */
56   GestureProperty()
57   : mValue(),
58     mInputChanged( false )
59   {
60   }
61
62   /**
63    * Virtual destructor.
64    */
65   ~GestureProperty() override = default;
66
67   /**
68    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
69    */
70   Dali::Property::Type GetType() const override
71   {
72     return Dali::PropertyTypes::Get< T >();
73   }
74
75   /**
76    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
77    */
78   virtual bool IsClean() const
79   {
80     return !InputChanged();
81   }
82
83   /**
84    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
85    */
86   bool InputInitialized() const override
87   {
88     // A constraint cannot use the property until it has been inherited (at least once).
89     return true;
90   }
91
92   /**
93    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
94    * @note A constraint can only receive the inherited property from the previous frame.
95    */
96   bool InputChanged() const override
97   {
98     return mInputChanged;
99   }
100
101   /**
102    * @brief Resets mInputChanged back to false
103    */
104   void Reset()
105   {
106     mInputChanged = false;
107   }
108
109   /**
110    * Set the property value.
111    * @param[in] value The new property value.
112    */
113   void Set(const T& value)
114   {
115     mValue = value;
116     mInputChanged = true;
117   }
118
119   /**
120    * Get the property value.
121    * @return The property value.
122    */
123   const T& Get() const
124   {
125     return mValue;
126   }
127
128 private:
129
130   // Undefined
131   GestureProperty(const GestureProperty& property);
132
133   // Undefined
134   GestureProperty& operator=(const GestureProperty& rhs);
135
136 protected:
137
138   T mValue;             ///< The property value
139   bool mInputChanged:1; ///< Whether the property has been modified
140 };
141
142 /**
143  * A read only Vector2 property used by Gestures.
144  */
145 class GesturePropertyVector2 : public GestureProperty< Vector2 >
146 {
147 public:
148
149   /**
150    * Virtual destructor.
151    */
152   ~GesturePropertyVector2() override = default;
153
154   /**
155    * @copydoc Dali::PropertyInput::GetVector2()
156    */
157   const Vector2& GetVector2( BufferIndex bufferIndex ) const override
158   {
159     return mValue;
160   }
161 };
162
163 /**
164  * A read only bool property used by Gestures.
165  */
166 class GesturePropertyBool : public GestureProperty< bool >
167 {
168 public:
169
170   /**
171    * Virtual destructor.
172    */
173   ~GesturePropertyBool() override = default;
174
175   /**
176    * @copydoc Dali::PropertyInput::GetBoolean()
177    */
178   const bool& GetBoolean( BufferIndex bufferIndex ) const override
179   {
180     return mValue;
181   }
182 };
183
184 } // namespace SceneGraph
185
186 } // namespace Internal
187
188 } // namespace Dali
189
190 #endif // DALI_INTERNAL_SCENE_GRAPH_GESTURE_PROPERTIES_H