57a78eb61dafb71d3e6d7e22fc0b53f02009e353
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/internal/event/common/object-impl.h>
19 #include <dali/internal/event/animation/property-constraint.h>
20 #include <dali/internal/event/animation/property-input-accessor.h>
21 #include <dali/internal/event/animation/property-input-indexer.h>
22 #include <dali/internal/update/common/property-base.h>
23 #include <dali/internal/update/common/property-owner.h>
24 #include <dali/internal/update/common/scene-graph-property-notification.h>
25 #include <dali/internal/update/common/property-condition-functions.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35
36 PropertyNotification* PropertyNotification::New(Object& object,
37                                                 Property::Index propertyIndex,
38                                                 Property::Type propertyType,
39                                                 int componentIndex,
40                                                 ConditionType condition,
41                                                 RawArgumentContainer& arguments,
42                                                 NotifyMode notifyMode,
43                                                 bool compare)
44 {
45   return new PropertyNotification( object, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode, compare );
46 }
47
48
49 PropertyNotification::PropertyNotification(Object& object,
50                                            Property::Index propertyIndex,
51                                            Property::Type propertyType,
52                                            int componentIndex,
53                                            ConditionType condition,
54                                            RawArgumentContainer& arguments,
55                                            NotifyMode notifyMode,
56                                            bool compare)
57 : mObject(&object),
58   mPropertyIndex(propertyIndex),
59   mPropertyType(propertyType),
60   mProperty(NULL),
61   mComponentIndex(componentIndex),
62   mConditionType(condition),
63   mArguments(arguments),
64   mValid(false),
65   mNotifyMode( Dali::PropertyNotification::Disabled ),
66   mConditionFunction(NULL)
67 {
68   SetNotifyMode(notifyMode);
69
70   switch(mConditionType)
71   {
72     case PropertyCondition::LessThan:
73     {
74       mConditionFunction = LessThan::GetFunction(mPropertyType);
75       break;
76     }
77     case PropertyCondition::GreaterThan:
78     {
79       mConditionFunction = GreaterThan::GetFunction(mPropertyType);
80       break;
81     }
82     case PropertyCondition::Inside:
83     {
84       mConditionFunction = Inside::GetFunction(mPropertyType);
85       break;
86     }
87     case PropertyCondition::Outside:
88     {
89       mConditionFunction = Outside::GetFunction(mPropertyType);
90       break;
91     }
92     case PropertyCondition::Step:
93     {
94       if( compare == true )
95       {
96         mConditionFunction = Step::GetCompareFunction(mPropertyType);
97       }
98       else
99       {
100         mConditionFunction = Step::GetFunction(mPropertyType);
101       }
102       break;
103     }
104     case PropertyCondition::VariableStep:
105     {
106       mConditionFunction = VariableStep::GetFunction(mPropertyType);
107       break;
108     }
109     case PropertyCondition::False:
110     {
111       mConditionFunction = PropertyNotification::EvalFalse;
112       break;
113     }
114   }
115
116   mProperty = mObject->GetSceneObjectInputProperty( mPropertyIndex );
117   int internalComponentIndex = mObject->GetPropertyComponentIndex(mPropertyIndex);
118   if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
119   {
120     // override the one passed in
121     mComponentIndex = internalComponentIndex;
122   }
123 }
124
125 PropertyNotification::~PropertyNotification()
126 {
127 }
128
129 bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, RawArgumentContainer& arg )
130 {
131   return false;
132 }
133
134 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
135 {
136   mNotifyMode = notifyMode;
137 }
138
139 bool PropertyNotification::Check( BufferIndex bufferIndex )
140 {
141   bool notifyRequired = false;
142   bool currentValid = false;
143
144   if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex )
145   {
146     // Evaluate Condition
147     const PropertyInputAccessor component( mProperty, mComponentIndex );
148     const PropertyInputIndexer< PropertyInputAccessor > input( bufferIndex, &component );
149     currentValid = mConditionFunction(input, mArguments);
150   }
151   else
152   {
153     // Evaluate Condition
154     const PropertyInputIndexer< PropertyInputImpl > input( bufferIndex, mProperty );
155     currentValid = mConditionFunction(input, mArguments);
156   }
157
158   if( mValid != currentValid
159       || ( currentValid && ( ( mConditionType == PropertyCondition::Step )
160                         || ( mConditionType == PropertyCondition::VariableStep ) ) ) )
161   {
162     mValid = currentValid;
163     //  means don't notify so notifyRequired stays false
164     switch( mNotifyMode )
165     {
166       case Dali::PropertyNotification::Disabled:
167       {
168         // notify never, already initialized to false
169         break;
170       }
171       case Dali::PropertyNotification::NotifyOnTrue:
172       {
173         notifyRequired = mValid; // notify if value is true
174         break;
175       }
176       case Dali::PropertyNotification::NotifyOnFalse:
177       {
178         notifyRequired = !mValid; // notify when its false
179         break;
180       }
181       case Dali::PropertyNotification::NotifyOnChanged:
182       {
183         notifyRequired = true; // notify whenever changed
184         break;
185       }
186     }
187   }
188
189   return notifyRequired;
190 }
191
192 bool PropertyNotification::GetValidity() const
193 {
194   return mValid;
195 }
196
197 } // namespace SceneGraph
198
199 } // namespace Internal
200
201 } // namespace Dali