#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
#include "dummy-control.h"
using namespace Dali;
TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
}
+ END_TEST;
+}
+
+int UtcDaliAnimatedImageVisualPlayback(void)
+{
+ ToolkitTestApplication application;
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+
+ tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
+
+ {
+ // request AnimatedImageVisual with a property map
+ // Test with forever (-1) loop count
+ VisualFactory factory = VisualFactory::Get();
+ Visual::Base animatedImageVisual = factory.CreateVisual(
+ Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
+ .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
+ .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
+ .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
+
+ DummyControl dummyControl = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
+ dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
+ textureTrace.Enable(true);
+ Stage::GetCurrent().Add( dummyControl );
+ application.SendNotification();
+ application.Render(16);
+
+ tet_infoline( "Test that a timer has been created" );
+ DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
+
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
+
+ Property::Map attributes;
+ tet_infoline( "Test Pause action. Timer should stop after Pause action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
+
+ tet_infoline( "Test Play action. Timer should Restart after Play action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
+
+ tet_infoline( "Test Stop action. Timer should stop after Stop action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
+
+ tet_infoline( "Test Play action. Timer should Restart after Play action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
+ Test::EmitGlobalTimerSignal();
+ application.SendNotification();
+ application.Render(16);
+ DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
+
+ dummyControl.Unparent();
+ }
+
END_TEST;
}
\ No newline at end of file
--- /dev/null
+#ifndef DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_IMAGE_VISUAL_ACTIONS_DEVEL_H
+#define DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_IMAGE_VISUAL_ACTIONS_DEVEL_H
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace DevelAnimatedImageVisual
+{
+
+/**
+ * @brief Actions that the animated image visual can perform. These actions are called through the Visual::Base::DoAction API.
+ */
+namespace Action
+{
+/**
+ * @brief The available actions for this visual
+ */
+enum Type
+{
+ PLAY, ///< Play the animated GIF. This is also Default playback mode.
+ PAUSE, ///< Pause the animated GIF.
+ STOP ///< Stop the animated GIF.
+};
+
+} // namespace Action
+
+} // namespace DevelAnimatedImageVisual
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_IMAGE_VISUAL_ACTIONS_DEVEL_H
mImageSize(),
mWrapModeU( WrapMode::DEFAULT ),
mWrapModeV( WrapMode::DEFAULT ),
+ mActionStatus( DevelAnimatedImageVisual::Action::PLAY ),
mStartFirstFrame(false)
{}
// Do nothing
}
+void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, const Dali::Property::Value& attributes )
+{
+ // Check if action is valid for this visual type and perform action if possible
+
+ switch ( actionId )
+ {
+ case DevelAnimatedImageVisual::Action::PAUSE:
+ {
+ // Pause will be executed on next timer tick
+ mActionStatus = DevelAnimatedImageVisual::Action::PAUSE;
+ break;
+ }
+ case DevelAnimatedImageVisual::Action::PLAY:
+ {
+ if( IsOnStage() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY )
+ {
+ mFrameDelayTimer.Start();
+ }
+ mActionStatus = DevelAnimatedImageVisual::Action::PLAY;
+ break;
+ }
+ case DevelAnimatedImageVisual::Action::STOP:
+ {
+ // STOP reset functionality will actually be done in a future change
+ // Stop will be executed on next timer tick
+ mCurrentFrameIndex = 0;
+ mActionStatus = DevelAnimatedImageVisual::Action::STOP;
+ break;
+ }
+ }
+}
+
void AnimatedImageVisual::DoSetProperties( const Property::Map& propertyMap )
{
// url[s] already passed in from constructor
bool AnimatedImageVisual::DisplayNextFrame()
{
+ if( mActionStatus == DevelAnimatedImageVisual::Action::STOP || mActionStatus == DevelAnimatedImageVisual::Action::PAUSE )
+ {
+ return false;
+ }
if( mFrameCount > 1 )
{
// Wrap the frame index
}
TextureSet textureSet;
- if (mImageCache)
- textureSet = mImageCache->NextFrame();
- if( textureSet )
+ if( mImageCache )
{
- SetImageSize( textureSet );
- mImpl->mRenderer.SetTextures( textureSet );
+ textureSet = mImageCache->NextFrame();
+ if( textureSet )
+ {
+ SetImageSize( textureSet );
+ mImpl->mRenderer.SetTextures( textureSet );
+ }
}
// Keep timer ticking