-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2014 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.
+ *
+ */
#include <sstream>
#include <iomanip>
-#include "../shared/view.h"
+#include "shared/view.h"
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/shader-effects/motion-blur-effect.h>
+#include <dali-toolkit/devel-api/controls/popup/popup.h>
using namespace Dali;
using namespace Dali::Toolkit;
-using namespace std;
const char* BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "background-default.png";
const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char* LAYOUT_IMAGE( DALI_IMAGE_DIR "icon_mode.png" );
+const char* LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-change.png" );
const char* APPLICATION_TITLE( "Motion Blur" );
-const char* ANIM_START_ICON( DALI_IMAGE_DIR "icon_play_small.png" );
-const char* ANIM_STOP_ICON( DALI_IMAGE_DIR "icon_stop_small.png" );
+const char* EFFECTS_OFF_ICON( DALI_IMAGE_DIR "icon-effects-off.png" );
+const char* EFFECTS_ON_ICON( DALI_IMAGE_DIR "icon-effects-on.png" );
const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons
const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f;
const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation.
-} // unnamed namespace
+/**
+ * @brief Load an image, scaled-down to no more than the dimensions passed in.
+ *
+ * Uses SHRINK_TO_FIT which ensures the resulting image is
+ * smaller than or equal to the specified dimensions while preserving its
+ * original aspect ratio.
+ */
+ResourceImage LoadImageFittedInBox( const char * const imagePath, uint32_t maxWidth, uint32_t maxHeight )
+{
+ // Load the image nicely scaled-down to fit within the specified max width and height:
+ return ResourceImage::New( imagePath, ImageDimensions( maxWidth, maxHeight ), FittingMode::SHRINK_TO_FIT, Dali::SamplingMode::BOX_THEN_LINEAR );
+}
+} // unnamed namespace
//
*/
MotionBlurExampleApp(Application &app)
: mApplication(app),
- mActorAnimationsEnabled(false),
+ mActorEffectsEnabled(false),
mCurrentActorAnimation(0),
mCurrentImage(0)
{
mToolBar,
BACKGROUND_IMAGE_PATH,
TOOLBAR_IMAGE,
- APPLICATION_TITLE);
+ APPLICATION_TITLE );
- //Add an slideshow icon on the right of the title
- mIconAnimsStart = Image::New( ANIM_START_ICON );
- mIconAnimsStop = Image::New( ANIM_STOP_ICON );
- mActorAnimsButton = Toolkit::PushButton::New();
- mActorAnimsButton.SetBackgroundImage( mIconAnimsStart );
- mActorAnimsButton.ClickedSignal().Connect( this, &MotionBlurExampleApp::OnAnimationButtonClicked );
- mToolBar.AddControl( mActorAnimsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING);
+ //Add an effects icon on the right of the title
+ mIconEffectsOff = ResourceImage::New( EFFECTS_OFF_ICON );
+ mIconEffectsOn = ResourceImage::New( EFFECTS_ON_ICON );
+ mActorEffectsButton = Toolkit::PushButton::New();
+ mActorEffectsButton.SetBackgroundImage( mIconEffectsOff );
+ mActorEffectsButton.ClickedSignal().Connect( this, &MotionBlurExampleApp::OnEffectButtonClicked );
+ mToolBar.AddControl( mActorEffectsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING );
// Creates a mode button.
// Create a effect toggle button. (right of toolbar)
- Image imageLayout = Image::New( LAYOUT_IMAGE );
+ Image imageLayout = ResourceImage::New( LAYOUT_IMAGE );
Toolkit::PushButton layoutButton = Toolkit::PushButton::New();
layoutButton.SetBackgroundImage(imageLayout);
layoutButton.ClickedSignal().Connect( this, &MotionBlurExampleApp::OnLayoutButtonClicked);
winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
// set initial orientation
- app.GetOrientation().ChangedSignal().Connect( this, &MotionBlurExampleApp::OnOrientationChanged );
- unsigned int degrees = app.GetOrientation().GetDegrees();
+ winHandle.GetOrientation().ChangedSignal().Connect( this, &MotionBlurExampleApp::OnOrientationChanged );
+ unsigned int degrees = winHandle.GetOrientation().GetDegrees();
Rotate( static_cast< DeviceOrientation >( degrees ) );
// Motion blurred actor
//
- Image image = Image::New( MOTION_BLUR_ACTOR_IMAGE1 );
+ // Scale down actor to fit on very low resolution screens with space to interact:
+ Size stageSize = Stage::GetCurrent().GetSize();
+ mMotionBlurActorSize = Size( std::min( stageSize.x * 0.3f, MOTION_BLUR_ACTOR_WIDTH ), std::min( stageSize.y * 0.3f, MOTION_BLUR_ACTOR_HEIGHT ) );
+ mMotionBlurActorSize = Size( std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ), std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ) );
+
+ Image image = LoadImageFittedInBox( MOTION_BLUR_ACTOR_IMAGE1, mMotionBlurActorSize.x, mMotionBlurActorSize.y );
mMotionBlurImageActor = ImageActor::New(image);
mMotionBlurImageActor.SetParentOrigin( ParentOrigin::CENTER );
- mMotionBlurImageActor.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT);
+ mMotionBlurImageActor.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y);
mContentLayer.Add( mMotionBlurImageActor );
mMotionBlurImageActor2 = ImageActor::New(image);
mMotionBlurImageActor2.SetParentOrigin( ParentOrigin::CENTER );
- mMotionBlurImageActor2.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT);
- mMotionBlurImageActor2.SetPosition(MOTION_BLUR_ACTOR_WIDTH * 1.1f, 0.0f);
+ mMotionBlurImageActor2.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y);
+ mMotionBlurImageActor2.SetPosition(mMotionBlurActorSize.x * 1.1f, 0.0f);
mMotionBlurImageActor.Add( mMotionBlurImageActor2 );
// Create shader used for doing motion blur
mMotionBlurImageActor3 = ImageActor::New(image);
mMotionBlurImageActor3.SetParentOrigin( ParentOrigin::CENTER );
- mMotionBlurImageActor3.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT);
- mMotionBlurImageActor3.SetPosition(-MOTION_BLUR_ACTOR_WIDTH * 1.1f, 0.0f);
+ mMotionBlurImageActor3.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y);
+ mMotionBlurImageActor3.SetPosition(-mMotionBlurActorSize.x * 1.1f, 0.0f);
mMotionBlurImageActor.Add( mMotionBlurImageActor3 );
// Create shader used for doing motion blur
mMotionBlurImageActor4 = ImageActor::New(image);
mMotionBlurImageActor4.SetParentOrigin( ParentOrigin::CENTER );
- mMotionBlurImageActor4.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT);
- mMotionBlurImageActor4.SetPosition(0.0f, MOTION_BLUR_ACTOR_HEIGHT * 1.1f);
+ mMotionBlurImageActor4.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y);
+ mMotionBlurImageActor4.SetPosition(0.0f, mMotionBlurActorSize.y * 1.1f);
mMotionBlurImageActor.Add( mMotionBlurImageActor4 );
// Create shader used for doing motion blur
mMotionBlurImageActor5 = ImageActor::New(image);
mMotionBlurImageActor5.SetParentOrigin( ParentOrigin::CENTER );
- mMotionBlurImageActor5.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT);
- mMotionBlurImageActor5.SetPosition(0.0f, -MOTION_BLUR_ACTOR_HEIGHT * 1.1f);
+ mMotionBlurImageActor5.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y);
+ mMotionBlurImageActor5.SetPosition(0.0f, -mMotionBlurActorSize.y * 1.1f);
mMotionBlurImageActor.Add( mMotionBlurImageActor5 );
// Create shader used for doing motion blur
{
// has parent so we expect it to be on stage, start animation
mRotateAnimation = Animation::New( ORIENTATION_DURATION );
- mRotateAnimation.SetDestroyAction( Animation::Bake );
- mRotateAnimation.RotateTo( mView, Degree( -orientation ), Vector3::ZAXIS, AlphaFunctions::EaseOut );
- mRotateAnimation.Resize( mView, targetSize.width, targetSize.height );
+ mRotateAnimation.AnimateTo( Property( mView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -orientation ) ), Vector3::ZAXIS ), AlphaFunction::EASE_OUT );
+ mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_WIDTH ), targetSize.width );
+ mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_HEIGHT ), targetSize.height );
mRotateAnimation.Play();
}
else
{
// set the rotation to match the orientation
- mView.SetRotation( Degree( -orientation ), Vector3::ZAXIS );
+ mView.SetOrientation( Degree( -orientation ), Vector3::ZAXIS );
mView.SetSize( targetSize );
}
}
//
// move to point on screen that was tapped
- void OnTap( Actor actor, TapGesture tapGesture )
+ void OnTap( Actor actor, const TapGesture& tapGesture )
{
Vector3 destPos;
float originOffsetX, originOffsetY;
mActorTapMovementAnimation = Animation::New( animDuration );
if ( mMotionBlurImageActor )
{
- mActorTapMovementAnimation.AnimateTo( Property(mMotionBlurImageActor, Actor::POSITION), destPos, AlphaFunctions::EaseInOutSine, TimePeriod(animDuration) );
+ mActorTapMovementAnimation.AnimateTo( Property(mMotionBlurImageActor, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration) );
}
mActorTapMovementAnimation.SetEndAction( Animation::Bake );
mActorTapMovementAnimation.Play();
// perform some spinning etc
- if(mActorAnimationsEnabled)
+ if(mActorEffectsEnabled)
{
switch(mCurrentActorAnimation)
{
{
float animDuration = 1.0f;
mActorAnimation = Animation::New(animDuration);
- mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut);
+ mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT );
mActorAnimation.SetEndAction( Animation::Bake );
mActorAnimation.Play();
}
{
float animDuration = 1.0f;
mActorAnimation = Animation::New(animDuration);
- mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(720), Vector3::ZAXIS, AlphaFunctions::EaseInOut);
+ mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT );
mActorAnimation.SetEndAction( Animation::Bake );
mActorAnimation.Play();
}
{
float animDuration = 1.0f;
mActorAnimation = Animation::New(animDuration);
- mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(360), Vector3::YAXIS, AlphaFunctions::EaseInOut);
- mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(360), Vector3::ZAXIS, AlphaFunctions::EaseInOut);
+ mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT );
+ mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT );
mActorAnimation.SetEndAction( Animation::Bake );
mActorAnimation.Play();
}
{
float animDuration = 1.0f;
mActorAnimation = Animation::New(animDuration);
- mActorAnimation.ScaleBy(mMotionBlurImageActor, Vector3(2.0f, 2.0f, 2.0f), AlphaFunctions::Bounce, 0.0f, 1.0f);
+ mActorAnimation.AnimateBy( Property( mMotionBlurImageActor, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod( 0.0f, 1.0f ) );
mActorAnimation.SetEndAction( Animation::Bake );
mActorAnimation.Play();
}
}
}
- void ToggleActorAnimations()
+ void ToggleActorEffects()
{
- if(!mActorAnimationsEnabled)
+ if(!mActorEffectsEnabled)
{
- mActorAnimationsEnabled = true;
- mActorAnimsButton.SetBackgroundImage( mIconAnimsStop );
+ mActorEffectsEnabled = true;
+ mActorEffectsButton.SetBackgroundImage( mIconEffectsOn );
}
else
{
- mActorAnimationsEnabled = false;
- mActorAnimsButton.SetBackgroundImage( mIconAnimsStart );
+ mActorEffectsEnabled = false;
+ mActorEffectsButton.SetBackgroundImage( mIconEffectsOff );
}
}
return true;
}
- bool OnAnimationButtonClicked( Toolkit::Button button )
+ bool OnEffectButtonClicked( Toolkit::Button button )
{
- ToggleActorAnimations();
+ ToggleActorEffects();
return true;
}
mCurrentImage = 0;
}
- Image blurImage = Image::New( MOTION_BLUR_ACTOR_IMAGES[mCurrentImage] );
+ Image blurImage = LoadImageFittedInBox( MOTION_BLUR_ACTOR_IMAGES[mCurrentImage], mMotionBlurActorSize.x, mMotionBlurActorSize.y );
mMotionBlurImageActor.SetImage(blurImage);
}
private:
Application& mApplication; ///< Application instance
- Toolkit::View mView;
+ Toolkit::Control mView;
Toolkit::ToolBar mToolBar;
- TextView mTitleActor; ///< The Toolbar's Title.
- Image mIconAnimsStart;
- Image mIconAnimsStop;
+ Image mIconEffectsOff;
+ Image mIconEffectsOn;
Layer mContentLayer; ///< Content layer (contains actor for this blur demo)
- PushButton mActorAnimsButton; ///< The actor animation toggling Button.
+ PushButton mActorEffectsButton; ///< The actor effects toggling Button.
// Motion blur
MotionBlurEffect mMotionBlurEffect;
ImageActor mMotionBlurImageActor;
+ Size mMotionBlurActorSize;
#ifdef MULTIPLE_MOTION_BLURRED_ACTORS
MotionBlurEffect mMotionBlurEffect2;
Animation mActorTapMovementAnimation;
// show different animations to demonstrate blur effect working on an object only movement basis
- bool mActorAnimationsEnabled;
+ bool mActorEffectsEnabled;
Animation mActorAnimation;
int mCurrentActorAnimation;
app.MainLoop();
}
-// Entry point for Linux & SLP applications
+// Entry point for Linux & Tizen applications
//
int main(int argc, char **argv)
{