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