Commit bf1f42d60babe2ab002e6a9126020965b7abbeb1

Authored by Xiangyin Ma
1 parent 25250984

Update the AnimatedImageVisual demo

Change-Id: Ic7f90ed9cc5d59e3cdcd2741691c8d927b4e9037
examples/animated-images/animated-images-example.cpp
... ... @@ -34,6 +34,9 @@ const char* const ANIMATE_GIF_DOG( DEMO_IMAGE_DIR "dog-anim.gif" );
34 34 const char* const STATIC_GIF_LOGO( DEMO_IMAGE_DIR "dali-logo-static.gif" );
35 35 const char* const ANIMATE_GIF_LOGO( DEMO_IMAGE_DIR "dali-logo-anim.gif" );
36 36  
  37 +const char* const ANIMATE_PIXEL_AREA( "Animate PixelArea" );
  38 +const char* const ANIMATE_PIXEL_AREA_AND_SCALE( "Animate PixelArea & Scale" );
  39 +
37 40 const Vector4 DIM_COLOR( 0.85f, 0.85f, 0.85f, 0.85f );
38 41 }
39 42  
... ... @@ -67,21 +70,24 @@ public:
67 70 // Tie-in input event handlers:
68 71 stage.KeyEventSignal().Connect( this, &AnimatedImageController::OnKeyEvent );
69 72  
70   - mActorDog = CreateGifViewWithOverlayButton( STATIC_GIF_DOG );
  73 + mActorDog = CreateGifViewWithOverlayPlayButton( STATIC_GIF_DOG );
71 74 mActorDog.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
72 75 mActorDog.SetY( -100.f );
73 76 stage.Add( mActorDog );
74 77  
75   - mActorLogo = CreateGifViewWithOverlayButton( STATIC_GIF_LOGO );
  78 + mActorLogo = CreateGifViewWithOverlayPlayButton( STATIC_GIF_LOGO );
76 79 mActorLogo.SetAnchorPoint( AnchorPoint::TOP_CENTER );
77 80 mActorLogo.SetY( 100.f );
78 81 stage.Add( mActorLogo );
  82 +
  83 + mTapDetector = TapGestureDetector::New();
  84 + mTapDetector.DetectedSignal().Connect( this, &AnimatedImageController::OnTap );
79 85 }
80 86  
81 87 /**
82 88 * Create the gif image view with an overlay play button.
83 89 */
84   - Toolkit::ImageView CreateGifViewWithOverlayButton( const std::string& gifUrl )
  90 + Toolkit::ImageView CreateGifViewWithOverlayPlayButton( const std::string& gifUrl )
85 91 {
86 92 Toolkit::ImageView imageView = Toolkit::ImageView::New( gifUrl );
87 93 imageView.SetParentOrigin( ParentOrigin::CENTER );
... ... @@ -101,6 +107,32 @@ public:
101 107 return imageView;
102 108 }
103 109  
  110 + Toolkit::ImageView CreateGifViewWithAnimatePixelAreaButton( const std::string& gifUrl, WrapMode::Type wrapModeU, WrapMode::Type wrapModeV, const std::string& buttonLabel )
  111 + {
  112 + Toolkit::ImageView imageView = Toolkit::ImageView::New();
  113 + imageView.SetProperty( Toolkit::ImageView::Property::IMAGE,
  114 + Property::Map().Add( Toolkit::ImageVisual::Property::URL, gifUrl )
  115 + .Add( Toolkit::ImageVisual::Property::WRAP_MODE_U, wrapModeU )
  116 + .Add( Toolkit::ImageVisual::Property::WRAP_MODE_V, wrapModeV ));
  117 + imageView.SetParentOrigin( ParentOrigin::CENTER );
  118 +
  119 + // Create a push button, and add it as child of the image view
  120 + Toolkit::PushButton animateButton = Toolkit::PushButton::New();
  121 + animateButton.SetProperty( Toolkit::Button::Property::LABEL, buttonLabel );
  122 + animateButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  123 + animateButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
  124 + animateButton.SetY( 20.f );
  125 +
  126 + animateButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
  127 + animateButton.SetProperty( Actor::Property::INHERIT_SCALE, false );
  128 + imageView.Add( animateButton );
  129 +
  130 + mTapDetector.Attach( animateButton );
  131 + mTapDetector.Attach( imageView );
  132 +
  133 + return imageView;
  134 + }
  135 +
