2 * Copyright (c) 2021 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/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/event/common/object-impl.h>
22 #include <dali/internal/update/common/property-base.h>
23 #include <dali/internal/update/common/property-condition-functions.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/scene-graph-property-notification.h>
33 PropertyNotification* PropertyNotification::New(Object& object,
34 Property::Index propertyIndex,
35 Property::Type propertyType,
37 ConditionType condition,
38 RawArgumentContainer& arguments,
39 NotifyMode notifyMode,
42 return new PropertyNotification(object, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode, compare);
45 PropertyNotification::PropertyNotification(Object& object,
46 Property::Index propertyIndex,
47 Property::Type propertyType,
49 ConditionType condition,
50 RawArgumentContainer& arguments,
51 NotifyMode notifyMode,
54 mPropertyIndex(propertyIndex),
55 mPropertyType(propertyType),
57 mComponentIndex(componentIndex),
58 mConditionType(condition),
59 mArguments(arguments),
61 mNotifyMode(Dali::PropertyNotification::DISABLED),
62 mConditionFunction(nullptr)
64 SetNotifyMode(notifyMode);
66 switch(mConditionType)
68 case PropertyCondition::LessThan:
70 mConditionFunction = LessThan::GetFunction(mPropertyType);
73 case PropertyCondition::GreaterThan:
75 mConditionFunction = GreaterThan::GetFunction(mPropertyType);
78 case PropertyCondition::Inside:
80 mConditionFunction = Inside::GetFunction(mPropertyType);
83 case PropertyCondition::Outside:
85 mConditionFunction = Outside::GetFunction(mPropertyType);
88 case PropertyCondition::Step:
92 mConditionFunction = Step::GetCompareFunction(mPropertyType);
96 mConditionFunction = Step::GetFunction(mPropertyType);
100 case PropertyCondition::VariableStep:
102 mConditionFunction = VariableStep::GetFunction(mPropertyType);
105 case PropertyCondition::False:
107 mConditionFunction = PropertyNotification::EvalFalse;
112 mProperty = mObject->GetSceneObjectInputProperty(mPropertyIndex);
113 int internalComponentIndex = mObject->GetPropertyComponentIndex(mPropertyIndex);
114 if(internalComponentIndex != Property::INVALID_COMPONENT_INDEX)
116 // override the one passed in
117 mComponentIndex = internalComponentIndex;
121 PropertyNotification::~PropertyNotification() = default;
123 bool PropertyNotification::EvalFalse(const Dali::PropertyInput& value, RawArgumentContainer& arg)
128 void PropertyNotification::SetNotifyMode(NotifyMode notifyMode)
130 mNotifyMode = notifyMode;
133 bool PropertyNotification::Check(BufferIndex bufferIndex)
135 bool notifyRequired = false;
136 bool currentValid = false;
138 if(Property::INVALID_COMPONENT_INDEX != mComponentIndex)
140 // Evaluate Condition
141 const PropertyInputAccessor component(mProperty, mComponentIndex);
142 const PropertyInputIndexer<PropertyInputAccessor> input(bufferIndex, &component);
143 currentValid = mConditionFunction(input, mArguments);
147 // Evaluate Condition
148 const PropertyInputIndexer<PropertyInputImpl> input(bufferIndex, mProperty);
149 currentValid = mConditionFunction(input, mArguments);
152 if(mValid != currentValid || (currentValid && ((mConditionType == PropertyCondition::Step) || (mConditionType == PropertyCondition::VariableStep))))
154 mValid = currentValid;
155 // means don't notify so notifyRequired stays false
158 case Dali::PropertyNotification::DISABLED:
160 // notify never, already initialized to false
163 case Dali::PropertyNotification::NOTIFY_ON_TRUE:
165 notifyRequired = mValid; // notify if value is true
168 case Dali::PropertyNotification::NOTIFY_ON_FALSE:
170 notifyRequired = !mValid; // notify when its false
173 case Dali::PropertyNotification::NOTIFY_ON_CHANGED:
175 notifyRequired = true; // notify whenever changed
181 return notifyRequired;
184 bool PropertyNotification::GetValidity() const
189 } // namespace SceneGraph
191 } // namespace Internal