2 * Copyright (c) 2022 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(const PropertyInputImpl* property,
34 Property::Index propertyIndex,
35 Property::Type propertyType,
37 ConditionType condition,
38 RawArgumentContainer& arguments,
39 NotifyMode notifyMode,
42 return new PropertyNotification(property, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode, compare);
45 PropertyNotification::PropertyNotification(const PropertyInputImpl* property,
46 Property::Index propertyIndex,
47 Property::Type propertyType,
49 ConditionType condition,
50 RawArgumentContainer& arguments,
51 NotifyMode notifyMode,
53 : mPropertyIndex(propertyIndex),
54 mPropertyType(propertyType),
56 mComponentIndex(componentIndex),
57 mConditionType(condition),
58 mArguments(arguments),
60 mNotifyMode(Dali::PropertyNotification::DISABLED),
61 mConditionFunction(nullptr)
63 SetNotifyMode(notifyMode);
65 switch(mConditionType)
67 case PropertyCondition::LessThan:
69 mConditionFunction = LessThan::GetFunction(mPropertyType);
72 case PropertyCondition::GreaterThan:
74 mConditionFunction = GreaterThan::GetFunction(mPropertyType);
77 case PropertyCondition::Inside:
79 mConditionFunction = Inside::GetFunction(mPropertyType);
82 case PropertyCondition::Outside:
84 mConditionFunction = Outside::GetFunction(mPropertyType);
87 case PropertyCondition::Step:
91 mConditionFunction = Step::GetCompareFunction(mPropertyType);
95 mConditionFunction = Step::GetFunction(mPropertyType);
99 case PropertyCondition::VariableStep:
101 mConditionFunction = VariableStep::GetFunction(mPropertyType);
104 case PropertyCondition::False:
106 mConditionFunction = PropertyNotification::EvalFalse;
112 PropertyNotification::~PropertyNotification() = default;
114 bool PropertyNotification::EvalFalse(const Dali::PropertyInput& value, RawArgumentContainer& arg)
119 void PropertyNotification::SetNotifyMode(NotifyMode notifyMode)
121 mNotifyMode = notifyMode;
124 bool PropertyNotification::Check(BufferIndex bufferIndex)
126 bool notifyRequired = false;
127 bool currentValid = false;
129 if(Property::INVALID_COMPONENT_INDEX != mComponentIndex)
131 // Evaluate Condition
132 const PropertyInputAccessor component(mProperty, mComponentIndex);
133 const PropertyInputIndexer<PropertyInputAccessor> input(bufferIndex, &component);
134 currentValid = mConditionFunction(input, mArguments);
138 // Evaluate Condition
139 const PropertyInputIndexer<PropertyInputImpl> input(bufferIndex, mProperty);
140 currentValid = mConditionFunction(input, mArguments);
143 if(mValid != currentValid || (currentValid && ((mConditionType == PropertyCondition::Step) || (mConditionType == PropertyCondition::VariableStep))))
145 mValid = currentValid;
146 // means don't notify so notifyRequired stays false
149 case Dali::PropertyNotification::DISABLED:
151 // notify never, already initialized to false
154 case Dali::PropertyNotification::NOTIFY_ON_TRUE:
156 notifyRequired = mValid; // notify if value is true
159 case Dali::PropertyNotification::NOTIFY_ON_FALSE:
161 notifyRequired = !mValid; // notify when its false
164 case Dali::PropertyNotification::NOTIFY_ON_CHANGED:
166 notifyRequired = true; // notify whenever changed
172 return notifyRequired;
175 bool PropertyNotification::GetValidity() const
180 } // namespace SceneGraph
182 } // namespace Internal