104 136 bool OnPlayButtonClicked( Toolkit::Button button )
105 137 {
106 138 Stage stage = Stage::GetCurrent();
... ... @@ -111,8 +143,7 @@ public:
111 143 // remove the static gif view, the play button is also removed as its child.
112 144 stage.Remove( mActorDog );
113 145  
114   - mActorDog = Toolkit::ImageView::New( ANIMATE_GIF_DOG );
115   - mActorDog.SetParentOrigin( ParentOrigin::CENTER );
  146 + mActorDog = CreateGifViewWithAnimatePixelAreaButton( ANIMATE_GIF_DOG, WrapMode::REPEAT, WrapMode::DEFAULT, ANIMATE_PIXEL_AREA_AND_SCALE );
116 147 mActorDog.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
117 148 mActorDog.SetY( -100.f );
118 149 stage.Add( mActorDog );
... ... @@ -122,8 +153,7 @@ public:
122 153 // remove the static gif view, the play button is also removed as its child.
123 154 stage.Remove( mActorLogo );
124 155  
125   - mActorLogo = Toolkit::ImageView::New( ANIMATE_GIF_LOGO );
126   - mActorLogo.SetParentOrigin( ParentOrigin::CENTER );
  156 + mActorLogo = CreateGifViewWithAnimatePixelAreaButton( ANIMATE_GIF_LOGO, WrapMode::DEFAULT, WrapMode::MIRRORED_REPEAT, ANIMATE_PIXEL_AREA );
127 157 mActorLogo.SetAnchorPoint( AnchorPoint::TOP_CENTER );
128 158 mActorLogo.SetY( 100.f );
129 159 stage.Add( mActorLogo );
... ... @@ -131,6 +161,42 @@ public:
131 161 return true;
132 162 }
133 163  
  164 + void OnTap(Dali::Actor actor, const Dali::TapGesture& tap)
  165 + {
  166 + if( actor.GetParent() == mActorDog ) // "Animate Pixel Area" button is clicked
  167 + {
  168 + Animation animation = Animation::New( 3.f );
  169 + animation.AnimateTo( Property( mActorDog, ImageView::Property::PIXEL_AREA ), Vector4( -1.0, 0.0, 3.f, 1.f ), AlphaFunction::SIN );
  170 + animation.AnimateTo( Property( mActorDog, Actor::Property::SCALE_X ), 3.f, AlphaFunction::SIN );
  171 + animation.Play();
  172 + }
  173 + else if( actor.GetParent() == mActorLogo ) // "Animate Pixel Area" button is clicked
  174 + {
  175 + Animation animation = Animation::New( 3.f );
  176 + animation.AnimateTo( Property( mActorLogo, ImageView::Property::PIXEL_AREA ), Vector4( 0.0, 1.0, 1.f, 1.f ), AlphaFunction::SIN );
  177 + animation.Play();
  178 + }
  179 + else if( actor == mActorDog ) // stop the animated gif, switch to static view
  180 + {
  181 + Stage stage = Stage::GetCurrent();
  182 + stage.Remove( mActorDog );
  183 +
  184 + mActorDog = CreateGifViewWithOverlayPlayButton( STATIC_GIF_DOG );
  185 + mActorDog.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  186 + mActorDog.SetY( -100.f );
  187 + stage.Add( mActorDog );
  188 + }
  189 + else if( actor == mActorLogo ) // stop the animated gif, switch to static view
  190 + {
  191 + Stage stage = Stage::GetCurrent();
  192 + stage.Remove( mActorLogo );
  193 +
  194 + mActorLogo = CreateGifViewWithOverlayPlayButton( STATIC_GIF_LOGO );
  195 + mActorLogo.SetAnchorPoint( AnchorPoint::TOP_CENTER );
  196 + mActorLogo.SetY( 100.f );
  197 + stage.Add( mActorLogo );
  198 + }
  199 + }
134 200  
135 201 void OnKeyEvent(const KeyEvent& event)
136 202 {
... ... @@ -147,6 +213,7 @@ private:
147 213 Application& mApplication;
148 214 Toolkit::ImageView mActorDog;
149 215 Toolkit::ImageView mActorLogo;
  216 + TapGestureDetector mTapDetector;
150 217 };
151 218  
152 219 // Entry point for Linux & Tizen applications
... ...