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.
19 #include <dali/internal/event/animation/linear-constrainer-impl.h>
22 #include <cstring> // for strcmp
25 #include <dali/internal/event/common/property-helper.h>
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/object/property-array.h>
28 #include <dali/public-api/object/type-registry.h>
37 // Name Type writable animatable constraint-input enum for index-checking
38 DALI_PROPERTY_TABLE_BEGIN
39 DALI_PROPERTY("value", ARRAY, true, false, false, Dali::LinearConstrainer::Property::VALUE)
40 DALI_PROPERTY("progress", ARRAY, true, false, false, Dali::LinearConstrainer::Property::PROGRESS)
41 DALI_PROPERTY_TABLE_END(DEFAULT_OBJECT_PROPERTY_START_INDEX, LinearConstrainerDefaultProperties)
45 return Dali::LinearConstrainer::New();
48 TypeRegistration mType(typeid(Dali::LinearConstrainer), typeid(Dali::Handle), Create, LinearConstrainerDefaultProperties);
52 LinearConstrainer* LinearConstrainer::New()
54 return new LinearConstrainer();
57 LinearConstrainer::LinearConstrainer()
62 LinearConstrainer::~LinearConstrainer() = default;
64 Property::Value LinearConstrainer::GetDefaultProperty(Property::Index index) const
66 if(index == Dali::LinearConstrainer::Property::VALUE)
68 Property::Value value(Property::ARRAY);
69 Property::Array* array = value.GetArray();
70 uint32_t count = static_cast<uint32_t>(mValue.Size());
74 array->Reserve(count);
75 for(uint32_t i(0); i != count; ++i)
77 array->PushBack(mValue[i]);
82 else if(index == Dali::LinearConstrainer::Property::PROGRESS)
84 Property::Value value(Property::ARRAY);
85 Property::Array* array = value.GetArray();
86 uint32_t count = static_cast<uint32_t>(mProgress.Size());
90 array->Reserve(count);
91 for(uint32_t i(0); i != count; ++i)
93 array->PushBack(mProgress[i]);
99 return Property::Value();
102 Property::Value LinearConstrainer::GetDefaultPropertyCurrentValue(Property::Index index) const
104 return GetDefaultProperty(index); // Event-side only properties
107 void LinearConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
109 const Property::Array* array = propertyValue.GetArray();
112 uint32_t propertyArrayCount = static_cast<uint32_t>(array->Count());
113 if(index == Dali::LinearConstrainer::Property::VALUE)
115 mValue.Clear(); // remove old values
116 mValue.Resize(propertyArrayCount);
117 for(uint32_t i(0); i != propertyArrayCount; ++i)
119 array->GetElementAt(i).Get(mValue[i]);
122 else if(index == Dali::LinearConstrainer::Property::PROGRESS)
124 mProgress.Clear(); // remove old values
125 mProgress.Resize(propertyArrayCount);
126 for(uint32_t i(0); i != propertyArrayCount; ++i)
128 array->GetElementAt(i).Get(mProgress[i]);
134 void LinearConstrainer::Apply(Property target, Property source, const Vector2& range, const Vector2& wrap)
136 Dali::Constraint constraint = Dali::Constraint::New<float>(target.object, target.propertyIndex, LinearConstraintFunctor(mValue, mProgress, range, wrap));
137 constraint.AddSource(Dali::Source(source.object, source.propertyIndex));
139 constraint.SetTag(static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this))); // taking 32bits of this as tag
140 constraint.SetRemoveAction(Dali::Constraint::DISCARD);
143 //Start observing the object
144 Observe(target.object);
147 } // namespace Internal