From 386c24d26e97c645a7a6dbecb16710293fe455e7 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Fri, 2 Jun 2017 12:10:57 +0100 Subject: [PATCH] Changes required after Visual parent-origin & anchor-point defaults change Change-Id: Ia9ba3566e226a73c2ccdc5716e6d64c638bbfc1b --- examples/mesh-visual/mesh-visual-example.cpp | 5 ++ .../primitive-shapes/primitive-shapes-example.cpp | 5 ++ examples/visual-transitions/beat-control-impl.cpp | 57 +++++++++++++++++----- examples/visual-transitions/beat-control-impl.h | 5 +- .../visual-transitions/transition-application.cpp | 4 +- 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/examples/mesh-visual/mesh-visual-example.cpp b/examples/mesh-visual/mesh-visual-example.cpp index 341a72c..4b9fb23 100644 --- a/examples/mesh-visual/mesh-visual-example.cpp +++ b/examples/mesh-visual/mesh-visual-example.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -321,6 +323,9 @@ public: //Create mesh property map Property::Map map; map.Insert( Visual::Property::TYPE, Visual::MESH ); + map.Insert( DevelVisual::Property::TRANSFORM, + Property::Map().Add( DevelVisual::Transform::Property::ORIGIN, Align::CENTER ) + .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::CENTER ) ); map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex] ); map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex] ); map.Insert( MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH ); diff --git a/examples/primitive-shapes/primitive-shapes-example.cpp b/examples/primitive-shapes/primitive-shapes-example.cpp index cc762be..cce4f3c 100644 --- a/examples/primitive-shapes/primitive-shapes-example.cpp +++ b/examples/primitive-shapes/primitive-shapes-example.cpp @@ -17,7 +17,9 @@ #include #include +#include #include +#include #include using namespace Dali; @@ -355,6 +357,9 @@ public: mVisualMap.Clear(); mVisualMap[ Visual::Property::TYPE ] = Visual::PRIMITIVE; mVisualMap[ PrimitiveVisual::Property::MIX_COLOR ] = mColor; + mVisualMap[ DevelVisual::Property::TRANSFORM ] = + Property::Map().Add( DevelVisual::Transform::Property::ORIGIN, Align::CENTER ) + .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::CENTER ); } //Sets the 3D model to a sphere and modifies the sliders appropriately. diff --git a/examples/visual-transitions/beat-control-impl.cpp b/examples/visual-transitions/beat-control-impl.cpp index d160e5b..54ae6b0 100644 --- a/examples/visual-transitions/beat-control-impl.cpp +++ b/examples/visual-transitions/beat-control-impl.cpp @@ -17,13 +17,10 @@ #include "beat-control-impl.h" #include #include -#include #include #include #include -#include - using namespace Dali; // Needed for macros using namespace Dali::Toolkit; @@ -60,13 +57,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; } @@ -77,6 +79,8 @@ Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& valu Internal::BeatControl::BeatControl() : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), mTransformSize(1.0f, 1.0f), + mTransformOrigin(Align::CENTER), + mTransformAnchorPoint(Align::CENTER), mAnimationPlaying(0) { } @@ -209,6 +213,8 @@ void BeatControl::RelayoutVisuals( const Vector2& targetSize ) // 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[ DevelVisual::Transform::Property::ORIGIN ] = mTransformOrigin; + transformMap[ DevelVisual::Transform::Property::ANCHOR_POINT ] = mTransformAnchorPoint; mVisual.SetTransformAndSize( transformMap, size ); } } @@ -249,7 +255,7 @@ 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. @@ -262,18 +268,47 @@ void BeatControl::SetProperty( BaseObject* object, Property::Index index, const Property::Map* transformMap = value->GetMap(); if( transformMap ) { + // 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( DevelVisual::Transform::Property::SIZE, "size" ); if( sizeValue ) { sizeValue->Get( impl.mTransformSize ); - if( map->Count() == 1 && transformMap->Count() == 1 ) + ++sizeAndPositionPropertyCount; + } + + Property::Value* originValue = transformMap->Find( DevelVisual::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( DevelVisual::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 ); diff --git a/examples/visual-transitions/beat-control-impl.h b/examples/visual-transitions/beat-control-impl.h index 7138a8e..7e77def 100644 --- a/examples/visual-transitions/beat-control-impl.h +++ b/examples/visual-transitions/beat-control-impl.h @@ -2,7 +2,7 @@ #define DALI_DEMO_INTERNAL_BEAT_CONTROL_IMPL_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -20,6 +20,7 @@ #include "beat-control.h" #include #include +#include #include #include @@ -128,6 +129,8 @@ private: Dali::Animation mYAnimation; Dali::Animation mFadeAnimation; Dali::Vector2 mTransformSize; + Dali::Toolkit::Align::Type mTransformOrigin; + Dali::Toolkit::Align::Type mTransformAnchorPoint; int mAnimationPlaying; }; diff --git a/examples/visual-transitions/transition-application.cpp b/examples/visual-transitions/transition-application.cpp index 7094d14..87a69d5 100644 --- a/examples/visual-transitions/transition-application.cpp +++ b/examples/visual-transitions/transition-application.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -124,7 +124,7 @@ void TransitionApplication::Create( Application& application ) Property::Map map; CreateVisualMap( i, map ); map.Add( DevelVisual::Property::TRANSFORM, Property::Map() - .Add( DevelVisual::Transform::Property::SIZE, Vector2(0.8f, 0.8f) ) ); + .Add( DevelVisual::Transform::Property::SIZE, Vector2(0.8f, 0.8f) ) ); mVisualButtons[i] = BeatControl::New(); mVisualButtons[i].SetProperty( BeatControl::Property::BEAT_VISUAL, map ); mVisualButtons[i].SetName("VisualButton"); -- 2.7.4