[dali_1.0.11] Merge branch 'tizen'
[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   mNotifyMode( Dali::PropertyNotification::Disabled )
66 {
67   SetNotifyMode(notifyMode);
68
69   switch(mConditionType)
70   {
71     case PropertyCondition::LessThan:
72     {
73       mConditionFunction = LessThan::GetFunction(mPropertyType);
74       break;
75     }
76     case PropertyCondition::GreaterThan:
77     {
78       mConditionFunction = GreaterThan::GetFunction(mPropertyType);
79       break;
80     }
81     case PropertyCondition::Inside:
82     {
83       mConditionFunction = Inside::GetFunction(mPropertyType);
84       break;
85     }
86     case PropertyCondition::Outside:
87     {
88       mConditionFunction = Outside::GetFunction(mPropertyType);
89       break;
90     }
91     case PropertyCondition::Step:
92     {
93       mConditionFunction = Step::GetFunction(mPropertyType);
94       break;
95     }
96     case PropertyCondition::VariableStep:
97     {
98       mConditionFunction = VariableStep::GetFunction(mPropertyType);
99       break;
100     }
101     case PropertyCondition::False:
102     {
103       mConditionFunction = PropertyNotification::EvalFalse;
104       break;
105     }
106   }
107
108   mProperty = mProxy->GetSceneObjectInputProperty( mPropertyIndex );
109   int internalComponentIndex = mProxy->GetPropertyComponentIndex(mPropertyIndex);
110   if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
111   {
112     // override the one passed in
113     mComponentIndex = internalComponentIndex;
114   }
115 }
116
117 PropertyNotification::~PropertyNotification()
118 {
119 }
120
121 bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, RawArgumentContainer& arg )
122 {
123   return false;
124 }
125
126 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
127 {
128   mNotifyMode = notifyMode;
129 }
130
131 bool PropertyNotification::Check( BufferIndex bufferIndex )
132 {
133   bool notifyRequired = false;
134   bool currentValid = false;
135
136   if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex )
137   {
138     // Evaluate Condition
139     const PropertyInputComponentAccessor component( mProperty, mComponentIndex );
140     const PropertyInputIndexer< PropertyInputComponentAccessor > input( bufferIndex, &component );
141     currentValid = mConditionFunction(input, mArguments);
142   }
143   else
144   {
145     // Evaluate Condition
146     const PropertyInputIndexer< PropertyInputImpl > input( bufferIndex, mProperty );
147     currentValid = mConditionFunction(input, mArguments);
148   }
149
150   if( mValid != currentValid
151       || (currentValid && ((mConditionType == PropertyCondition::Step)
152                         || (mConditionType == PropertyCondition::VariableStep))) )
153   {
154     mValid = currentValid;
155     //  means don't notify so notifyRequired stays false
156     switch( mNotifyMode )
157     {
158       case Dali::PropertyNotification::Disabled:
159       {
160         // notify never, already initialized to false
161         break;
162       }
163       case Dali::PropertyNotification::NotifyOnTrue:
164       {
165         notifyRequired = mValid; // notify if value is true
166         break;
167       }
168       case Dali::PropertyNotification::NotifyOnFalse:
169       {
170         notifyRequired = !mValid; // notify when its false
171         break;
172       }
173       case Dali::PropertyNotification::NotifyOnChanged:
174       {
175         notifyRequired = true; // notify whenever changed
176         break;
177       }
178     }
179   }
180
181   return notifyRequired;
182 }
183
184 bool PropertyNotification::GetValidity() const
185 {
186   return mValid;
187 }
188
189 } // namespace SceneGraph
190
191 } // namespace Internal
192
193 } // namespace Dali