(PropertyNotification) Force a property notification from step conditions everytime...
[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     default:
105     {
106       DALI_ASSERT_ALWAYS(false && "Unrecognized ConditionType");
107       break;
108     }
109   }
110
111   mProperty = mProxy->GetSceneObjectInputProperty( mPropertyIndex );
112   int internalComponentIndex = mProxy->GetPropertyComponentIndex(mPropertyIndex);
113   if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
114   {
115     // override the one passed in
116     mComponentIndex = internalComponentIndex;
117   }
118 }
119
120 PropertyNotification::~PropertyNotification()
121 {
122 }
123
124 bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, RawArgumentContainer& arg )
125 {
126   return false;
127 }
128
129 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
130 {
131   switch(notifyMode)
132   {
133     case Dali::PropertyNotification::Disabled:
134     {
135       mNotifyValidity[0] = false;
136       mNotifyValidity[1] = false;
137       break;
138     }
139     case Dali::PropertyNotification::NotifyOnTrue:
140     {
141       mNotifyValidity[0] = false;
142       mNotifyValidity[1] = true;
143       break;
144     }
145     case Dali::PropertyNotification::NotifyOnFalse:
146     {
147       mNotifyValidity[0] = true;
148       mNotifyValidity[1] = false;
149       break;
150     }
151     case Dali::PropertyNotification::NotifyOnChanged:
152     {
153       mNotifyValidity[0] = true;
154       mNotifyValidity[1] = true;
155       break;
156     }
157   }
158 }
159
160 bool PropertyNotification::Check( BufferIndex bufferIndex )
161 {
162   bool notifyRequired = false;
163   bool currentValid = false;
164
165   if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex )
166   {
167     // Evaluate Condition
168     const PropertyInputComponentAccessor component( mProperty, mComponentIndex );
169     const PropertyInputIndexer< PropertyInputComponentAccessor > input( bufferIndex, &component );
170     currentValid = mConditionFunction(input, mArguments);
171   }
172   else
173   {
174     // Evaluate Condition
175     const PropertyInputIndexer< PropertyInputImpl > input( bufferIndex, mProperty );
176     currentValid = mConditionFunction(input, mArguments);
177   }
178
179   if( mValid != currentValid
180       || (currentValid && ((mConditionType == PropertyCondition::Step)
181                         || (mConditionType == PropertyCondition::VariableStep))) )
182   {
183     mValid = currentValid;
184     notifyRequired = mNotifyValidity[currentValid];
185   }
186
187   return notifyRequired;
188 }
189
190 bool PropertyNotification::GetValidity() const
191 {
192   return mValid;
193 }
194
195 } // namespace SceneGraph
196
197 } // namespace Internal
198
199 } // namespace Dali