From: Adeel Kazmi Date: Fri, 21 Oct 2016 10:34:10 +0000 (-0700) Subject: Merge "Added code for stylable transitions" into devel/master X-Git-Tag: dali_1.2.12~21 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=f4c1e7f52d49c3ce033b9ee4c3c7414b06a22d45;hp=6f0cec093ffdac0afee6ad28441d1398281f4c4c Merge "Added code for stylable transitions" into devel/master --- diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index 6031392..1c6f3c9 100644 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -33,6 +33,7 @@ SET(TC_SOURCES utc-Dali-TextLabel.cpp utc-Dali-TextSelectionPopup.cpp utc-Dali-ToolBar.cpp + utc-Dali-TransitionData.cpp utc-Dali-Button.cpp utc-Dali-Control.cpp utc-Dali-ControlImpl.cpp diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp index 7e102f5..a100a1f 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp @@ -70,7 +70,6 @@ DummyControlImpl::DummyControlImpl() { } - DummyControlImpl::~DummyControlImpl() { } @@ -110,6 +109,11 @@ Actor DummyControlImpl::GetPlacementActor( Property::Index index ) return Control::GetPlacementActor( index ); } +Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition ) +{ + return Control::CreateTransition( transition ); +} + DummyControl DummyControlImplOverride::New() { IntrusivePtr< DummyControlImplOverride > impl = new DummyControlImplOverride; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h index 3e5e56f..d63b853 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h @@ -79,6 +79,7 @@ public: Toolkit::Visual::Base GetVisual( Property::Index index ); Actor GetPlacementActor( Property::Index index ); + Animation CreateTransition( const Toolkit::TransitionData& transition ); // Used to test signal connections void CustomSlot1( Actor actor ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp new file mode 100644 index 0000000..7f3d8aa --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp @@ -0,0 +1,646 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include "dummy-control.h" + +using namespace Dali; +using namespace Toolkit; + + +void utc_dali_toolkit_transition_data_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_toolkit_transition_data_cleanup(void) +{ + test_return_value = TET_PASS; +} + +Property::Map CreateMap() +{ + Property::Map map; + + map["target"] = "Actor1"; + map["property"] = "color"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT_BACK") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + return map; +} + +void CHECK_MAP_EQUALS( Property::Map test, Property::Map result ) +{ + DALI_TEST_EQUALS(test.Count(), result.Count(), TEST_LOCATION); + + for( unsigned int i=0; i< test.Count(); ++i ) + { + KeyValuePair keyValue = test.GetKeyValue(i); + Property::Value* value; + + if( keyValue.first.type == Property::Key::STRING ) + { + value = result.Find(keyValue.first.stringKey); + } + else + { + value = result.Find(keyValue.first.indexKey); + } + + DALI_TEST_CHECK( value != NULL ); + if( value != NULL ) + { + DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION ); + if( keyValue.second.GetType() == Property::MAP ) + { + CHECK_MAP_EQUALS( *(keyValue.second.GetMap()), *(value->GetMap()) ); + } + else if( keyValue.second.GetType() == Property::ARRAY ) + { + } + else if( keyValue.second.GetType() == Property::STRING ) + { + std::string str; + value->Get(str); + DALI_TEST_EQUALS( keyValue.second, str.c_str(), TEST_LOCATION ); + } + else + { + DALI_TEST_EQUALS( keyValue.second, *value, 0.001f, TEST_LOCATION ); + } + } + } +} + + +int UtcDaliTransitionDataNew(void) +{ + TestApplication application; + + Property::Map map = CreateMap(); + Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + DALI_TEST_CHECK( transition ); + + END_TEST; +} + +int UtcDaliTransitionDataDownCast(void) +{ + TestApplication application; + + Property::Map map = CreateMap(); + + BaseHandle handle = TransitionData::New( map ); + DALI_TEST_CHECK( handle ); + + TransitionData transitionData = TransitionData::DownCast( handle ); + DALI_TEST_CHECK( transitionData ); + END_TEST; +} + +int UtcDaliTransitionDataCopyConstructor(void) +{ + TestApplication application; + + Property::Map map = CreateMap(); + + TransitionData transitionData = TransitionData::New( map ); + DALI_TEST_CHECK( transitionData ); + + TransitionData td2( transitionData ); + DALI_TEST_CHECK( td2 ); + DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliTransitionDataAssignmentOperator(void) +{ + TestApplication application; + + Property::Map map = CreateMap(); + + TransitionData transitionData = TransitionData::New( map ); + DALI_TEST_CHECK( transitionData ); + + TransitionData td2; + DALI_TEST_CHECK( !td2 ); + + td2 = transitionData; + DALI_TEST_CHECK( td2 ); + + DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliTransitionDataCount(void) +{ + TestApplication application; + + Property::Map map = CreateMap(); + TransitionData transitionData = TransitionData::New( map ); + DALI_TEST_CHECK( transitionData ); + DALI_TEST_EQUALS( transitionData.Count(), 1, TEST_LOCATION ); + + Property::Array array; + array.PushBack( map ); + array.PushBack( map ); + array.PushBack( map ); + + TransitionData transitionData2 = TransitionData::New( array ); + DALI_TEST_CHECK( transitionData2 ); + DALI_TEST_EQUALS( transitionData2.Count(), 3, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTransitionDataMap1P(void) +{ + TestApplication application; + + tet_printf("Testing animation of a visual property using stylesheet equivalent maps\n"); + + Property::Map map; + map["target"] = "visual1"; + map["property"] = "mixColor"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + + Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + + DummyControl actor = DummyControl::New(); + actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + actor.SetName("Actor1"); + actor.SetColor(Color::CYAN); + Stage::GetCurrent().Add(actor); + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + + Property::Map visualMap; + visualMap[Visual::Property::TYPE] = Visual::COLOR; + visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA; + Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap ); + visual.SetName( "visual1" ); + + Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1; + dummyImpl.RegisterVisual( visualIndex, actor, visual ); + + Animation anim = dummyImpl.CreateTransition( transition ); + DALI_TEST_CHECK( anim ); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR ); + application.SendNotification(); + application.Render(0); + + DALI_TEST_EQUALS( renderer.GetProperty(mixColorIndex), Color::MAGENTA, TEST_LOCATION); + + anim.Play(); + + application.SendNotification(); + application.Render(0); + application.Render(500); // Start animation + application.Render(500); // Halfway thru anim + application.SendNotification(); + DALI_TEST_EQUALS( renderer.GetProperty(mixColorIndex), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION); + + application.Render(500); // End of anim + application.SendNotification(); + DALI_TEST_EQUALS( renderer.GetProperty(mixColorIndex), Color::RED, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTransitionDataMap2P(void) +{ + TestApplication application; + + tet_printf("Testing animation of a visual property using programmatic maps\n"); + + Property::Map map; + map["target"] = "visual1"; + //Control::CONTROL_PROPERTY_END_INDEX + 1 + map["property"] = ColorVisual::Property::MIX_COLOR; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", "LINEAR") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + + Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + + DummyControl actor = DummyControl::New(); + actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + actor.SetName("Actor1"); + actor.SetColor(Color::CYAN); + Stage::GetCurrent().Add(actor); + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + + Property::Map visualMap; + visualMap[Visual::Property::TYPE] = Visual::COLOR; + visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA; + Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap ); + visual.SetName( "visual1" ); + + Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1; + dummyImpl.RegisterVisual( visualIndex, actor, visual ); + + Animation anim = dummyImpl.CreateTransition( transition ); + DALI_TEST_CHECK( anim ); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR ); + application.SendNotification(); + application.Render(0); + + DALI_TEST_EQUALS( renderer.GetProperty(mixColorIndex), Color::MAGENTA, TEST_LOCATION); + + anim.Play(); + + application.SendNotification(); + application.Render(0); + application.Render(500); // Start animation + application.Render(500); // Halfway thru anim + application.SendNotification(); + DALI_TEST_EQUALS( renderer.GetProperty(mixColorIndex), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION); + + application.Render(500); // End of anim + application.SendNotification(); + DALI_TEST_EQUALS( renderer.GetProperty(mixColorIndex), Color::RED, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliTransitionDataMapP3(void) +{ + TestApplication application; + + tet_printf("Testing animation of a visual's placement actor property\n"); + + Property::Map map; + map["target"] = "visual1"; + map["property"] = "color"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + + Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + + DummyControl actor = DummyControl::New(); + actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + actor.SetName("Actor1"); + actor.SetColor(Color::CYAN); + Stage::GetCurrent().Add(actor); + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + + Property::Map visualMap; + visualMap[Visual::Property::TYPE] = Visual::COLOR; + visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA; + Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap ); + visual.SetName( "visual1" ); + + Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1; + dummyImpl.RegisterVisual( visualIndex, actor, visual ); + + Animation anim = dummyImpl.CreateTransition( transition ); + DALI_TEST_CHECK( anim ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION); + + anim.Play(); + + application.SendNotification(); + application.Render(0); + application.Render(500); + application.Render(500); // Halfway thru map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION); + + application.Render(500); // End of map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliTransitionDataMap1N(void) +{ + TestApplication application; + + Property::Map map; + map["target"] = "Actor1"; + map["property"] = "randomProperty"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", "EASE_OUT") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + + Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + + DummyControl actor = DummyControl::New(); + actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + actor.SetName("Actor1"); + actor.SetColor(Color::CYAN); + Stage::GetCurrent().Add(actor); + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + Animation anim = dummyImpl.CreateTransition( transition ); + DALI_TEST_CHECK( ! anim ); + + CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) ); + END_TEST; +} + + +int UtcDaliTransitionDataMapN3(void) +{ + TestApplication application; + + tet_printf("Testing visual lookup with no renderers\n"); + + Property::Map map; + map["target"] = "visual1"; + map["property"] = "mixColor"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", "EASE_OUT_BACK") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + + Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) ); + + DummyControl actor = DummyControl::New(); + actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + actor.SetName("Actor1"); + actor.SetColor(Color::CYAN); + // Don't stage actor + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + Property::Map visualMap; + visualMap[Visual::Property::TYPE] = Visual::COLOR; + visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA; + Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap ); + visual.SetName( "visual1" ); + + Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1; + dummyImpl.RegisterVisual( visualIndex, actor, visual ); + + Animation anim = dummyImpl.CreateTransition( transition ); + DALI_TEST_CHECK( !anim ); + END_TEST; +} + +int UtcDaliTransitionDataArrayP(void) +{ + TestApplication application; + + Property::Map map1; + map1["target"] = "Actor1"; + map1["property"] = "color"; + map1["initialValue"] = Color::MAGENTA; + map1["targetValue"] = Color::RED; + map1["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + + Property::Map map2; + map2["target"] = "Actor1"; + map2["property"] = "position"; + map2["initialValue"] = Vector3(100,0,0); + map2["targetValue"] = Vector3(0,100,0); + map2["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT") + .Add("timePeriod", Property::Map() + .Add("delay", 0.0f) + .Add("duration", 1.0f)); + + Property::Map map3; + map3["target"] = "Actor1"; + map3["property"] = "orientation"; + map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS ); + + Property::Array array; + array.PushBack(map1); + array.PushBack(map2); + array.PushBack(map3); + + Dali::Toolkit::TransitionData transition = TransitionData::New( array ); + + DummyControl actor = DummyControl::New(); + actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + actor.SetName("Actor1"); + actor.SetColor(Color::CYAN); + Stage::GetCurrent().Add(actor); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION); + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + Animation anim = dummyImpl.CreateTransition( transition ); + DALI_TEST_CHECK( anim ); + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION); + DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION); + anim.Play(); + + application.SendNotification(); + application.Render(0); // start map2 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION); + + application.Render(500); // Start map1 animation, halfway thru map2 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION); + + application.Render(500); // Halfway thru map1 anim, end of map2 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION); + DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION); + + application.Render(500); // End of map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliTransitionDataGetAnimatorP(void) +{ + TestApplication application; + + Property::Map map1; + map1["target"] = "Actor1"; + map1["property"] = "color"; + map1["initialValue"] = Color::MAGENTA; + map1["targetValue"] = Color::RED; + map1["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_SQUARE") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 0.5f)); + + Property::Map map2; + map2["target"] = "Actor1"; + map2["property"] = "position"; + map2["initialValue"] = Vector3(100,0,0); + map2["targetValue"] = Vector3(0,100,0); + map2["animator"] = Property::Map() + .Add("alphaFunction", "EASE_OUT_SQUARE") + .Add("timePeriod", Property::Map() + .Add("delay", 0.2f) + .Add("duration", 2.0f)); + + Property::Map map3; + map3["target"] = "Actor1"; + map3["property"] = "size"; + map3["initialValue"] = Vector2(10,10); + map3["targetValue"] = Vector2(100,100); + map3["animator"] = Property::Map() + .Add("alphaFunction", "EASE_OUT_SINE") + .Add("timePeriod", Property::Map() + .Add("delay", 0.4f) + .Add("duration", 3.0f)); + + Property::Map map4; + map4["target"] = "Actor2"; + map4["property"] = "color"; + map4["initialValue"] = Color::BLACK; + map4["targetValue"] = Color::GREEN; + map4["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT_SINE") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 0.5f)); + + Property::Map map5; + map5["target"] = "Actor2"; + map5["property"] = "position"; + map5["initialValue"] = Vector3(100,0,0); + map5["targetValue"] = Vector3(0,100,0); + map5["animator"] = Property::Map() + .Add("alphaFunction", "BOUNCE") + .Add("timePeriod", Property::Map() + .Add("delay", 0.2f) + .Add("duration", 2.0f)); + + Property::Map map6; + map6["target"] = "Actor2"; + map6["property"] = "size"; + map6["initialValue"] = Vector2(10,10); + map6["targetValue"] = Vector2(100,100); + map6["animator"] = Property::Map() + .Add("alphaFunction", "SIN") + .Add("timePeriod", Property::Map() + .Add("delay", 0.4f) + .Add("duration", 3.0f)); + + Property::Map map7; + map7["target"] = "Actor4"; + map7["property"] = "sizeModeFactor"; + map7["initialValue"] = Vector3(1,1,1); + map7["targetValue"] = Vector3(2,2,2); + map7["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_SINE") + .Add("timePeriod", Property::Map() + .Add("delay", 0.0f) + .Add("duration", 1.0f)); + + Property::Map map8; + map8["target"] = "Visual1"; + map8["property"] = "colorAlpha"; + map8["targetValue"] = 1.0f; + map8["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN") + .Add("timePeriod", Property::Map() + .Add("delay", 0.3f) + .Add("duration", 9.0f)); + + Property::Map map9; + map9["target"] = "Actor2"; + map9["property"] = "scale"; + map9["initialValue"] = Vector3(0,0,0); + map9["targetValue"] = Vector3(1,1,1); + map9["animator"] = Property::Map() + .Add("alphaFunction", "REVERSE") + .Add("timePeriod", Property::Map() + .Add("delay", 0.0f) + .Add("duration", 1.0f)); + + Property::Map map10; + map10["target"] = "Actor1"; + map10["property"] = "orientation"; + map10["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS ); + + Property::Array array; + array.PushBack(map1); + array.PushBack(map2); + array.PushBack(map3); + array.PushBack(map4); + array.PushBack(map5); + array.PushBack(map6); + array.PushBack(map7); + array.PushBack(map8); + array.PushBack(map9); + array.PushBack(map10); + + Dali::Toolkit::TransitionData transition = TransitionData::New( array ); + + DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION ); + + for( unsigned int i=0; i < array.Count(); ++i ) + { + Property::Map animatorMap = transition.GetAnimatorAt(i); + Property::Value& value = array.GetElementAt(i); + Property::Map* inputMap = value.GetMap(); + DALI_TEST_CHECK( inputMap ); + CHECK_MAP_EQUALS( *inputMap, animatorMap ); + } + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 0b767d7..35c224e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -24,6 +24,7 @@ #include #include #include +#include "dummy-control.h" using namespace Dali; using namespace Dali::Toolkit; @@ -83,6 +84,25 @@ int UtcDaliVisualCopyAndAssignment(void) END_TEST; } +int UtcDaliVisualSetName01(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualSetName" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + Visual::Base visual = factory.CreateVisual( propertyMap ); + + const char* visualName = "backgroundVisual"; + visual.SetName( visualName ); + + DALI_TEST_EQUALS( visual.GetName(), visualName, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliVisualSetGetDepthIndex(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index 509f22e..5bcf750 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -29,6 +29,7 @@ devel_api_src_files = \ $(devel_api_src_dir)/transition-effects/cube-transition-effect.cpp \ $(devel_api_src_dir)/transition-effects/cube-transition-fold-effect.cpp \ $(devel_api_src_dir)/transition-effects/cube-transition-wave-effect.cpp \ + $(devel_api_src_dir)/visual-factory/transition-data.cpp \ $(devel_api_src_dir)/visual-factory/visual-factory.cpp \ $(devel_api_src_dir)/visual-factory/visual-base.cpp \ $(devel_api_src_dir)/controls/gaussian-blur-view/gaussian-blur-view.cpp @@ -72,6 +73,7 @@ devel_api_progress_bar_header_files = \ $(devel_api_src_dir)/controls/progress-bar/progress-bar.h devel_api_visual_factory_header_files = \ + $(devel_api_src_dir)/visual-factory/transition-data.h \ $(devel_api_src_dir)/visual-factory/visual-factory.h \ $(devel_api_src_dir)/visual-factory/visual-base.h diff --git a/dali-toolkit/devel-api/visual-factory/transition-data.cpp b/dali-toolkit/devel-api/visual-factory/transition-data.cpp new file mode 100644 index 0000000..86d6128 --- /dev/null +++ b/dali-toolkit/devel-api/visual-factory/transition-data.cpp @@ -0,0 +1,77 @@ +/* + * 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 Dali +{ +namespace Toolkit +{ + +TransitionData::TransitionData() +{ +} + +TransitionData::~TransitionData() +{ +} + +TransitionData TransitionData::New( const Property::Array& transition ) +{ + Internal::TransitionDataPtr transitionData = Internal::TransitionData::New( transition ); + return TransitionData( transitionData.Get() ); +} + +TransitionData TransitionData::New( const Property::Map& transition ) +{ + Internal::TransitionDataPtr transitionData = Internal::TransitionData::New( transition ); + return TransitionData( transitionData.Get() ); +} + +TransitionData TransitionData::DownCast( BaseHandle handle ) +{ + return TransitionData( dynamic_cast(handle.GetObjectPtr())); +} + +TransitionData::TransitionData( const TransitionData& handle ) +: BaseHandle( handle ) +{ +} + +TransitionData& TransitionData::operator=( const TransitionData& handle ) +{ + BaseHandle::operator=( handle ); + return *this; +} + +size_t TransitionData::Count() const +{ + return GetImplementation( *this ).Count(); +} + +Property::Map TransitionData::GetAnimatorAt( size_t index ) +{ + return GetImplementation( *this ).GetAnimatorAt( index ); +} + +TransitionData::TransitionData( Internal::TransitionData* pointer ) +: BaseHandle( pointer ) +{ +} + +} // namespace Toolkit +} // namespace Dali diff --git a/dali-toolkit/devel-api/visual-factory/transition-data.h b/dali-toolkit/devel-api/visual-factory/transition-data.h new file mode 100644 index 0000000..23dfb2c --- /dev/null +++ b/dali-toolkit/devel-api/visual-factory/transition-data.h @@ -0,0 +1,156 @@ +#ifndef __DALI_TOOLKIT_TRANSITION_DATA_H__ +#define __DALI_TOOLKIT_TRANSITION_DATA_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 + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ +class TransitionData; +} + +/** + * @brief This object translates data from a property array of maps + * into an array of animators. + * + * Each animator describes a named object and a named property of that object + * to be animated. Internally, these are translated into object instances and + * property indices to be animated. + * @see Dali::Toolkit::Internal::Control::CreateTransition() + * + * The animators can each be retrieved as a Property::Map by using Count() and + * GetAnimatorAt(). + * + * In psuedo-JSON, the property array can be represented as follows: + * + * [ + * { + * "target": "objectName", + * "property": "propertyKey", + * "initialValue": , # The property value can be one of several types + * "targetValue": , + * "animator": { + * "alphaFunction":", + * "timePeriod":{ + * "duration": 1.0, + * "delay": 0.0 + * } + * } + * }, + * # more animators + * ] + * + */ +class DALI_IMPORT_API TransitionData : public BaseHandle +{ +public: + /** + * Create an uninitialized handle + * + * @SINCE_1_2.12 + */ + TransitionData(); + + /** + * Destructor - non virtual + * + * @SINCE_1_2.12 + */ + ~TransitionData(); + + /** + * @brief Creates a TransitionData object + * + * @SINCE_1_2.12 + * @param[in] transition The transition data to store (a single animator) + * @return A handle to an initialized data. + */ + static TransitionData New( const Property::Map& transition ); + + /** + * @brief Creates a TransitionData object + * + * @SINCE_1_2.12 + * @param[in] transition The transition data to store (an array of maps of animators) + * @return A handle to an initialized data. + */ + static TransitionData New( const Property::Array& transition ); + + /** + * @brief Downcast to a TransitionData handle + * + * @SINCE_1_2.12 + * If handle is not a TransitionData, the returned handle is left uninitialized. + * @param[in] handle Handle to an object + * @return TransitionData handle or an uninitialized handle. + */ + static TransitionData DownCast( BaseHandle handle ); + + /** + * @brief Copy constructor + * + * @SINCE_1_2.12 + * @param[in] handle Handle to an object + */ + TransitionData( const TransitionData& handle ); + + /** + * @brief Assignment Operator + * + * @SINCE_1_2.12 + * @param[in] handle Handle to an object + * @return A reference to this object. + */ + TransitionData& operator=( const TransitionData& handle ); + + /** + * @brief returns the count of the individual property transitions + * stored within this handle. + * + * @SINCE_1_2.12 + * @return The count of individual transitions + */ + size_t Count() const; + + /** + * @brief Return the animator at the given index as a property map. + * @param[in] index The index of the animator ( Must be less than Count() ) + * @return A property map representing the animator + */ + Property::Map GetAnimatorAt( size_t index ); + +public: // Not intended for application developers + + explicit DALI_INTERNAL TransitionData( Internal::TransitionData *impl ); +}; + +} // namespace Toolkit +} // namespace Dali + +#endif // __DALI_TOOLKIT_TRANSITION_DATA_H__ diff --git a/dali-toolkit/devel-api/visual-factory/visual-base.cpp b/dali-toolkit/devel-api/visual-factory/visual-base.cpp index 52f7f3e..c40bc41 100644 --- a/dali-toolkit/devel-api/visual-factory/visual-base.cpp +++ b/dali-toolkit/devel-api/visual-factory/visual-base.cpp @@ -51,6 +51,16 @@ Visual::Base::Base(Internal::Visual::Base *impl) { } +void Visual::Base::SetName( const std::string& name ) +{ + GetImplementation( *this ).SetName( name ); +} + +const std::string& Visual::Base::GetName() +{ + return GetImplementation( *this ).GetName(); +} + void Visual::Base::SetSize( const Vector2& size ) { GetImplementation( *this ).SetSize( size ); diff --git a/dali-toolkit/devel-api/visual-factory/visual-base.h b/dali-toolkit/devel-api/visual-factory/visual-base.h index 075ef0f..2cbb0b7 100644 --- a/dali-toolkit/devel-api/visual-factory/visual-base.h +++ b/dali-toolkit/devel-api/visual-factory/visual-base.h @@ -76,6 +76,22 @@ public: Base& operator=( const Base& handle ); /** + * @brief Set the name of the visual + * + * Used by the styling system to animate properties + * @param[in] name The name to give the visual + */ + void SetName( const std::string& name ); + + /** + * @brief Get the name of the visual + * + * Used by the styling system to animate properties + * @return The name of the visual + */ + const std::string& GetName(); + + /** * @brief Set the size of the painting area. * * @param[in] size The size of the painting area. diff --git a/dali-toolkit/internal/builder/replacement.cpp b/dali-toolkit/internal/builder/replacement.cpp index 446a014..07240be 100644 --- a/dali-toolkit/internal/builder/replacement.cpp +++ b/dali-toolkit/internal/builder/replacement.cpp @@ -583,4 +583,3 @@ bool Replacement::IsArray( OptionalChild child, Property::Value& out ) const } // namespace Toolkit } // namespace Dali - diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index 7514ea5..57b4dbf 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -31,6 +31,7 @@ toolkit_src_files = \ $(toolkit_src_dir)/visuals/svg/svg-visual.cpp \ $(toolkit_src_dir)/visuals/text/text-visual.cpp \ $(toolkit_src_dir)/visuals/wireframe/wireframe-visual.cpp \ + $(toolkit_src_dir)/visuals/transition-data-impl.cpp \ $(toolkit_src_dir)/controls/alignment/alignment-impl.cpp \ $(toolkit_src_dir)/controls/bloom-view/bloom-view-impl.cpp \ $(toolkit_src_dir)/controls/bubble-effect/bubble-emitter-impl.cpp \ diff --git a/dali-toolkit/internal/visuals/transition-data-impl.cpp b/dali-toolkit/internal/visuals/transition-data-impl.cpp new file mode 100644 index 0000000..30c0dee --- /dev/null +++ b/dali-toolkit/internal/visuals/transition-data-impl.cpp @@ -0,0 +1,323 @@ +/* + * 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. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL HEADERS +#include +#include +#include +#include +#include +#include + +using namespace Dali; + +namespace +{ +const char* TOKEN_TARGET("target"); +const char* TOKEN_PROPERTY("property"); +const char* TOKEN_INITIAL_VALUE("initialValue"); +const char* TOKEN_TARGET_VALUE("targetValue"); +const char* TOKEN_ANIMATOR("animator"); +const char* TOKEN_TIME_PERIOD("timePeriod"); +const char* TOKEN_DURATION("duration"); +const char* TOKEN_DELAY("delay"); +const char* TOKEN_ALPHA_FUNCTION("alphaFunction"); + + +DALI_ENUM_TO_STRING_TABLE_BEGIN( ALPHA_FUNCTION_BUILTIN ) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, LINEAR) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, REVERSE) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_IN) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_OUT) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_IN_OUT) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_IN_SQUARE) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_OUT_SQUARE) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_IN_SINE) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_OUT_SINE) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_IN_OUT_SINE) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, EASE_OUT_BACK) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, BOUNCE) +DALI_ENUM_TO_STRING_WITH_SCOPE(AlphaFunction, SIN) +DALI_ENUM_TO_STRING_TABLE_END( ALPHA_FUNCTION_BUILTIN ) +} + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal +{ + +TransitionData::TransitionData() +{ +} + +TransitionData::~TransitionData() +{ +} + +TransitionDataPtr TransitionData::New( const Property::Array& value ) +{ + TransitionDataPtr transitionData( new TransitionData() ); + transitionData->Initialize(value); + return transitionData; +} + +TransitionDataPtr TransitionData::New( const Property::Map& value ) +{ + TransitionDataPtr transitionData( new TransitionData() ); + transitionData->Initialize(value); + return transitionData; +} + + +void TransitionData::Initialize( const Property::Map& map ) +{ + TransitionData::Animator* animator = ConvertMap( map ); + Add( animator ); +} + +void TransitionData::Initialize( const Property::Array& array ) +{ + for( unsigned int arrayIdx = 0, transitionArrayCount = array.Count(); arrayIdx < transitionArrayCount; ++arrayIdx ) + { + const Property::Value& element = array.GetElementAt( arrayIdx ); + // Expect each child to be an object representing an animator: + + Property::Map* map = element.GetMap(); + if( map != NULL ) + { + TransitionData::Animator* animator = ConvertMap( *map ); + Add( animator ); + } + } +} + +TransitionData::Animator* TransitionData::ConvertMap( const Property::Map& map) +{ + TransitionData::Animator* animator = new TransitionData::Animator(); + animator->alphaFunction = AlphaFunction::LINEAR; + animator->timePeriodDelay = 0.0f; + animator->timePeriodDuration = 1.0f; + + for( unsigned int mapIdx = 0; mapIdx < map.Count(); ++mapIdx ) + { + const KeyValuePair pair( map.GetKeyValue( mapIdx ) ); + if( pair.first.type == Property::Key::INDEX ) + { + continue; // We don't consider index keys. + } + + const std::string& key( pair.first.stringKey ); + const Property::Value& value( pair.second ); + + if( key == TOKEN_TARGET ) + { + animator->objectName = value.Get< std::string >(); + } + else if( key == TOKEN_PROPERTY ) + { + if( value.GetType() == Property::STRING ) + { + animator->propertyKey = Property::Key( value.Get() ); + } + else + { + animator->propertyKey = Property::Key( value.Get() ); + } + } + else if( key == TOKEN_INITIAL_VALUE ) + { + animator->initialValue = value; + } + else if( key == TOKEN_TARGET_VALUE ) + { + animator->targetValue = value; + } + else if( key == TOKEN_ANIMATOR ) + { + animator->animate = true; + Property::Map animatorMap = value.Get< Property::Map >(); + for( size_t animatorMapIdx = 0; animatorMapIdx < animatorMap.Count(); ++animatorMapIdx ) + { + const KeyValuePair pair( animatorMap.GetKeyValue( animatorMapIdx ) ); + + if( pair.first.type == Property::Key::INDEX ) + { + continue; // We don't consider index keys. + } + + const std::string& key( pair.first.stringKey ); + const Property::Value& value( pair.second ); + + if( key == TOKEN_ALPHA_FUNCTION ) + { + std::string alphaFunctionValue = value.Get< std::string >(); + + if( alphaFunctionValue == "LINEAR" ) + { + animator->alphaFunction = AlphaFunction::LINEAR; + } + else if( ! alphaFunctionValue.compare(0, 5, "EASE_" ) ) + { + if( alphaFunctionValue == "EASE_IN" ) + { + animator->alphaFunction = AlphaFunction::EASE_IN; + } + else if( alphaFunctionValue == "EASE_OUT" ) + { + animator->alphaFunction = AlphaFunction::EASE_OUT; + } + else if( ! alphaFunctionValue.compare( 5, 3, "IN_" ) ) + { + if( ! alphaFunctionValue.compare(8, -1, "SQUARE" )) + { + animator->alphaFunction = AlphaFunction::EASE_IN_SQUARE; + } + else if( ! alphaFunctionValue.compare(8, -1, "OUT" )) + { + animator->alphaFunction = AlphaFunction::EASE_IN_OUT; + } + else if( ! alphaFunctionValue.compare(8, -1, "OUT_SINE" )) + { + animator->alphaFunction = AlphaFunction::EASE_IN_OUT_SINE; + } + else if( ! alphaFunctionValue.compare(8, -1, "SINE" )) + { + animator->alphaFunction = AlphaFunction::EASE_IN_SINE; + } + } + else if( ! alphaFunctionValue.compare( 5, 4, "OUT_" ) ) + { + if( ! alphaFunctionValue.compare(9, -1, "SQUARE" ) ) + { + animator->alphaFunction = AlphaFunction::EASE_OUT_SQUARE; + } + else if( ! alphaFunctionValue.compare(9, -1, "SINE" ) ) + { + animator->alphaFunction = AlphaFunction::EASE_OUT_SINE; + } + else if( ! alphaFunctionValue.compare(9, -1, "BACK" ) ) + { + animator->alphaFunction = AlphaFunction::EASE_OUT_BACK; + } + } + } + else if( alphaFunctionValue == "REVERSE" ) + { + animator->alphaFunction = AlphaFunction::REVERSE; + } + else if( alphaFunctionValue == "BOUNCE" ) + { + animator->alphaFunction = AlphaFunction::BOUNCE; + } + else if( alphaFunctionValue == "SIN" ) + { + animator->alphaFunction = AlphaFunction::SIN; + } + } + else if( key == TOKEN_TIME_PERIOD ) + { + Property::Map timeMap = value.Get< Property::Map >(); + for( size_t timeMapIdx = 0; timeMapIdx < timeMap.Count(); ++timeMapIdx ) + { + const KeyValuePair pair( timeMap.GetKeyValue( timeMapIdx ) ); + if( pair.first.type == Property::Key::INDEX ) + { + continue; + } + const std::string& key( pair.first.stringKey ); + + if( key == TOKEN_DELAY ) + { + animator->timePeriodDelay = pair.second.Get< float >(); + } + else if( key == TOKEN_DURATION ) + { + animator->timePeriodDuration = pair.second.Get< float >(); + } + } + } + } + } + } + return animator; +} + +void TransitionData::Add( Animator* animator ) +{ + mAnimators.PushBack( animator ); +} + +TransitionData::Iterator TransitionData::Begin() const +{ + return mAnimators.Begin(); +} + +TransitionData::Iterator TransitionData::End() const +{ + return mAnimators.End(); +} + +size_t TransitionData::Count() const +{ + return mAnimators.Count(); +} + +Property::Map TransitionData::GetAnimatorAt( size_t index ) +{ + DALI_ASSERT_ALWAYS( index < Count() && "index exceeds bounds" ); + + Animator* animator = mAnimators[index]; + Property::Map map; + map[TOKEN_TARGET] = animator->objectName; + if( animator->propertyKey.type == Property::Key::INDEX ) + { + map[TOKEN_PROPERTY] = animator->propertyKey.indexKey; + } + else + { + map[TOKEN_PROPERTY] = animator->propertyKey.stringKey; + } + if( animator->initialValue.GetType() != Property::NONE ) + { + map[TOKEN_INITIAL_VALUE] = animator->initialValue; + } + if( animator->targetValue.GetType() != Property::NONE ) + { + map[TOKEN_TARGET_VALUE] = animator->targetValue; + } + if( animator->animate ) + { + map[TOKEN_ANIMATOR] = Property::Map() + .Add(TOKEN_ALPHA_FUNCTION, GetEnumerationName( animator->alphaFunction, + ALPHA_FUNCTION_BUILTIN_TABLE, + ALPHA_FUNCTION_BUILTIN_TABLE_COUNT )) + .Add(TOKEN_TIME_PERIOD, Property::Map() + .Add( TOKEN_DELAY, animator->timePeriodDelay ) + .Add( TOKEN_DURATION, animator->timePeriodDuration )); + } + + return map; +} + +} // namespace Internal +} // namespace Toolkit +} // namespace Dali diff --git a/dali-toolkit/internal/visuals/transition-data-impl.h b/dali-toolkit/internal/visuals/transition-data-impl.h new file mode 100644 index 0000000..9622951 --- /dev/null +++ b/dali-toolkit/internal/visuals/transition-data-impl.h @@ -0,0 +1,170 @@ +#ifndef DALI_TOOLKIT_INTERNAL_TRANSITION_DATA_H +#define DALI_TOOLKIT_INTERNAL_TRANSITION_DATA_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 + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal +{ + +class TransitionData; +typedef IntrusivePtr TransitionDataPtr; + +/** + * TransitionData is an object that holds animator data. + */ +class TransitionData : public BaseObject +{ +public: + + /** + * @brief TransitionDataElement Describes one animator of an transition. + */ + struct Animator + { + Animator() + : propertyKey( Property::INVALID_INDEX ), + alphaFunction( AlphaFunction::DEFAULT ), + timePeriodDelay( 0.0f ), + timePeriodDuration( 1.0f ), + animate(false) + { + } + + std::string objectName; ///< An identifier of the actor or visual + Property::Key propertyKey; ///< A property key of the property owner + Property::Value initialValue; ///< The value to set at the start of the transition + Property::Value targetValue; ///< The value to set or animate to + Dali::AlphaFunction::BuiltinFunction alphaFunction; + float timePeriodDelay; + float timePeriodDuration; + bool animate; + }; + + /** + * @brief TransitionData holds the required data required to define an + * transition to be performed on a property owner + */ + typedef Dali::OwnerContainer< Animator* > AnimatorList; + typedef AnimatorList::Iterator Iterator; + +public: + /** + * @copydoc Dali::Transition::New() + */ + static TransitionDataPtr New( const Property::Array& value ); + + /** + * @copydoc Dali::Transition::New() + */ + static TransitionDataPtr New( const Property::Map& value ); + + /** + * @brief Iterator to the beginning of the data + */ + Iterator Begin() const; + + /** + * @brief Iterator to the end of the data (one past last element) + */ + Iterator End() const; + + /** + * @copydoc Dali::Transition::Count() + */ + size_t Count() const; + + /** + * @copydoc Dali::Transition::GetAnimatorAt() + */ + Property::Map GetAnimatorAt( size_t index ); + +private: // Implementation + /** + * Ref counted object - Only allow construction via New(). + */ + TransitionData(); + + /** + * Second stage initialiazation + */ + void Initialize( const Property::Map& value ); + + /** + * Second stage initialiazation + */ + void Initialize( const Property::Array& value ); + + /** + * @brief Adds one Animator to the list to describe a transition. + * @param[in] animator An animator data structure + */ + void Add( Animator* animator ); + + /** + * Convert a Property map into Animator data + */ + Animator* ConvertMap( const Property::Map& map ); + +protected: + /** + * A ref counted object may only be deleted by calling Unreference + */ + virtual ~TransitionData(); + +private: // Unimplemented methods + TransitionData( const TransitionData& ); + TransitionData& operator=( const TransitionData& ); + +private: // Data members + AnimatorList mAnimators; ///< A vector of individual property transitions from which to generate a Dali::Animation. +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods +inline Internal::TransitionData& GetImplementation( Dali::Toolkit::TransitionData& handle ) +{ + DALI_ASSERT_ALWAYS(handle && "TransitionData handle is empty"); + BaseObject& object = handle.GetBaseObject(); + return static_cast(object); +} + +inline const Internal::TransitionData& GetImplementation( const Dali::Toolkit::TransitionData& handle ) +{ + DALI_ASSERT_ALWAYS(handle && "TransitionData handle is empty"); + const BaseObject& object = handle.GetBaseObject(); + return static_cast(object); +} + +} // namespace Toolkit +} // namespace Dali + + +#endif // DALI_TOOLKIT_INTERNAL_TRANSITION_DATA_H diff --git a/dali-toolkit/internal/visuals/visual-base-data-impl.h b/dali-toolkit/internal/visuals/visual-base-data-impl.h index 524057e..c4877b4 100644 --- a/dali-toolkit/internal/visuals/visual-base-data-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-data-impl.h @@ -60,13 +60,12 @@ struct Base::Impl void CreatePropertyMap( Property::Map& map ) const; }; - Renderer mRenderer; - + Renderer mRenderer; CustomShader* mCustomShader; - - Vector2 mSize; - float mDepthIndex; - int mFlags; + std::string mName; + Vector2 mSize; + float mDepthIndex; + int mFlags; Impl(); ~Impl(); diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 86d2114..48df29a 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -55,7 +55,7 @@ void Visual::Base::SetCustomShader( const Property::Map& shaderMap ) } else { - mImpl->mCustomShader = new Impl::CustomShader( shaderMap ); + mImpl->mCustomShader = new Impl::CustomShader( shaderMap ); } } @@ -74,6 +74,16 @@ void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap ) DoInitialize( actor, propertyMap ); } +void Visual::Base::SetName( const std::string& name ) +{ + mImpl->mName = name; +} + +const std::string& Visual::Base::GetName() +{ + return mImpl->mName; +} + void Visual::Base::SetSize( const Vector2& size ) { mImpl->mSize = size; diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 23394ad..475a5fa 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -76,6 +76,16 @@ public: void Initialize( Actor& actor, const Property::Map& propertyMap ); /** + * @copydoc Toolkit::Visual::Base::SetName + */ + void SetName( const std::string& name ); + + /** + * @copydoc Toolkit::Visual::Base::GetName + */ + const std::string& GetName(); + + /** * @copydoc Toolkit::Visual::Base::SetSize */ virtual void SetSize( const Vector2& size ); diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 58d2d92..6c4b211 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -42,6 +42,7 @@ #include #include #include +#include namespace Dali { @@ -52,6 +53,10 @@ namespace Toolkit namespace { +#if defined(DEBUG_ENABLED) +Debug::Filter* gLogFilter = Debug::Filter::New( Debug::General, false, "LOG_CONTROL_VISUALS"); +#endif + /** * Struct used to store Visual within the control, index is a unique key for each visual. */ @@ -66,6 +71,25 @@ struct RegisteredVisual index(aIndex), visual(aVisual), placementActor(aPlacementActor), enabled(aEnabled) {} }; +struct VisualProperty +{ + Handle handle; ///< a handle to the target object + Property::Index index; ///< The index of a property provided by the referenced object + + VisualProperty( ) + : handle(), + index( Property::INVALID_INDEX ) + { + } + + VisualProperty( Handle& handle, Property::Index index ) + : handle( handle ), + index( index ) + { + } +}; + + typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer; /** @@ -83,6 +107,71 @@ bool FindVisual( Property::Index targetIndex, RegisteredVisualContainer& visuals return false; } +VisualProperty GetVisualProperty( + Internal::Control& controlImpl, + RegisteredVisualContainer& visuals, + const std::string& visualName, + Property::Key propertyKey ) +{ +#if defined(DEBUG_ENABLED) + std::ostringstream oss; + oss << "Control::GetVisualProperty(" << visualName << ", " << propertyKey << ")" << std::endl; + DALI_LOG_INFO( gLogFilter, Debug::General, oss.str().c_str() ); +#endif + + // Find visualName in the control + RegisteredVisualContainer::Iterator iter; + for ( iter = visuals.Begin(); iter != visuals.End(); iter++ ) + { + if ( (*iter)->visual.GetName() == visualName ) + { + break; + } + } + + // Does either it's renderer or placement actor have an associated property? + if( iter != visuals.End() ) + { + Actor placementActor = (*iter)->placementActor; + if( !placementActor ) + { + placementActor = controlImpl.Self(); + } + + Property::Index index = placementActor.GetPropertyIndex( propertyKey ); + if( index != Property::INVALID_INDEX ) + { + // It's a placement actor property: + return VisualProperty( placementActor, index ); + } + else + { + // Check if it is a renderer property: + if( placementActor.GetRendererCount() > 0 ) + { + // @todo Need to use correct renderer index when placement actors + // are removed + Renderer renderer = placementActor.GetRendererAt(0); + Property::Index index = renderer.GetPropertyIndex( propertyKey ); + if( index != Property::INVALID_INDEX ) + { + // It's a renderer property: + return VisualProperty( renderer, index ); + } + } + else + { + std::ostringstream oss; + oss << propertyKey; + DALI_LOG_WARNING( "Control::GetVisualProperty(%s, %s) No renderers\n", visualName.c_str(), oss.str().c_str() ); + } + } + } + Handle handle; + return VisualProperty( handle, Property::INVALID_INDEX ); +} + + /** * Creates control through type registry */ @@ -207,21 +296,21 @@ public: // Construction & Destruction Impl(Control& controlImpl) -: mControlImpl( controlImpl ), - mStyleName(""), - mBackgroundVisual(), - mBackgroundColor(Color::TRANSPARENT), - mStartingPinchScale( NULL ), - mKeyEventSignal(), - mPinchGestureDetector(), - mPanGestureDetector(), - mTapGestureDetector(), - mLongPressGestureDetector(), - mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), - mIsKeyboardNavigationSupported( false ), - mIsKeyboardFocusGroup( false ) -{ -} + : mControlImpl( controlImpl ), + mStyleName(""), + mBackgroundVisual(), + mBackgroundColor(Color::TRANSPARENT), + mStartingPinchScale( NULL ), + mKeyEventSignal(), + mPinchGestureDetector(), + mPanGestureDetector(), + mTapGestureDetector(), + mLongPressGestureDetector(), + mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), + mIsKeyboardNavigationSupported( false ), + mIsKeyboardFocusGroup( false ) + { + } ~Impl() { @@ -791,6 +880,73 @@ Actor Control::GetPlacementActor( Property::Index index ) const return Actor(); } +Dali::Animation Control::CreateTransition( const Toolkit::TransitionData& handle ) +{ + Dali::Animation transition; + const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle ); + + if( transitionData.Count() > 0 ) + { + // Setup a Transition from TransitionData. + TransitionData::Iterator end = transitionData.End(); + for( TransitionData::Iterator iter = transitionData.Begin() ; + iter != end; ++iter ) + { + TransitionData::Animator* animator = (*iter); + VisualProperty visualProperty; + + // Attempt to find the object name as a child actor + Actor child = Self().FindChildByName( animator->objectName ); + if( child ) + { + Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey ); + visualProperty = VisualProperty( child, propertyIndex ); + } + else + { + // Is it a placement actor/visual pair?; + visualProperty = GetVisualProperty( *this, mImpl->mVisuals, + animator->objectName, + animator->propertyKey ); + } + + if( visualProperty.handle && visualProperty.index != Property::INVALID_INDEX ) + { + if( animator->animate == false ) + { + if( animator->targetValue.GetType() != Property::NONE ) + { + visualProperty.handle.SetProperty( visualProperty.index, animator->targetValue ); + } + } + else + { + if( animator->initialValue.GetType() != Property::NONE ) + { + visualProperty.handle.SetProperty( visualProperty.index, animator->initialValue ); + } + + if( ! transition ) + { + // Create an animation with a default .1 second duration - the animators + // will automatically force it to the 'right' duration. + transition = Dali::Animation::New( 0.1f ); + } + + transition.AnimateTo( Property( visualProperty.handle, visualProperty.index ), + animator->targetValue, + animator->alphaFunction, + TimePeriod( animator->timePeriodDelay, + animator->timePeriodDuration ) ); + } + } + } + } + + return transition; +} + + bool Control::OnAccessibilityActivated() { return false; // Accessibility activation is not handled by default diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index eb7d6a9..92786d4 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -32,22 +32,25 @@ namespace Dali { - namespace Toolkit { + /** * @addtogroup dali_toolkit_controls * @{ */ class StyleManager; +class TransitionData; namespace Visual { class Base; } + namespace Internal { + /** * @brief This is the internal base class for all controls. * @@ -308,73 +311,84 @@ protected: // For derived classes to call * @note Derived class should not call visual.SetOnStage(placementActor). It is the responsibility of the base class to connect/disconnect registered visual to stage. * Use below API with enabled set to false if derived class wishes to control when visual is staged. */ - void RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual ); - - /** - * @brief Register a visual by Property Index, linking an Actor to visual when required. - * In the case of the visual being an actor or control deeming visual not required then visual should be an empty handle. - * If enabled is false then the visual is not set on stage until enabled by the derived class. - * @see EnableVisual - * - * @SINCE_1_2.11 - * - * @param[in] index The Property index of the visual, used to reference visual - * @param[in] placementActor The actor used to by the visual. - * @param[in] visual The visual to register - * @param[in] enabled false if derived class wants to control when visual is set on stage. - * - */ - void RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual, bool enabled ); - - /** - * @brief Erase the entry matching the given index from the list of registered visuals - * @param[in] index The Property index of the visual, used to reference visual - * - * @SINCE_1_2.0 - */ - void UnregisterVisual( Property::Index index ); - - /** - * @brief Retrieve the visual associated with the given property index. - * - * @SINCE_1_2.2 - * - * @param[in] index The Property index of the visual. - * @return The registered visual if exist, otherwise empty handle. - * @note For managing object life-cycle, do not store the returned visual as a member which increments its reference count. - */ - Toolkit::Visual::Base GetVisual( Property::Index index ) const; - - /** - * @brief Sets the given visual to be displayed or not when parent staged. - * - * @SINCE_1_2.11 - * - * @param[in] index The Property index of the visual - * @param[in] enable flag to set enabled or disabled. - */ - void EnableVisual( Property::Index index, bool enable ); - - /** - * @brief Queries if the given visual is to be displayed when parent staged. - * - * @SINCE_1_2.11 - * - * @param[in] index The Property index of the visual - * @return bool whether visual is enabled or not - */ - bool IsVisualEnabled( Property::Index index ) const; - - /** - * @brief Retrieve the placement actor associated with the given index. - * - * @SINCE_1_2.2 - * - * @@param[in] index The Property index of the visual. - * @return Then placement actor if exist, otherwise empty handle. - * @note For managing object life-cycle, do not store the returned placement actor as a member which increments its reference count. - */ - Actor GetPlacementActor( Property::Index index ) const; + void RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual ); + + /** + * @brief Register a visual by Property Index, linking an Actor to visual when required. + * In the case of the visual being an actor or control deeming visual not required then visual should be an empty handle. + * If enabled is false then the visual is not set on stage until enabled by the derived class. + * @see EnableVisual + * + * @SINCE_1_2.11 + * + * @param[in] index The Property index of the visual, used to reference visual + * @param[in] placementActor The actor used to by the visual. + * @param[in] visual The visual to register + * @param[in] enabled false if derived class wants to control when visual is set on stage. + * + */ + void RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual, bool enabled ); + + /** + * @brief Erase the entry matching the given index from the list of registered visuals + * @param[in] index The Property index of the visual, used to reference visual + * + * @SINCE_1_2.0 + */ + void UnregisterVisual( Property::Index index ); + + /** + * @brief Retrieve the visual associated with the given property index. + * + * @SINCE_1_2.2 + * + * @param[in] index The Property index of the visual. + * @return The registered visual if exist, otherwise empty handle. + * @note For managing object life-cycle, do not store the returned visual as a member which increments its reference count. + */ + Toolkit::Visual::Base GetVisual( Property::Index index ) const; + + /** + * @brief Sets the given visual to be displayed or not when parent staged. + * + * @SINCE_1_2.11 + * + * @param[in] index The Property index of the visual + * @param[in] enable flag to set enabled or disabled. + */ + void EnableVisual( Property::Index index, bool enable ); + + /** + * @brief Queries if the given visual is to be displayed when parent staged. + * + * @SINCE_1_2.11 + * + * @param[in] index The Property index of the visual + * @return bool whether visual is enabled or not + */ + bool IsVisualEnabled( Property::Index index ) const; + + /** + * @brief Retrieve the placement actor associated with the given index. + * + * @SINCE_1_2.2 + * + * @@param[in] index The Property index of the visual. + * @return Then placement actor if exist, otherwise empty handle. + * @note For managing object life-cycle, do not store the returned placement actor as a member which increments its reference count. + */ + Actor GetPlacementActor( Property::Index index ) const; + + /** + * @brief Create a transition effect on the control. + * + * @SINCE_1_2.12 + * + * @param[in] transitionData The transition data describing the effect to create + * @return A handle to an animation defined with the given effect, or an empty + * handle if no properties match. + */ + Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData ); /** * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal diff --git a/dali-toolkit/public-api/file.list b/dali-toolkit/public-api/file.list index 2439b45..3734525 100755 --- a/dali-toolkit/public-api/file.list +++ b/dali-toolkit/public-api/file.list @@ -25,10 +25,10 @@ public_api_src_files = \ $(public_api_src_dir)/controls/text-controls/text-editor.cpp \ $(public_api_src_dir)/controls/text-controls/text-label.cpp \ $(public_api_src_dir)/controls/text-controls/text-field.cpp \ + $(public_api_src_dir)/controls/video-view/video-view.cpp \ $(public_api_src_dir)/styling/style-manager.cpp \ $(public_api_src_dir)/accessibility-manager/accessibility-manager.cpp \ $(public_api_src_dir)/focus-manager/keyboard-focus-manager.cpp \ - $(public_api_src_dir)/controls/video-view/video-view.cpp \ $(public_api_src_dir)/dali-toolkit-version.cpp \ $(public_api_src_dir)/enums.cpp