2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/internal/event/common/object-impl.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>
36 PropertyNotification* PropertyNotification::New(Object& object,
37 Property::Index propertyIndex,
38 Property::Type propertyType,
40 ConditionType condition,
41 RawArgumentContainer& arguments,
42 NotifyMode notifyMode,
45 return new PropertyNotification( object, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode, compare );
49 PropertyNotification::PropertyNotification(Object& object,
50 Property::Index propertyIndex,
51 Property::Type propertyType,
53 ConditionType condition,
54 RawArgumentContainer& arguments,
55 NotifyMode notifyMode,
58 mPropertyIndex(propertyIndex),
59 mPropertyType(propertyType),
61 mComponentIndex(componentIndex),
62 mConditionType(condition),
63 mArguments(arguments),
65 mNotifyMode( Dali::PropertyNotification::Disabled ),
66 mConditionFunction(NULL)
68 SetNotifyMode(notifyMode);
70 switch(mConditionType)
72 case PropertyCondition::LessThan:
74 mConditionFunction = LessThan::GetFunction(mPropertyType);
77 case PropertyCondition::GreaterThan:
79 mConditionFunction = GreaterThan::GetFunction(mPropertyType);
82 case PropertyCondition::Inside:
84 mConditionFunction = Inside::GetFunction(mPropertyType);
87 case PropertyCondition::Outside:
89 mConditionFunction = Outside::GetFunction(mPropertyType);
92 case PropertyCondition::Step:
96 mConditionFunction = Step::GetCompareFunction(mPropertyType);
100 mConditionFunction = Step::GetFunction(mPropertyType);
104 case PropertyCondition::VariableStep:
106 mConditionFunction = VariableStep::GetFunction(mPropertyType);
109 case PropertyCondition::False:
111 mConditionFunction = PropertyNotification::EvalFalse;
116 mProperty = mObject->GetSceneObjectInputProperty( mPropertyIndex );
117 int internalComponentIndex = mObject->GetPropertyComponentIndex(mPropertyIndex);
118 if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
120 // override the one passed in
121 mComponentIndex = internalComponentIndex;
125 PropertyNotification::~PropertyNotification()
129 bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, RawArgumentContainer& arg )
134 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
136 mNotifyMode = notifyMode;
139 bool PropertyNotification::Check( BufferIndex bufferIndex )
141 bool notifyRequired = false;
142 bool currentValid = false;
144 if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex )
146 // Evaluate Condition
147 const PropertyInputAccessor component( mProperty, mComponentIndex );
148 const PropertyInputIndexer< PropertyInputAccessor > input( bufferIndex, &component );
149 currentValid = mConditionFunction(input, mArguments);
153 // Evaluate Condition
154 const PropertyInputIndexer< PropertyInputImpl > input( bufferIndex, mProperty );
155 currentValid = mConditionFunction(input, mArguments);
158 if( mValid != currentValid
159 || ( currentValid && ( ( mConditionType == PropertyCondition::Step )
160 || ( mConditionType == PropertyCondition::VariableStep ) ) ) )
162 mValid = currentValid;
163 // means don't notify so notifyRequired stays false
164 switch( mNotifyMode )
166 case Dali::PropertyNotification::Disabled:
168 // notify never, already initialized to false
171 case Dali::PropertyNotification::NotifyOnTrue:
173 notifyRequired = mValid; // notify if value is true
176 case Dali::PropertyNotification::NotifyOnFalse:
178 notifyRequired = !mValid; // notify when its false
181 case Dali::PropertyNotification::NotifyOnChanged:
183 notifyRequired = true; // notify whenever changed
189 return notifyRequired;
192 bool PropertyNotification::GetValidity() const
197 } // namespace SceneGraph
199 } // namespace Internal