Conversion to Apache 2.0 license
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.cpp
1 /*
2  * Copyright (c) 2014 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/proxy-object.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 using namespace std;
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace SceneGraph
36 {
37
38 PropertyNotification* PropertyNotification::New(ProxyObject& proxy,
39                                                 Property::Index propertyIndex,
40                                                 Property::Type propertyType,
41                                                 int componentIndex,
42                                                 ConditionType condition,
43                                                 RawArgumentContainer& arguments,
44                                                 NotifyMode notifyMode)
45 {
46   return new PropertyNotification( proxy, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode );
47 }
48
49
50 PropertyNotification::PropertyNotification(ProxyObject& proxy,
51                                            Property::Index propertyIndex,
52                                            Property::Type propertyType,
53                                            int componentIndex,
54                                            ConditionType condition,
55                                            RawArgumentContainer& arguments,
56                                            NotifyMode notifyMode)
57 : mProxy(&proxy),
58   mPropertyIndex(propertyIndex),
59   mPropertyType(propertyType),
60   mProperty(NULL),
61   mComponentIndex(componentIndex),
62   mConditionType(condition),
63   mArguments(arguments),
64   mValid(false)
65 {
66   SetNotifyMode(notifyMode);
67
68   switch(mConditionType)
69   {
70     case PropertyCondition::LessThan:
71     {
72       mConditionFunction = LessThan::GetFunction(mPropertyType);
73       break;
74     }
75     case PropertyCondition::GreaterThan:
76     {
77       mConditionFunction = GreaterThan::GetFunction(mPropertyType);
78       break;
79     }
80     case PropertyCondition::Inside:
81     {
82       mConditionFunction = Inside::GetFunction(mPropertyType);
83       break;
84     }
85     case PropertyCondition::Outside:
86     {
87       mConditionFunction = Outside::GetFunction(mPropertyType);
88       break;
89     }
90     case PropertyCondition::Step:
91     {
92       mConditionFunction = Step::GetFunction(mPropertyType);
93       break;
94     }
95     case PropertyCondition::VariableStep:
96     {
97       mConditionFunction = VariableStep::GetFunction(mPropertyType);
98       break;
99     }
100     case PropertyCondition::False:
101     {
102       mConditionFunction = PropertyNotification::EvalFalse;
103       break;
104     }
105   }
106
107   mProperty = mProxy->GetSceneObjectInputProperty( mPropertyIndex );
108   int internalComponentIndex = mProxy->GetPropertyComponentIndex(mPropertyIndex);
109   if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
110   {
111     // override the one passed in
112     mComponentIndex = internalComponentIndex;
113   }
114 }
115
116 PropertyNotification::~PropertyNotification()
117 {
118 }
119
120 bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, RawArgumentContainer& arg )
121 {
122   return false;
123 }
124
125 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
126 {
127   switch(notifyMode)
128   {
129     case Dali::PropertyNotification::Disabled:
130     {
131       mNotifyValidity[0] = false;
132       mNotifyValidity[1] = false;
133       break;
134     }
135     case Dali::PropertyNotification::NotifyOnTrue:
136     {
137       mNotifyValidity[0] = false;
138       mNotifyValidity[1] = true;
139       break;
140     }
141     case Dali::PropertyNotification::NotifyOnFalse:
142     {
143       mNotifyValidity[0] = true;
144       mNotifyValidity[1] = false;
145       break;
146     }
147     case Dali::PropertyNotification::NotifyOnChanged:
148     {
149       mNotifyValidity[0] = true;
150       mNotifyValidity[1] = true;
151       break;
152     }
153   }
154 }
155
156 bool PropertyNotification::Check( BufferIndex bufferIndex )
157 {
158   bool notifyRequired = false;
159   bool currentValid = false;
160
161   if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex )
162   {
163     // Evaluate Condition
164     const PropertyInputComponentAccessor component( mProperty, mComponentIndex );
165     const PropertyInputIndexer< PropertyInputComponentAccessor > input( bufferIndex, &component );
166     currentValid = mConditionFunction(input, mArguments);
167   }
168   else
169   {
170     // Evaluate Condition
171     const PropertyInputIndexer< PropertyInputImpl > input( bufferIndex, mProperty );
172     currentValid = mConditionFunction(input, mArguments);
173   }
174
175   if( mValid != currentValid
176       || (currentValid && ((mConditionType == PropertyCondition::Step)
177                         || (mConditionType == PropertyCondition::VariableStep))) )
178   {
179     mValid = currentValid;
180     notifyRequired = mNotifyValidity[currentValid];
181   }
182
183   return notifyRequired;
184 }
185
186 bool PropertyNotification::GetValidity() const
187 {
188   return mValid;
189 }
190
191 } // namespace SceneGraph
192
193 } // namespace Internal
194
195 } // namespace Dali