From: David Steele Date: Thu, 16 Feb 2017 15:47:44 +0000 (+0000) Subject: Example of transitions of each visual type. X-Git-Tag: dali_1.2.28~3 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-demo.git;a=commitdiff_plain;h=c015449ba18acb34fe217c070c7fe3302cabee93 Example of transitions of each visual type. Change-Id: I8d15f1aec5cdca527f93283ff179dcf572e831ea --- diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 4511e54..ba61290 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -177,6 +177,9 @@ + + + diff --git a/examples/styling/image-channel-control-impl.cpp b/examples/styling/image-channel-control-impl.cpp index c805e39..631c0fa 100644 --- a/examples/styling/image-channel-control-impl.cpp +++ b/examples/styling/image-channel-control-impl.cpp @@ -37,12 +37,13 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord;\n uniform sampler2D sTexture;\n uniform mediump vec4 uColor;\n - uniform mediump vec4 mixColor;\n + uniform mediump vec3 mixColor;\n + uniform mediump float opacity;\n uniform mediump vec3 uChannels;\n \n void main()\n {\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * mixColor * uColor * vec4(uChannels, 1.0) ;\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(mixColor,opacity) * uColor * vec4(uChannels, 1.0) ;\n }\n ); diff --git a/examples/text-label/text-label-example.cpp b/examples/text-label/text-label-example.cpp index e3f0523..85c51eb 100644 --- a/examples/text-label/text-label-example.cpp +++ b/examples/text-label/text-label-example.cpp @@ -80,17 +80,17 @@ struct HSVColorConstraint { } - void operator()(Vector4& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs ) { - current = hsv2rgb(Vector4(inputs[0]->GetFloat(), saturation, value, current.a)); + current = hsv2rgb(Vector3(inputs[0]->GetFloat(), saturation, value)); } - Vector4 hsv2rgb(Vector4 colorHSV) + Vector3 hsv2rgb(Vector3 colorHSV) { float r=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x)-1)); float g=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x-2.09439)-1)); float b=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x+2.09439)-1)); - return Vector4(r, g, b, colorHSV.a); + return Vector3(r, g, b); } float hue; float saturation; @@ -173,7 +173,7 @@ public: Renderer bgRenderer = mLabel.GetRendererAt(0); mOverrideMixColorIndex = DevelHandle::GetPropertyIndex( bgRenderer, ColorVisual::Property::MIX_COLOR ); - Constraint constraint = Constraint::New( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f)); + Constraint constraint = Constraint::New( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f)); constraint.AddSource( Source( mLabel, mHueAngleIndex ) ); constraint.SetRemoveAction( Constraint::Discard ); constraint.Apply(); diff --git a/examples/visual-transitions/beat-control-impl.cpp b/examples/visual-transitions/beat-control-impl.cpp new file mode 100644 index 0000000..ef0c56d --- /dev/null +++ b/examples/visual-transitions/beat-control-impl.cpp @@ -0,0 +1,347 @@ +/* + * Copyright (c) 2016 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 "beat-control-impl.h" +#include +#include +#include +#include +#include + +#include + +using namespace Dali; // Needed for macros +using namespace Dali::Toolkit; + +namespace Demo +{ +namespace Internal +{ + +namespace +{ + +const int BOUNCE_ANIMATION_RUNNING(0x0001); +const int FADE_ANIMATION_RUNNING (0x0002); +const int X_ANIMATION_RUNNING (0x0004); +const int Y_ANIMATION_RUNNING (0x0008); + + +Dali::BaseHandle Create() +{ + return Demo::BeatControl::New(); +} + +DALI_TYPE_REGISTRATION_BEGIN( BeatControl, Dali::Toolkit::Control, Create ); + +DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "bounceTransition", STRING, BOUNCE_TRANSITION ); +DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "leftTransition", STRING, LEFT_TRANSITION ); +DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "upTransition", STRING, UP_TRANSITION ); +DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "fadeTransition", STRING, FADE_TRANSITION ); +DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "beatVisual", MAP, BEAT_VISUAL ); +DALI_TYPE_REGISTRATION_END(); + + +Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& value ) +{ + Toolkit::TransitionData transitionData; + + if( value.GetType() == Property::ARRAY ) + { + transitionData = Toolkit::TransitionData::New( *value.GetArray()); + } + else if( value.GetType() == Property::MAP ) + { + transitionData = Toolkit::TransitionData::New( *value.GetMap() ); + } + return transitionData; +} + +} // anonymous namespace + + +Internal::BeatControl::BeatControl() +: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), + mTransformSize(1.0f, 1.0f), + mAnimationPlaying(0) +{ +} + +Internal::BeatControl::~BeatControl() +{ +} + +Demo::BeatControl Internal::BeatControl::New() +{ + IntrusivePtr impl = new Internal::BeatControl(); + Demo::BeatControl handle = Demo::BeatControl( *impl ); + impl->Initialize(); + return handle; +} + + +void BeatControl::StartBounceAnimation() +{ + if( mAnimation ) + { + mAnimation.Stop(); + mAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnBounceAnimationFinished ); + OnBounceAnimationFinished(mAnimation); + } + + mAnimation = CreateTransition( mBounceTransition ); + mAnimation.FinishedSignal().Connect( this, &BeatControl::OnBounceAnimationFinished ); + mAnimation.Play(); + mAnimationPlaying |= BOUNCE_ANIMATION_RUNNING; +} + + +void BeatControl::StartXAnimation() +{ + if( mXAnimation ) + { + mXAnimation.Stop(); + mXAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnXAnimationFinished ); + OnXAnimationFinished(mXAnimation); + } + + mXAnimation = CreateTransition( mLeftTransition ); + mXAnimation.FinishedSignal().Connect( this, &BeatControl::OnXAnimationFinished ); + mXAnimation.Play(); + mAnimationPlaying |= X_ANIMATION_RUNNING; +} + +void BeatControl::StartYAnimation() +{ + if( mYAnimation ) + { + mYAnimation.Stop(); + mYAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnYAnimationFinished ); + OnYAnimationFinished(mYAnimation); + } + + mYAnimation = CreateTransition( mUpTransition ); + mYAnimation.FinishedSignal().Connect( this, &BeatControl::OnYAnimationFinished ); + mYAnimation.Play(); + mAnimationPlaying |= Y_ANIMATION_RUNNING; +} + +void BeatControl::StartFadeAnimation() +{ + if( mFadeAnimation ) + { + mFadeAnimation.Stop(); + mFadeAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnFadeAnimationFinished ); + OnFadeAnimationFinished(mFadeAnimation); + } + + mFadeAnimation = CreateTransition( mFadeTransition ); + mFadeAnimation.FinishedSignal().Connect( this, &BeatControl::OnFadeAnimationFinished ); + mFadeAnimation.Play(); + mAnimationPlaying |= FADE_ANIMATION_RUNNING; +} + +void BeatControl::OnBounceAnimationFinished( Animation& src ) +{ + mAnimationPlaying &= ~BOUNCE_ANIMATION_RUNNING; +} +void BeatControl::OnXAnimationFinished( Animation& src ) +{ + mAnimationPlaying &= ~X_ANIMATION_RUNNING; +} +void BeatControl::OnYAnimationFinished( Animation& src ) +{ + mAnimationPlaying &= ~Y_ANIMATION_RUNNING; +} +void BeatControl::OnFadeAnimationFinished( Animation& src ) +{ + mAnimationPlaying &= ~FADE_ANIMATION_RUNNING; +} + +void BeatControl::OnInitialize() +{ + Actor self = Self(); +} + +void BeatControl::OnStageConnection( int depth ) +{ + Control::OnStageConnection( depth ); +} + +void BeatControl::OnStageDisconnection() +{ + Control::OnStageDisconnection(); +} + +void BeatControl::OnSizeSet( const Vector3& targetSize ) +{ + Control::OnSizeSet( targetSize ); + RelayoutVisuals( Vector2( targetSize ) ); +} + +void BeatControl::OnRelayout( const Vector2& targetSize, RelayoutContainer& container ) +{ + RelayoutVisuals( targetSize ); +} + +void BeatControl::RelayoutVisuals( const Vector2& targetSize ) +{ + if( mVisual ) + { + if( (mAnimationPlaying & (X_ANIMATION_RUNNING | Y_ANIMATION_RUNNING)) == 0) + { + Vector2 size( targetSize ); + Property::Map transformMap; + // Make the visual half the size of the control, but leave + // origin and anchor point at center, position is relative, but Zer0 + transformMap[ DevelVisual::Transform::Property::SIZE ] = mTransformSize; + mVisual.SetTransformAndSize( transformMap, size ); + } + } +} + +Vector3 BeatControl::GetNaturalSize() +{ + if( mVisual ) + { + Vector2 naturalSize; + mVisual.GetNaturalSize(naturalSize); + return Vector3(naturalSize); + } + return Vector3::ZERO; +} + +void BeatControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) +{ + // Chain up. + Control::OnStyleChange( styleManager, change ); +} + + +/////////////////////////////////////////////////////////// +// +// Properties +// + +void BeatControl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Demo::BeatControl beatControl = Demo::BeatControl::DownCast( Dali::BaseHandle( object ) ); + + if( beatControl ) + { + BeatControl& impl = GetImpl( beatControl ); + Actor self = impl.Self(); + switch ( index ) + { + case Demo::BeatControl::Property::BEAT_VISUAL: + { + bool sizeOnly = false; + + // Determine if a transform.size property exists in the map, and + // save it. + Property::Map* map = value.GetMap(); + if( map ) + { + Property::Value* value = map->Find( DevelVisual::Property::TRANSFORM, "transform" ); + if( value ) + { + Property::Map* transformMap = value->GetMap(); + if( transformMap ) + { + Property::Value* sizeValue = transformMap->Find( DevelVisual::Transform::Property::SIZE, "size" ); + if( sizeValue ) + { + sizeValue->Get( impl.mTransformSize ); + if( map->Count() == 1 && transformMap->Count() == 1 ) + { + sizeOnly = true; + } + } + } + } + if( ! sizeOnly ) + { + // Only register a visual if there is more than just a size setting + impl.mVisual = Toolkit::VisualFactory::Get().CreateVisual( *map ); + impl.RegisterVisual( Demo::BeatControl::Property::BEAT_VISUAL, impl.mVisual ); + + // We have registered a new visual: must trigger size negotiation + // in order to call SetTransformAndSize on the visual with the right size: + impl.RelayoutRequest(); + } + } + break; + } + case Demo::BeatControl::Property::BOUNCE_TRANSITION: + { + impl.mBounceTransition = ConvertPropertyToTransition( value ); + break; + } + case Demo::BeatControl::Property::LEFT_TRANSITION: + { + impl.mLeftTransition = ConvertPropertyToTransition( value ); + break; + } + case Demo::BeatControl::Property::UP_TRANSITION: + { + impl.mUpTransition = ConvertPropertyToTransition( value ); + break; + } + case Demo::BeatControl::Property::FADE_TRANSITION: + { + impl.mFadeTransition = ConvertPropertyToTransition( value ); + break; + } + } + } +} + +Property::Value BeatControl::GetProperty( BaseObject* object, Property::Index propertyIndex ) +{ + Property::Value value; + + Demo::BeatControl beatControl = Demo::BeatControl::DownCast( Dali::BaseHandle( object ) ); + + if ( beatControl ) + { + BeatControl& impl = GetImpl( beatControl ); + switch ( propertyIndex ) + { + case Demo::BeatControl::Property::BEAT_VISUAL: + { + if( impl.mVisual ) + { + Property::Map map; + impl.mVisual.CreatePropertyMap(map); + value = map; + } + break; + } + case Demo::BeatControl::Property::BOUNCE_TRANSITION: + case Demo::BeatControl::Property::LEFT_TRANSITION: + case Demo::BeatControl::Property::UP_TRANSITION: + case Demo::BeatControl::Property::FADE_TRANSITION: + default: + break; + } + } + + return value; +} + + +} // Internal +} // Demo diff --git a/examples/visual-transitions/beat-control-impl.h b/examples/visual-transitions/beat-control-impl.h new file mode 100644 index 0000000..7138a8e --- /dev/null +++ b/examples/visual-transitions/beat-control-impl.h @@ -0,0 +1,152 @@ +#ifndef DALI_DEMO_INTERNAL_BEAT_CONTROL_IMPL_H +#define DALI_DEMO_INTERNAL_BEAT_CONTROL_IMPL_H + +/* + * Copyright (c) 2016 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 "beat-control.h" +#include +#include +#include +#include + +namespace Demo +{ + +namespace Internal // To use TypeRegistry, handle and body classes need the same name +{ + +class BeatControl : public Dali::Toolkit::Internal::Control +{ +public: + /** + * Instantiate a new BeatControl object + */ + static Demo::BeatControl New(); + BeatControl(); + ~BeatControl(); + +public: // API + void StartBounceAnimation(); + + void StartXAnimation(); + + void StartYAnimation(); + + void StartFadeAnimation(); + +public: // Properties + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex ); + +private: // From Control + /** + * @copydoc Toolkit::Control::OnInitialize() + */ + virtual void OnInitialize(); + + /** + * @copydoc Toolkit::Control::OnStageConnect() + */ + virtual void OnStageConnection( int depth ); + + /** + * @copydoc Toolkit::Control::OnStageDisconnection() + */ + virtual void OnStageDisconnection(); + + /** + * @copydoc Toolkit::Control::OnSizeSet() + */ + virtual void OnSizeSet( const Dali::Vector3& targetSize ); + + /** + * @copydoc Toolkit::Control::OnRelayout() + */ + virtual void OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container ); + /** + * @copydoc Toolkit::Control::GetNaturalSize + */ + virtual Dali::Vector3 GetNaturalSize(); + + /** + * @copydoc Toolkit::Control::OnStyleChange + */ + virtual void OnStyleChange( Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change ); + +private: + void OnBounceAnimationFinished( Dali::Animation& handle ); + void OnXAnimationFinished( Dali::Animation& src ); + void OnYAnimationFinished( Dali::Animation& src ); + void OnFadeAnimationFinished( Dali::Animation& src ); + + /** + * Relayout the visuals as a result of size negotiation + */ + void RelayoutVisuals( const Dali::Vector2& targetSize ); + +private: + //undefined + BeatControl( const BeatControl& ); + BeatControl& operator=( const BeatControl& ); + +private: + // Implementation details + Dali::Toolkit::Visual::Base mVisual; + Dali::Toolkit::TransitionData mBounceTransition; + Dali::Toolkit::TransitionData mLeftTransition; + Dali::Toolkit::TransitionData mUpTransition; + Dali::Toolkit::TransitionData mFadeTransition; + Dali::Animation mAnimation; + Dali::Animation mXAnimation; + Dali::Animation mYAnimation; + Dali::Animation mFadeAnimation; + Dali::Vector2 mTransformSize; + int mAnimationPlaying; +}; + +} // Internal + +inline Internal::BeatControl& GetImpl( Demo::BeatControl& handle ) +{ + DALI_ASSERT_ALWAYS( handle ); + Dali::RefObject& object = handle.GetImplementation(); + return static_cast(object); +} + +inline const Internal::BeatControl& GetImpl( const Demo::BeatControl& handle ) +{ + DALI_ASSERT_ALWAYS( handle ); + const Dali::RefObject& object = handle.GetImplementation(); + return static_cast(object); +} + +} // Demo + +#endif // DALI_DEMO_BEAT_CONTROL_IMPL_H diff --git a/examples/visual-transitions/beat-control.cpp b/examples/visual-transitions/beat-control.cpp new file mode 100644 index 0000000..2dc16fd --- /dev/null +++ b/examples/visual-transitions/beat-control.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016 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 "beat-control.h" +#include "beat-control-impl.h" + +namespace Demo +{ + +BeatControl::BeatControl() +{ +} + +BeatControl::BeatControl( const BeatControl& beatControl ) +: Control( beatControl ) +{ +} + +BeatControl& BeatControl::operator= ( const BeatControl& rhs ) +{ + if( &rhs != this ) + { + Control::operator=( rhs ); + } + return *this; +} + +BeatControl::~BeatControl() +{ +} + +BeatControl BeatControl::New() +{ + BeatControl beatControl = Internal::BeatControl::New(); + return beatControl; +} + +BeatControl BeatControl::New( const std::string& url ) +{ + BeatControl beatControl = Internal::BeatControl::New(); + return beatControl; +} + +BeatControl BeatControl::DownCast( BaseHandle handle ) +{ + return Control::DownCast< BeatControl, Internal::BeatControl > ( handle ); +} + +void BeatControl::StartBounceAnimation() +{ + GetImpl(*this).StartBounceAnimation(); +} + +void BeatControl::StartXAnimation() +{ + GetImpl(*this).StartXAnimation(); +} +void BeatControl::StartYAnimation() +{ + GetImpl(*this).StartYAnimation(); +} +void BeatControl::StartFadeAnimation() +{ + GetImpl(*this).StartFadeAnimation(); +} + +BeatControl::BeatControl( Internal::BeatControl& implementation ) +: Control( implementation ) +{ +} + +BeatControl::BeatControl( Dali::Internal::CustomActor* internal ) +: Control( internal ) +{ + VerifyCustomActorPointer< Internal::BeatControl >( internal ) ; +} + + +} //namespace Demo diff --git a/examples/visual-transitions/beat-control.h b/examples/visual-transitions/beat-control.h new file mode 100644 index 0000000..f0e6e00 --- /dev/null +++ b/examples/visual-transitions/beat-control.h @@ -0,0 +1,124 @@ +#ifndef DALI_DEMO_BEAT_CONTROL_H +#define DALI_DEMO_BEAT_CONTROL_H + +/* + * Copyright (c) 2016 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 +#include + +namespace Demo +{ + +namespace Internal +{ +// All type registered types need to have the same name for the body and the handle +class BeatControl; +} + +/** + * Control that allows the RGB channels of an image to be altered. + */ +class BeatControl : public Dali::Toolkit::Control +{ +public: + /** + * The start and end property ranges for this control + */ + enum PropertyRange + { + PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, + ANIMATABLE_PROPERTY_START_INDEX = Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, + ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX+1000 + }; + + struct Property + { + enum + { + BOUNCE_TRANSITION = PROPERTY_START_INDEX, + LEFT_TRANSITION, + UP_TRANSITION, + FADE_TRANSITION, + BEAT_VISUAL + }; + }; + +public: // Construction / destruction + + /** + * Create an uninitialized handle + */ + BeatControl(); + + /** + * Create a new image channel control without an image. Use + * SetImage to give this control an image + */ + static BeatControl New(); + + /** + * Create a new image channel control from a given URL + */ + static BeatControl New( const std::string& url ); + + /** + * Destructor. This is non-virtual since derived Handle types must not + * contain data or virtual methods + */ + ~BeatControl(); + + /** + * Copy Constructor + */ + BeatControl( const BeatControl& beatControl ); + + /** + * Assignment Operator + */ + BeatControl& operator=( const BeatControl& beatControl ); + + /** + * Downcast + */ + static BeatControl DownCast( BaseHandle handle ); + +public: // API + + void StartBounceAnimation(); + + void StartXAnimation(); + + void StartYAnimation(); + + void StartFadeAnimation(); + +public: // Not for public use + /** + * Create a handle from an implementation + */ + BeatControl( Internal::BeatControl& implementation ); + + /** + * Allow the creation of an BeatControl handle from an internal CustomActor pointer + */ + BeatControl( Dali::Internal::CustomActor* internal ); +}; + +} // namespace Demo + +#endif // DALI_DEMO_BEAT_CONTROL_H diff --git a/examples/visual-transitions/transition-application.cpp b/examples/visual-transitions/transition-application.cpp new file mode 100644 index 0000000..32c4188 --- /dev/null +++ b/examples/visual-transitions/transition-application.cpp @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2016 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. + */ + +/** + * @file transition-application.cpp + * @brief Application class for showing stylable transitions + */ + +// Class include +#include "transition-application.h" + +// External includes +#include +#include +#include +#include "beat-control.h" +#include +#include + +// Internal includes + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace Demo +{ + +const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" ); +const char* DALI_LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" ); +const char* DALI_ROBOT_MODEL_PATH( DEMO_MODEL_DIR "ToyRobot-Metal.obj" ); +const char* DALI_ROBOT_MATERIAL_PATH( DEMO_MODEL_DIR "ToyRobot-Metal.mtl" ); + + +TransitionApplication::TransitionApplication( Application& application ) +: mApplication( application ), + mTitle(), + mBeatControl(), + mActionButtons(), + mActionIndex( Property::INVALID_INDEX ) +{ + application.InitSignal().Connect( this, &TransitionApplication::Create ); +} + +TransitionApplication::~TransitionApplication() +{ +} + +void TransitionApplication::Create( Application& application ) +{ + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent); + stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) ); + + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + + // Content panes: + TableView contentLayout = TableView::New( 4, 1 ); + contentLayout.SetName("ContentLayout"); + contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT ); + contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) ); + + // Assign all rows the size negotiation property of fitting to children + + stage.Add( contentLayout ); + + mTitle = TextLabel::New( "Custom Control Transition Example" ); + mTitle.SetName( "Title" ); + mTitle.SetStyleName("Title"); + mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); + contentLayout.Add( mTitle ); + contentLayout.SetFitHeight(0); // Fill width + + mBeatControl = BeatControl::New(); + mBeatControl.SetName("BeatControl"); + mBeatControl.SetProperty( BeatControl::Property::BEAT_VISUAL, Property::Map() + .Add( DevelVisual::Property::TRANSFORM, Property::Map() + .Add( DevelVisual::Transform::Property::SIZE, Vector2(0.5f, 0.5f) ) ) ); + + mBeatControl.SetAnchorPoint( AnchorPoint::CENTER ); + mBeatControl.SetParentOrigin( ParentOrigin::CENTER ); + mBeatControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + contentLayout.Add( mBeatControl ); + // beat control should fill the tableview cell, so no change to default parameters + + TableView visualTypeLayout = TableView::New( 1, NUMBER_OF_VISUAL_BUTTONS ); + visualTypeLayout.SetName("VisualTypeLayout"); + visualTypeLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + visualTypeLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); + visualTypeLayout.SetFitHeight( 0 ); + + contentLayout.Add( visualTypeLayout ); + contentLayout.SetFitHeight(2); + + for( int i=0; i( mVisualIndex ); + Property::Map map; + CreateVisualMap( visual, map ); + map.Add( DevelVisual::Property::TRANSFORM, Property::Map() + .Add( DevelVisual::Transform::Property::SIZE, Vector2( 0.5f, 0.5f ) ) ); + mBeatControl.SetProperty( BeatControl::Property::BEAT_VISUAL, map ); + } + return true; +} + +bool TransitionApplication::OnActionButtonClicked( Button button ) +{ + int action = button.GetProperty( mActionIndex ); + switch( action ) + { + case 0: + { + mBeatControl.StartBounceAnimation(); + break; + } + case 1: + { + mBeatControl.StartXAnimation(); + break; + } + case 2: + { + mBeatControl.StartYAnimation(); + break; + } + case 3: + { + mBeatControl.StartFadeAnimation(); + break; + } + } + + return true; +} + +void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent ) +{ + static int keyPressed = 0; + + if( keyEvent.state == KeyEvent::Down) + { + if( keyPressed == 0 ) // Is this the first down event? + { + printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode ); + + if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + else if( keyEvent.keyPressedName.compare("Return") == 0 ) + { + } + } + keyPressed = 1; + } + else if( keyEvent.state == KeyEvent::Up ) + { + keyPressed = 0; + } +} + +} // namespace Demo diff --git a/examples/visual-transitions/transition-application.h b/examples/visual-transitions/transition-application.h new file mode 100644 index 0000000..9846c11 --- /dev/null +++ b/examples/visual-transitions/transition-application.h @@ -0,0 +1,85 @@ +#ifndef DALI_DEMO_TRANSITION_APPLICATION_H +#define DALI_DEMO_TRANSITION_APPLICATION_H + +/* + * Copyright (c) 2016 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. + */ + +// External includes +#include +//#include +#include +#include "beat-control.h" +#include +#include + +// Internal includes + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace Demo +{ + +class TransitionApplication : public ConnectionTracker +{ +public: + static const int NUMBER_OF_ACTION_BUTTONS=4; + static const int NUMBER_OF_VISUAL_BUTTONS=10; + +public: + // Constructor + TransitionApplication( Application& application ); + + // Destructor + ~TransitionApplication(); + + // Init signal handler + void Create( Application& application ); + + // Create the GUI components + Toolkit::TextLabel CreateTitle( std::string title ); + Actor CreateContentPane(); + + // Key event handler + void OnKeyEvent( const KeyEvent& event ); + + bool OnActionButtonClicked( Button button ); + bool OnVisualButtonClicked( Actor actor, const TouchData& touchData ); + + static const char* DEMO_THEME_ONE_PATH; + +private: + + /** Create a visual map + * + * @param[in] index The index of the visual to create + * @param[out] map The map to generate + */ + void CreateVisualMap( int index, Property::Map& map ); + + Application& mApplication; + TextLabel mTitle; + BeatControl mBeatControl; + PushButton mActionButtons[NUMBER_OF_ACTION_BUTTONS]; + BeatControl mVisualButtons[NUMBER_OF_VISUAL_BUTTONS]; + Property::Index mVisualIndex; + Property::Index mActionIndex; +}; + +} // Namespace Demo + + +#endif // DALI_DEMO_TRANSITION_APPLICATION_H diff --git a/examples/visual-transitions/transition-example.cpp b/examples/visual-transitions/transition-example.cpp new file mode 100644 index 0000000..adc4563 --- /dev/null +++ b/examples/visual-transitions/transition-example.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 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. + */ + +/** + * @file transition-example.cpp + * @brief Example of stylable transitions. + */ + +// External includes +#include + +// Internal includes +#include "transition-application.h" + + +/// Entry point for applications +int DALI_EXPORT_API main( int argc, char** argv ) +{ + const char* themeName = Demo::TransitionApplication::DEMO_THEME_ONE_PATH; + + Application application = Application::New( &argc, &argv, themeName ); + Demo::TransitionApplication transitionApplication( application ); + application.MainLoop(); + return 0; +} diff --git a/resources/style/mobile/style-example-theme-one.json.in b/resources/style/mobile/style-example-theme-one.json.in index 6d6c7d8..9447a9d 100644 --- a/resources/style/mobile/style-example-theme-one.json.in +++ b/resources/style/mobile/style-example-theme-one.json.in @@ -73,9 +73,9 @@ [ { "target":"imageVisual", - "property":"mixColor", - "initialValue":[1,1,1,0], - "targetValue":[1,1,1,1], + "property":"opacity", + "initialValue":0, + "targetValue":1, "animator": { "alphaFunction":"EASE_IN_OUT", @@ -96,8 +96,8 @@ [ { "target":"imageVisual", - "property":"mixColor", - "targetValue":[1,1,1,0], + "property":"opacity", + "targetValue":0, "animator": { "alphaFunction":"EASE_IN_OUT", @@ -378,6 +378,88 @@ } } ] + }, + "BeatControl": + { + "beatVisual":{ + "visualType":"IMAGE", + "url":"{APPLICATION_RESOURCE_PATH}/images/Logo-for-demo.png" + }, + + "bounceTransition": + [ + { + "target":"beatVisual", + "property":"size", + "initialValue":[0.5, 0.5], + "targetValue":[0.75, 0.75], + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + ], + + "leftTransition": + [ + { + "target":"beatVisual", + "property":"offset", + "initialValue":[0, 0], + "targetValue":[0.25, 0], + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + ], + + "upTransition": + [ + { + "target":"beatVisual", + "property":"offset", + "initialValue":[0, 0], + "targetValue":[0, 0.25], + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + ], + + "fadeTransition": + [ + { + "target":"beatVisual", + "property":"opacity", + "targetValue":0, + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.8, + "delay":0 + } + } + } + ] } } } diff --git a/resources/style/style-example-theme-one.json.in b/resources/style/style-example-theme-one.json.in index a28f842..507c685 100644 --- a/resources/style/style-example-theme-one.json.in +++ b/resources/style/style-example-theme-one.json.in @@ -73,9 +73,9 @@ [ { "target":"imageVisual", - "property":"mixColor", - "initialValue":[1,1,1,0], - "targetValue":[1,1,1,1], + "property":"opacity", + "initialValue":0, + "targetValue":1, "animator": { "alphaFunction":"EASE_IN_OUT", @@ -96,8 +96,8 @@ [ { "target":"imageVisual", - "property":"mixColor", - "targetValue":[1,1,1,0], + "property":"opacity", + "targetValue":0, "animator": { "alphaFunction":"EASE_IN_OUT", @@ -378,6 +378,88 @@ } } ] + }, + "BeatControl": + { + "beatVisual":{ + "visualType":"IMAGE", + "url":"{APPLICATION_RESOURCE_PATH}/images/Logo-for-demo.png" + }, + + "bounceTransition": + [ + { + "target":"beatVisual", + "property":"size", + "initialValue":[0.5, 0.5], + "targetValue":[0.75, 0.75], + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + ], + + "leftTransition": + [ + { + "target":"beatVisual", + "property":"offset", + "initialValue":[0, 0], + "targetValue":[0.25, 0], + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + ], + + "upTransition": + [ + { + "target":"beatVisual", + "property":"offset", + "initialValue":[0, 0], + "targetValue":[0, 0.25], + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + ], + + "fadeTransition": + [ + { + "target":"beatVisual", + "property":"opacity", + "targetValue":0, + "animator": + { + "alphaFunction":"BOUNCE", + "timePeriod": + { + "duration":0.8, + "delay":0 + } + } + } + ] } } }