9bc139c474574d2c1ab22b524299c73b49f9d94e
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_NOTIFICATION_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_NOTIFICATION_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-notification.h>
23 #include <dali/devel-api/common/owner-container.h>
24 #include <dali/internal/event/common/property-notification-impl.h>
25 #include <dali/internal/update/common/property-base.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 class Object;
34 class PropertyNotification;
35
36 namespace SceneGraph
37 {
38
39 class PropertyNotification;
40
41 typedef OwnerContainer< PropertyNotification* > PropertyNotificationContainer;
42 typedef PropertyNotificationContainer::Iterator PropertyNotificationIter;
43 typedef PropertyNotificationContainer::ConstIterator PropertyNotificationConstIter;
44 typedef bool(*ConditionFunction)(const Dali::PropertyInput& value, Dali::Internal::PropertyNotification::RawArgumentContainer& args);
45
46 /**
47  * PropertyNotifications are used to inspect properties of scene graph objects, as part of a scene
48  * managers "update" phase. When a condition has been met the application receives a notification signal.
49  */
50 class PropertyNotification
51 {
52 public:
53
54   typedef Dali::PropertyNotification::NotifyMode NotifyMode;
55   typedef Dali::Internal::PropertyNotification::ConditionType ConditionType;
56   typedef Dali::Internal::PropertyNotification::RawArgumentContainer RawArgumentContainer;
57   typedef const void *(*GetPropertyFunction)( const SceneGraph::PropertyBase*, int );
58
59   /**
60    * Construct a new PropertyNotification
61    * @param[in] object The event-object for a scene-graph object to inspect.
62    * @param[in] propertyIndex The index of a property provided by the object.
63    * @param[in] propertyType The type of property we're inspecting.
64    * @param[in] componentIndex Index to the component of a complex property such as a Vector
65    * @param[in] condition The condition type (e.g. LessThan, GreaterThan...)
66    * @param[in] arguments The arguments which accompany the condition.
67    * @param[in] notifyMode The notification mode setting
68    * @param[in] compare The flag of comparing the previous and current data.
69    * @return A new PropertyNotification object.
70    */
71   static PropertyNotification* New(Object& object,
72                                    Property::Index propertyIndex,
73                                    Property::Type propertyType,
74                                    int componentIndex,
75                                    ConditionType condition,
76                                    RawArgumentContainer& arguments,
77                                    NotifyMode notifyMode,
78                                    bool compare);
79
80   /**
81    * Virtual destructor
82    */
83   virtual ~PropertyNotification();
84
85   /**
86    * Sets Notify Mode, whether to notify if the condition is true
87    * and if the condition is false.
88    *
89    * @param[in] notifyMode The notification mode setting
90    */
91   void SetNotifyMode( NotifyMode notifyMode );
92
93   /**
94    * Check this property notification condition,
95    * and if true then dispatch notification.
96    * @param[in] bufferIndex The current update buffer index.
97    * @return Whether the validity of this notification has changed.
98    */
99   bool Check( BufferIndex bufferIndex );
100
101   /**
102    * Returns the validity of the last condition check
103    *
104    * @return the validity
105    */
106   bool GetValidity() const;
107
108 protected:
109
110   /**
111    * Construct the PropertyNotification
112    * @param[in] object The event-object for a scene-graph object to inspect.
113    * @param[in] propertyIndex The index of a property provided by the object.
114    * @param[in] propertyType The type of property we're inspecting.
115    * @param[in] componentIndex Index to the component of a complex property such as a Vector
116    * @param[in] condition The condition type (e.g. LessThan, GreaterThan...)
117    * @param[in] arguments The arguments which accompany the condition.
118    * @param[in] notifyMode The notification mode setting
119    */
120   PropertyNotification(Object& object,
121                        Property::Index propertyIndex,
122                        Property::Type propertyType,
123                        int componentIndex,
124                        ConditionType condition,
125                        RawArgumentContainer& arguments,
126                        NotifyMode notifyMode,
127                        bool compare);
128
129 private:
130
131   /**
132    * Checks if bool is LessThan
133    * @param[in] value The value being examined.
134    * @param[in] arg The supplied arguments for the condition.
135    * @return Condition result (true if condition met, false if not)
136    */
137   static bool EvalFalse( const Dali::PropertyInput& value, Dali::Internal::PropertyNotification::RawArgumentContainer& arg );
138
139   // Undefined
140   PropertyNotification(const PropertyNotification&);
141
142   // Undefined
143   PropertyNotification& operator=(const PropertyNotification& rhs);
144
145 protected:
146
147   Object* mObject;                              ///< Not owned by the property notification. Valid until ObjectDestroyed() is called.
148   Property::Index mPropertyIndex;               ///< The index of this property.
149   Property::Type mPropertyType;                 ///< The type of property this is.
150   const PropertyInputImpl* mProperty;           ///< The scene graph property
151   int mComponentIndex;                          ///< Used for accessing float components of Vector3/4
152   ConditionType mConditionType;                 ///< The ConditionType
153   RawArgumentContainer mArguments;              ///< The arguments.
154   bool mValid;                                  ///< Whether this property notification is currently valid or not.
155   NotifyMode mNotifyMode;                       ///< Whether to notify on invalid and/or valid
156   ConditionFunction mConditionFunction;         ///< The Condition Function pointer to be evaluated.
157 };
158
159 } // namespace SceneGraph
160
161 } // namespace Internal
162
163 } // namespace Dali
164
165 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_NOTIFICATION_H