Commit 722e746ee785904f2bf69aef1684460ee9c08354
1 parent
fc459055
(Gestures) Added Rotation support
Change-Id: I83b0bf917c22db4b579b57277e589dd4f963d20c
Showing
2 changed files
with
57 additions
and
6 deletions
.gitignore
examples/gestures/gesture-example.cpp
| ... | ... | @@ -18,6 +18,8 @@ |
| 18 | 18 | // EXTERNAL INCLUDES |
| 19 | 19 | #include <dali-toolkit/dali-toolkit.h> |
| 20 | 20 | #include <string> |
| 21 | +#include <dali/devel-api/events/rotation-gesture.h> | |
| 22 | +#include <dali/devel-api/events/rotation-gesture-detector.h> | |
| 21 | 23 | |
| 22 | 24 | using namespace Dali; |
| 23 | 25 | using namespace Dali::Toolkit; |
| ... | ... | @@ -58,12 +60,13 @@ const float PAN_MODE_CHANGE_ANIMATION_DURATION( 0.25f ); |
| 58 | 60 | const Vector3 PAN_MODE_START_ANIMATION_SCALE( 1.2f, 1.2f, 1.0f ); |
| 59 | 61 | const Vector3 PAN_MODE_END_ANIMATION_SCALE( 0.8f, 0.8f, 1.0f ); |
| 60 | 62 | |
| 61 | -const float TAP_ANIMATION_DURATON( 0.5f ); | |
| 63 | +const float TAP_ANIMATION_DURATION( 0.5f ); | |
| 62 | 64 | const Vector4 TAP_ANIMATION_COLOR( 0.8f, 0.5, 0.2f, 0.6f ); |
| 63 | 65 | |
| 64 | 66 | const Vector3 MINIMUM_SCALE( Vector3::ONE ); |
| 65 | 67 | const Vector3 MAXIMUM_SCALE( Vector3::ONE * 2.0f ); |
| 66 | 68 | const float SCALE_BACK_ANIMATION_DURATION( 0.25f ); |
| 69 | +const float ROTATE_BACK_ANIMATION_DURATION( 0.25f ); | |
| 67 | 70 | |
| 68 | 71 | /** |
| 69 | 72 | * @brief Shows the given string between the given start and end times. |
| ... | ... | @@ -86,6 +89,7 @@ void AddHelpInfo( const std::string&& string, Actor parent, Animation animation, |
| 86 | 89 | text.SetPosition( position ); |
| 87 | 90 | text.SetOpacity( 0.0f ); |
| 88 | 91 | text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, Text::HorizontalAlignment::CENTER ); |
| 92 | + text.SetProperty( TextLabel::Property::MULTI_LINE, true ); | |
| 89 | 93 | parent.Add( text ); |
| 90 | 94 | |
| 91 | 95 | // Animate IN |
| ... | ... | @@ -177,6 +181,11 @@ private: |
| 177 | 181 | mPinchDetector.Attach( touchControl ); |
| 178 | 182 | mPinchDetector.DetectedSignal().Connect( this, &GestureExample::OnPinch ); |
| 179 | 183 | |
| 184 | + // Create a rotation gesture detector, attach the actor & connect | |
| 185 | + mRotationDetector = RotationGestureDetector::New(); | |
| 186 | + mRotationDetector.Attach( touchControl ); | |
| 187 | + mRotationDetector.DetectedSignal().Connect( this, &GestureExample::OnRotation ); | |
| 188 | + | |
| 180 | 189 | // Create an animation which shakes the actor when in Pan mode |
| 181 | 190 | mShakeAnimation = Animation::New( SHAKY_ANIMATION_DURATION ); |
| 182 | 191 | mShakeAnimation.AnimateBy( Property( touchControl, Actor::Property::ORIENTATION ), |
| ... | ... | @@ -196,9 +205,10 @@ private: |
| 196 | 205 | float startTime( 0.0f ); |
| 197 | 206 | float endTime( startTime + HELP_ANIMATION_SEGMENT_TIME ); |
| 198 | 207 | |
| 199 | - AddHelpInfo( "Tap image for animation", background, helpAnimation, startTime, endTime ); | |
| 200 | - AddHelpInfo( "Press & Hold image to drag", background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); | |
| 201 | - AddHelpInfo( "Pinch image to resize", background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); | |
| 208 | + AddHelpInfo( "Tap image for animation", background, helpAnimation, startTime, endTime ); | |
| 209 | + AddHelpInfo( "Press & Hold image to drag", background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); | |
| 210 | + AddHelpInfo( "Pinch image to resize", background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); | |
| 211 | + AddHelpInfo( "Move fingers in a circular motion on image to rotate", background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); | |
| 202 | 212 | helpAnimation.SetLooping( true ); |
| 203 | 213 | helpAnimation.Play(); |
| 204 | 214 | } |
| ... | ... | @@ -362,10 +372,11 @@ private: |
| 362 | 372 | { |
| 363 | 373 | // Do a short animation to show a tap has happened. |
| 364 | 374 | |
| 365 | - Animation anim = Animation::New( TAP_ANIMATION_DURATON ); | |
| 366 | - anim.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Degree( 360.0f ), Vector3::ZAXIS ) ); | |
| 375 | + Animation anim = Animation::New( TAP_ANIMATION_DURATION ); | |
| 376 | + anim.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( ANGLE_360, Vector3::ZAXIS ) ); | |
| 367 | 377 | anim.AnimateTo( Property( actor, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::LINEAR ); |
| 368 | 378 | anim.AnimateTo( Property( actor, Actor::Property::COLOR ), TAP_ANIMATION_COLOR, AlphaFunction::BOUNCE ); |
| 379 | + anim.AnimateTo( Property( actor, Actor::Property::POSITION ), Vector3::ZERO, AlphaFunction::EASE_OUT_SQUARE ); | |
| 369 | 380 | anim.Play(); |
| 370 | 381 | } |
| 371 | 382 | |
| ... | ... | @@ -418,6 +429,42 @@ private: |
| 418 | 429 | } |
| 419 | 430 | |
| 420 | 431 | /** |
| 432 | + * @brief Called when a rotation gesture is detected on our control. | |
| 433 | + * | |
| 434 | + * @param[in] actor The actor that's been pinched | |
| 435 | + * @param[in] rotation The rotation gesture information | |
| 436 | + */ | |
| 437 | + void OnRotation( Actor actor, const RotationGesture& rotation ) | |
| 438 | + { | |
| 439 | + switch( rotation.state ) | |
| 440 | + { | |
| 441 | + case Gesture::Started: | |
| 442 | + { | |
| 443 | + // Starting orientation is required so that we know what to multiply the rotation.rotation by. | |
| 444 | + mStartingOrientation = actor.GetCurrentOrientation(); | |
| 445 | + break; | |
| 446 | + } | |
| 447 | + | |
| 448 | + case Gesture::Finished: | |
| 449 | + case Gesture::Cancelled: | |
| 450 | + { | |
| 451 | + // Do an animation to come back to go back to the original orientation. | |
| 452 | + Animation anim = Animation::New( ROTATE_BACK_ANIMATION_DURATION ); | |
| 453 | + anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion::IDENTITY, AlphaFunction::LINEAR ); | |
| 454 | + anim.Play(); | |
| 455 | + break; | |
| 456 | + } | |
| 457 | + | |
| 458 | + default: | |
| 459 | + { | |
| 460 | + break; | |
| 461 | + } | |
| 462 | + } | |
| 463 | + | |
| 464 | + actor.SetOrientation( mStartingOrientation * Quaternion( rotation.rotation, Vector3::ZAXIS ) ); | |
| 465 | + } | |
| 466 | + | |
| 467 | + /** | |
| 421 | 468 | * @brief Called when any key event is received. |
| 422 | 469 | * |
| 423 | 470 | * Will use this to quit the application if Back or the Escape key is received. |
| ... | ... | @@ -441,8 +488,10 @@ private: |
| 441 | 488 | LongPressGestureDetector mLongPressDetector; |
| 442 | 489 | TapGestureDetector mTapDetector; |
| 443 | 490 | PinchGestureDetector mPinchDetector; |
| 491 | + RotationGestureDetector mRotationDetector; | |
| 444 | 492 | |
| 445 | 493 | Vector3 mStartingScale; ///< Set to the scale of the control when pinch starts. |
| 494 | + Quaternion mStartingOrientation; ///< Set to the orientation of the control when the rotation starts. | |
| 446 | 495 | Animation mShakeAnimation; ///< "Shake" animation to show when we are in panning mode. |
| 447 | 496 | bool mPanMode = false; ///< Set to true when we have long-pressed to put us into panning mode. |
| 448 | 497 | bool mPanStarted = false; ///< Set to true to state that panning has started. | ... | ... |