1 #ifndef ITEM_VIEW_ORIENTATION_CONSTRAINT_H
2 #define ITEM_VIEW_ORIENTATION_CONSTRAINT_H
5 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/animation/constraint.h>
23 #include <dali/public-api/math/degree.h>
24 #include <dali/public-api/math/math-utils.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/radian.h>
27 #include <dali/public-api/math/vector3.h>
30 * @brief Constraint used to constrain the orientation of the item-view depending on the position within the layout.
32 class ItemViewOrientationConstraint
38 * @param[in] maximumRotationInDegrees The maximum rotation (in degrees) that we should rotate the item-view by.
39 * @param[in] layoutPositionChangeMultiplier This value is used to multiply the change in layout position
40 * (in order to exaggerate the amount moved so it's more visible).
42 ItemViewOrientationConstraint( float maximumRotationInDegrees, float layoutPositionChangeMultiplier )
43 : mMaximumRotationInDegrees( maximumRotationInDegrees ),
44 mLayoutPositionChangeMultiplier( layoutPositionChangeMultiplier ),
45 mStartingLayoutPosition( 0.0f ),
46 mStartingAngle( 0.0f ),
52 * @brief Will be called by the Constraint.
54 * The first time this operator is called, it uses the values as it's base reference.
55 * Thereafter, the position in the layout is used to determine the rotation around the X-Axis.
57 * @param[in] rotation The rotation of the item-view.
58 * @param[in] inputs The constraint inputs:
59 * [0] ItemView::Property::LAYOUT_POSITION, float
61 void operator()( Dali::Quaternion& rotation, const Dali::PropertyInputContainer& inputs )
63 const float& layoutPosition = inputs[ 0 ]->GetFloat();
65 // Store values for base reference when called the first call.
68 mStartingLayoutPosition = layoutPosition;
71 Dali::Radian angleInRadians;
72 rotation.ToAxisAngle( axis, angleInRadians );
73 Dali::Degree angleInDegrees( angleInRadians ); // Convert to Degrees
75 mStartingAngle = angleInDegrees.degree;
76 if( axis.x < 0.0f ) // We only rotate round the X-Axis. So if the X-Axis is negative, then the angle is also a negative angle.
78 mStartingAngle = -mStartingAngle;
85 // All subsequent calls should tilt the orientation of the item-view around the X-Axis depending on how much our position has changed in the layout.
87 Dali::Degree angle( mStartingAngle + mLayoutPositionChangeMultiplier * ( mStartingLayoutPosition - layoutPosition ) );
88 Dali::ClampInPlace( angle.degree, -mMaximumRotationInDegrees, mMaximumRotationInDegrees ); // Ensure the angle does not exceed maximum specified (in both directions).
89 rotation = Dali::Quaternion( angle, Dali::Vector3::XAXIS );
95 const float mMaximumRotationInDegrees; ///< The maximum allowable rotation of the item-view.
96 const float mLayoutPositionChangeMultiplier; ///< This value is used to multiply the change in layout position.
97 float mStartingLayoutPosition; ///< The starting layout position.
98 float mStartingAngle; ///< The starting angle (in degrees) of the item-view.
99 bool mFirstCall; ///< A boolean to state whether this is the first time the operator() is called. Allows us to set the starting values.
102 #endif // ITEM_VIEW_ORIENTATION_CONSTRAINT_H