Remove use of deprecated Control flag REQUIRES_STYLE_CHANGE_SIGNALS
[platform/core/uifw/dali-demo.git] / examples / visual-transitions / beat-control-impl.cpp
index ef0c56d..956fe11 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
 
 #include "beat-control-impl.h"
 #include <dali-toolkit/dali-toolkit.h>
-#include <dali/public-api/object/type-registry-helper.h>
-#include <dali-toolkit/devel-api/align-enums.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
-#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
-
-#include <cstdio>
 
 using namespace Dali; // Needed for macros
 using namespace Dali::Toolkit;
@@ -59,13 +55,18 @@ Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& valu
 {
   Toolkit::TransitionData transitionData;
 
-  if( value.GetType() == Property::ARRAY )
+  const Property::Array* array = value.GetArray();
+  if( array )
   {
-    transitionData = Toolkit::TransitionData::New( *value.GetArray());
+    transitionData = Toolkit::TransitionData::New( *array );
   }
-  else if( value.GetType() == Property::MAP )
+  else
   {
-    transitionData = Toolkit::TransitionData::New( *value.GetMap() );
+    const Property::Map* map = value.GetMap();
+    if( map )
+    {
+      transitionData = Toolkit::TransitionData::New( *map );
+    }
   }
   return transitionData;
 }
@@ -74,8 +75,10 @@ Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& valu
 
 
 Internal::BeatControl::BeatControl()
-: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
   mTransformSize(1.0f, 1.0f),
+  mTransformOrigin(Align::CENTER),
+  mTransformAnchorPoint(Align::CENTER),
   mAnimationPlaying(0)
 {
 }
@@ -102,7 +105,7 @@ void BeatControl::StartBounceAnimation()
     OnBounceAnimationFinished(mAnimation);
   }
 
-  mAnimation = CreateTransition( mBounceTransition );
+  mAnimation = DevelControl::CreateTransition( *this, mBounceTransition );
   mAnimation.FinishedSignal().Connect( this, &BeatControl::OnBounceAnimationFinished );
   mAnimation.Play();
   mAnimationPlaying |= BOUNCE_ANIMATION_RUNNING;
@@ -118,7 +121,7 @@ void BeatControl::StartXAnimation()
     OnXAnimationFinished(mXAnimation);
   }
 
-  mXAnimation = CreateTransition( mLeftTransition );
+  mXAnimation = DevelControl::CreateTransition( *this, mLeftTransition );
   mXAnimation.FinishedSignal().Connect( this, &BeatControl::OnXAnimationFinished );
   mXAnimation.Play();
   mAnimationPlaying |= X_ANIMATION_RUNNING;
@@ -133,7 +136,7 @@ void BeatControl::StartYAnimation()
     OnYAnimationFinished(mYAnimation);
   }
 
-  mYAnimation = CreateTransition( mUpTransition );
+  mYAnimation = DevelControl::CreateTransition( *this, mUpTransition );
   mYAnimation.FinishedSignal().Connect( this, &BeatControl::OnYAnimationFinished );
   mYAnimation.Play();
   mAnimationPlaying |= Y_ANIMATION_RUNNING;
@@ -148,7 +151,7 @@ void BeatControl::StartFadeAnimation()
     OnFadeAnimationFinished(mFadeAnimation);
   }
 
-  mFadeAnimation = CreateTransition( mFadeTransition );
+  mFadeAnimation = DevelControl::CreateTransition( *this, mFadeTransition );
   mFadeAnimation.FinishedSignal().Connect( this, &BeatControl::OnFadeAnimationFinished );
   mFadeAnimation.Play();
   mAnimationPlaying |= FADE_ANIMATION_RUNNING;
@@ -176,14 +179,14 @@ void BeatControl::OnInitialize()
   Actor self = Self();
 }
 
-void BeatControl::OnStageConnection( int depth )
+void BeatControl::OnSceneConnection( int depth )
 {
-  Control::OnStageConnection( depth );
+  Control::OnSceneConnection( depth );
 }
 
-void BeatControl::OnStageDisconnection()
+void BeatControl::OnSceneDisconnection()
 {
-  Control::OnStageDisconnection();
+  Control::OnSceneDisconnection();
 }
 
 void BeatControl::OnSizeSet( const Vector3& targetSize )
@@ -207,7 +210,9 @@ void BeatControl::RelayoutVisuals( const Vector2& 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;
+      transformMap[ Visual::Transform::Property::SIZE ] = mTransformSize;
+      transformMap[ Visual::Transform::Property::ORIGIN ] = mTransformOrigin;
+      transformMap[ Visual::Transform::Property::ANCHOR_POINT ] = mTransformAnchorPoint;
       mVisual.SetTransformAndSize( transformMap, size );
     }
   }
@@ -248,35 +253,64 @@ void BeatControl::SetProperty( BaseObject* object, Property::Index index, const
     {
       case Demo::BeatControl::Property::BEAT_VISUAL:
       {
-        bool sizeOnly = false;
+        bool sizeAndPositionOnly = 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" );
+          Property::Value* value = map->Find( Visual::Property::TRANSFORM, "transform" );
           if( value )
           {
             Property::Map* transformMap = value->GetMap();
             if( transformMap )
             {
-              Property::Value* sizeValue = transformMap->Find( DevelVisual::Transform::Property::SIZE, "size" );
+              // We'll increment this whenever SIZE, ORIGIN or ANCHOR_POINT's are modified as we won't need to create a new visual if only these properties are used
+              // If there are more properties in the transform map, then we need to create a new visual
+              unsigned int sizeAndPositionPropertyCount = 0;
+
+              Property::Value* sizeValue = transformMap->Find( Visual::Transform::Property::SIZE, "size" );
               if( sizeValue )
               {
                 sizeValue->Get( impl.mTransformSize );
-                if( map->Count() == 1 && transformMap->Count() == 1 )
+                ++sizeAndPositionPropertyCount;
+              }
+
+              Property::Value* originValue = transformMap->Find( Visual::Transform::Property::ORIGIN, "origin" );
+              if( originValue )
+              {
+                int intValue = 0;
+                if( originValue->Get( intValue ) )
                 {
-                  sizeOnly = true;
+                  impl.mTransformOrigin = static_cast< Toolkit::Align::Type >( intValue );
+                  ++sizeAndPositionPropertyCount;
                 }
               }
+
+              Property::Value* anchorPointValue = transformMap->Find( Visual::Transform::Property::ANCHOR_POINT, "anchorPoint" );
+              if( anchorPointValue )
+              {
+                int intValue = 0;
+                if( anchorPointValue->Get( intValue ) )
+                {
+                  impl.mTransformAnchorPoint = static_cast< Toolkit::Align::Type >( intValue );
+                  ++sizeAndPositionPropertyCount;
+                }
+              }
+
+              // If the only properties that the application is overriding are the size and the position properties, then we do not need to create another visual.
+              if( map->Count() == 1 && transformMap->Count() == sizeAndPositionPropertyCount )
+              {
+                sizeAndPositionOnly = true;
+              }
             }
           }
-          if( ! sizeOnly )
+          if( ! sizeAndPositionOnly )
           {
             // 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 );
+            DevelControl::RegisterVisual( impl, 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: