(Animation) Added component index to allow animation of separate components of a...
[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                                                 const 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                                            const 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::False:
90     {
91       mConditionFunction = PropertyNotification::EvalFalse;
92       break;
93     }
94     default:
95     {
96       DALI_ASSERT_ALWAYS(false && "Unrecognized ConditionType");
97       break;
98     }
99   }
100
101   mProperty = mProxy->GetSceneObjectInputProperty( mPropertyIndex );
102   int internalComponentIndex = mProxy->GetPropertyComponentIndex(mPropertyIndex);
103   if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
104   {
105     // override the one passed in
106     mComponentIndex = internalComponentIndex;
107   }
108 }
109
110 PropertyNotification::~PropertyNotification()
111 {
112 }
113
114 bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, const RawArgumentContainer& arg )
115 {
116   return false;
117 }
118
119 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
120 {
121   switch(notifyMode)
122   {
123     case Dali::PropertyNotification::Disabled:
124     {
125       mNotifyValidity[0] = false;
126       mNotifyValidity[1] = false;
127       break;
128     }
129     case Dali::PropertyNotification::NotifyOnTrue:
130     {
131       mNotifyValidity[0] = false;
132       mNotifyValidity[1] = true;
133       break;
134     }
135     case Dali::PropertyNotification::NotifyOnFalse:
136     {
137       mNotifyValidity[0] = true;
138       mNotifyValidity[1] = false;
139       break;
140     }
141     case Dali::PropertyNotification::NotifyOnChanged:
142     {
143       mNotifyValidity[0] = true;
144       mNotifyValidity[1] = true;
145       break;
146     }
147   }
148 }
149
150 bool PropertyNotification::Check( BufferIndex bufferIndex )
151 {
152   bool validityChanged = false;
153   bool currentValid = false;
154
155   if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex )
156   {
157     // Evaluate Condition
158     const PropertyInputComponentAccessor component( mProperty, mComponentIndex );
159     const PropertyInputIndexer< PropertyInputComponentAccessor > input( bufferIndex, &component );
160     currentValid = mConditionFunction(input, mArguments);
161   }
162   else
163   {
164     // Evaluate Condition
165     const PropertyInputIndexer< PropertyInputImpl > input( bufferIndex, mProperty );
166     currentValid = mConditionFunction(input, mArguments);
167   }
168
169   if( mValid != currentValid )
170   {
171     mValid = currentValid;
172     validityChanged = mNotifyValidity[currentValid];
173   }
174
175   return validityChanged;
176 }
177
178 bool PropertyNotification::GetValidity() const
179 {
180   return mValid;
181 }
182
183 } // namespace SceneGraph
184
185 } // namespace Internal
186
187 } // namespace Dali