From: Adeel Kazmi Date: Tue, 25 Oct 2016 14:32:44 +0000 (-0700) Subject: Merge "Changed README to README.md" into devel/master X-Git-Tag: dali_1.2.12~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=97d688bcdfb692dd2ff535c1965077dd747cfcf6;hp=94e850baaef23523b6e0c56daefd7b34c50c8a2c Merge "Changed README to README.md" 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..71851de --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp @@ -0,0 +1,916 @@ +/* + * 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_ARRAY_EQUALS( Property::Array test, Property::Value result ) +{ + if( result.GetType() == Property::ARRAY ) + { + // Compare arrays + Property::Array *resultArray = result.GetArray(); + DALI_TEST_EQUALS( test.Count(), resultArray->Count(), TEST_LOCATION ); + for( size_t i=0; i < std::min(test.Count(), resultArray->Count()); ++i ) + { + Property::Value a = test.GetElementAt(i); + Property::Value b = resultArray->GetElementAt(i); + DALI_TEST_EQUALS( a.GetType(), b.GetType(), TEST_LOCATION ); + DALI_TEST_EQUALS( a, b, 0.001, TEST_LOCATION ); + } + } + else if( result.GetType() == Property::VECTOR4 ) + { + Vector4 value = result.Get(); + DALI_TEST_CHECK( test.Count() >= 4 ); + for( size_t i=0; i < 4; ++i ) + { + Property::Value a = test.GetElementAt(i); + DALI_TEST_EQUALS( a.GetType(), Property::FLOAT, TEST_LOCATION ); + DALI_TEST_EQUALS( a.Get(), value[i], 0.001, TEST_LOCATION ); + } + } + else + { + DALI_TEST_CHECK( 0 ); + } +} + +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 ) + { + if( keyValue.second.GetType() == Property::MAP ) + { + DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION ); + CHECK_MAP_EQUALS( *(keyValue.second.GetMap()), *(value->GetMap()) ); + } + else if( keyValue.second.GetType() == Property::ARRAY ) + { + CHECK_ARRAY_EQUALS( *(keyValue.second.GetArray()), *value ); + } + else if( keyValue.second.GetType() == Property::STRING ) + { + DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION ); + std::string str; + value->Get(str); + DALI_TEST_EQUALS( keyValue.second, str.c_str(), TEST_LOCATION ); + } + else + { + DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION ); + 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 UtcDaliTransitionDataMap3P(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 UtcDaliTransitionDataMap4P(void) +{ + TestApplication application; + + tet_printf("Testing animation of a visual's placement actor property using bezier curve\n"); + + Property::Map map; + map["target"] = "Actor1"; + map["property"] = "position"; + map["initialValue"] = Vector3(0, 0, 0); + map["targetValue"] = Vector3(100, 100, 0); + map["animator"] = Property::Map() + .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) ) + .Add("timePeriod", Property::Map() + .Add("delay", 0.0f) + .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"); + Stage::GetCurrent().Add(actor); + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + Animation anim = dummyImpl.CreateTransition( transition ); + DALI_TEST_CHECK( anim ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION); + + anim.Play(); + + application.SendNotification(); + application.Render(0); + + application.Render(250); // 25% + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(-10,-10,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50% + + application.Render(250); // Halfway thru map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(24,24,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50% + + application.Render(250); // End of map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve + + application.Render(250); // End of map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), 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 UtcDaliTransitionDataMapN4(void) +{ + TestApplication application; + + tet_printf("Testing visual doesn't animate with duff bezier data \n"); + + Property::Map map; + map["target"] = "visual1"; + map["property"] = "mixColor"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", Vector3(.1f,1.0f,0.5f)) + .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); + application.SendNotification(); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index mixColorIdx = renderer.GetPropertyIndex(ColorVisual::Property::MIX_COLOR); + + tet_printf( "Test that the property has been set to target value\n"); + DALI_TEST_EQUALS(renderer.GetProperty(mixColorIdx), Color::RED, 0.001, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliTransitionDataMapN5(void) +{ + TestApplication application; + + tet_printf("Testing visual doesn't animate with duff bezier data \n"); + + Property::Map map; + map["target"] = "visual1"; + map["property"] = "mixColor"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f)) + .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); + application.SendNotification(); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index mixColorIdx = renderer.GetPropertyIndex(ColorVisual::Property::MIX_COLOR); + + tet_printf( "Test that the property has been set to target value\n"); + DALI_TEST_EQUALS(renderer.GetProperty(mixColorIdx), Color::RED, 0.001, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliTransitionDataMapN6(void) +{ + TestApplication application; + + tet_printf("Testing visual doesn't animate with duff bezier data \n"); + + Property::Map map; + map["target"] = "visual1"; + map["property"] = "mixColor"; + map["initialValue"] = Color::MAGENTA; + map["targetValue"] = Color::RED; + map["animator"] = Property::Map() + .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4")) + .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); + application.SendNotification(); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index mixColorIdx = renderer.GetPropertyIndex(ColorVisual::Property::MIX_COLOR); + + tet_printf( "Test that the property has been set to target value\n"); + DALI_TEST_EQUALS(renderer.GetProperty(mixColorIdx), Color::RED, 0.001, TEST_LOCATION); + + 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"] = "Actor2"; + map10["property"] = "scale"; + map10["initialValue"] = Vector3(0,0,0); + map10["targetValue"] = Vector3(1,1,1); + map10["animator"] = Property::Map() + .Add("alphaFunction", Vector4(.23,.4,.8,1.2)) + .Add("timePeriod", Property::Map() + .Add("delay", 0.0f) + .Add("duration", 1.0f)); + + Property::Map map11; + map11["target"] = "Actor2"; + map11["property"] = "scale"; + map11["initialValue"] = Vector3(0,0,0); + map11["targetValue"] = Vector3(1,1,1); + map11["animator"] = Property::Map() + .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f)) + .Add("timePeriod", Property::Map() + .Add("delay", 0.0f) + .Add("duration", 1.0f)); + + Property::Map map12; + map12["target"] = "Actor1"; + map12["property"] = "orientation"; + map12["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); + array.PushBack(map11); + array.PushBack(map12); + + 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/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 7b3f2d6..dcb2901 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -2683,6 +2683,12 @@ void Controller::Impl::ClampHorizontalScroll( const Vector2& layoutSize ) void Controller::Impl::ClampVerticalScroll( const Vector2& layoutSize ) { + if( LayoutEngine::SINGLE_LINE_BOX == mLayoutEngine.GetLayout() ) + { + // Nothing to do if the text is single line. + return; + } + // Clamp between -space & 0. if( layoutSize.height > mVisualModel->mControlSize.height ) { diff --git a/dali-toolkit/internal/visuals/border/border-visual.cpp b/dali-toolkit/internal/visuals/border/border-visual.cpp index 0c27103..764d178 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.cpp +++ b/dali-toolkit/internal/visuals/border/border-visual.cpp @@ -102,6 +102,11 @@ const char* FRAGMENT_SHADER_ANTI_ALIASING = DALI_COMPOSE_SHADER( ); } +BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache ) +{ + return new BorderVisual( factoryCache ); +} + BorderVisual::BorderVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mBorderColor( Color::TRANSPARENT ), @@ -116,7 +121,7 @@ BorderVisual::~BorderVisual() { } -void BorderVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void BorderVisual::DoSetProperties( const Property::Map& propertyMap ) { Property::Value* color = propertyMap.Find( Toolkit::BorderVisual::Property::COLOR, COLOR_NAME ); if( !( color && color->Get(mBorderColor) ) ) diff --git a/dali-toolkit/internal/visuals/border/border-visual.h b/dali-toolkit/internal/visuals/border/border-visual.h index c1e30d8..4f999b4 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.h +++ b/dali-toolkit/internal/visuals/border/border-visual.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -33,6 +34,9 @@ namespace Toolkit namespace Internal { +class BorderVisual; +typedef IntrusivePtr< BorderVisual > BorderVisualPtr; + /** * The visual which renders a solid color to the control's quad border fixed to a specified size. * @@ -44,12 +48,21 @@ namespace Internal * | borderSize | FLOAT | * | antiAliasing | BOOLEAN | */ - class BorderVisual : public Visual::Base { public: /** + * @brief Create a new border visual. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. + */ + static BorderVisualPtr New( VisualFactoryCache& factoryCache ); + +protected: + + /** * @brief Constructor. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object @@ -61,12 +74,10 @@ public: */ virtual ~BorderVisual(); -protected: - /** - * @copydoc Visual::Base::DoInitialize + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index a1ef6d2..cbe0036 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -65,6 +65,11 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( ); } +ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache ) +{ + return new ColorVisual( factoryCache ); +} + ColorVisual::ColorVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mMixColorIndex( Property::INVALID_INDEX ) @@ -75,7 +80,7 @@ ColorVisual::~ColorVisual() { } -void ColorVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void ColorVisual::DoSetProperties( const Property::Map& propertyMap ) { Property::Value* color = propertyMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR, COLOR_NAME ); if( !( color && color->Get(mMixColor) ) ) diff --git a/dali-toolkit/internal/visuals/color/color-visual.h b/dali-toolkit/internal/visuals/color/color-visual.h index 88fb152..cf2b057 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.h +++ b/dali-toolkit/internal/visuals/color/color-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_COLOR_VISUAL_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include @@ -30,6 +33,9 @@ namespace Toolkit namespace Internal { +class ColorVisual; +typedef IntrusivePtr< ColorVisual > ColorVisualPtr; + /** * The visual which renders a solid color to the control's quad * @@ -44,16 +50,12 @@ class ColorVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new color visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - ColorVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - virtual ~ColorVisual(); + static ColorVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -80,9 +82,21 @@ public: // from Visual protected: /** - * @copydoc Visual::Base::DoInitialize + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + ColorVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~ColorVisual(); + + /** + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index f30ff03..ee2b150 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -185,6 +185,10 @@ Dali::WrapMode::Type GetWrapMode( Toolkit::GradientVisual::SpreadMethod::Type sp } // unnamed namespace +GradientVisualPtr GradientVisual::New( VisualFactoryCache& factoryCache ) +{ + return new GradientVisual( factoryCache ); +} GradientVisual::GradientVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), @@ -197,7 +201,7 @@ GradientVisual::~GradientVisual() { } -void GradientVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void GradientVisual::DoSetProperties( const Property::Map& propertyMap ) { Toolkit::GradientVisual::Units::Type gradientUnits = Toolkit::GradientVisual::Units::OBJECT_BOUNDING_BOX; diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.h b/dali-toolkit/internal/visuals/gradient/gradient-visual.h index 1726c51..f7f47ee 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.h +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include @@ -33,6 +36,8 @@ namespace Internal { class Gradient; +class GradientVisual; +typedef IntrusivePtr< GradientVisual > GradientVisualPtr; /** * The visual which renders smooth transition of colors to the control's quad. @@ -80,16 +85,12 @@ public: }; /** - * @brief Constructor. + * @brief Create a new gradient visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - GradientVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~GradientVisual(); + static GradientVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -114,10 +115,23 @@ public: // from Visual virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index ); protected: + + /** + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + GradientVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~GradientVisual(); + /** - * @copydoc Visual::Base::DoInitialize + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/image/batch-image-visual.cpp b/dali-toolkit/internal/visuals/image/batch-image-visual.cpp index 46244aa..eecef34 100644 --- a/dali-toolkit/internal/visuals/image/batch-image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/batch-image-visual.cpp @@ -85,11 +85,16 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( }\n ); -} //unnamed namespace +} // unnamed namespace + +BatchImageVisualPtr BatchImageVisual::New( VisualFactoryCache& factoryCache ) +{ + return new BatchImageVisual( factoryCache ); +} BatchImageVisual::BatchImageVisual( VisualFactoryCache& factoryCache ) - : Visual::Base( factoryCache ), - mDesiredSize() +: Visual::Base( factoryCache ), + mDesiredSize() { } @@ -97,7 +102,7 @@ BatchImageVisual::~BatchImageVisual() { } -void BatchImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void BatchImageVisual::DoSetProperties( const Property::Map& propertyMap ) { std::string oldImageUrl = mImageUrl; Property::Value* imageURLValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::URL, Dali::Toolkit::Internal::IMAGE_URL_NAME ); @@ -122,25 +127,6 @@ void BatchImageVisual::DoInitialize( Actor& actor, const Property::Map& property mDesiredSize = ImageDimensions( desiredWidth, desiredHeight ); } - - // Remove old renderer if exit. - if( mImpl->mRenderer ) - { - if( actor ) // Remove old renderer from actor. - { - actor.RemoveRenderer( mImpl->mRenderer ); - } - if( !oldImageUrl.empty() ) // Clean old renderer from cache. - { - CleanCache( oldImageUrl ); - } - } - - // If actor is on stage, create new renderer and apply to actor. - if( actor && actor.OnStage() ) - { - SetOnStage( actor ); - } } void BatchImageVisual::SetSize( const Vector2& size ) diff --git a/dali-toolkit/internal/visuals/image/batch-image-visual.h b/dali-toolkit/internal/visuals/image/batch-image-visual.h index e5536e9..be84aab 100644 --- a/dali-toolkit/internal/visuals/image/batch-image-visual.h +++ b/dali-toolkit/internal/visuals/image/batch-image-visual.h @@ -18,13 +18,13 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL HEADER #include #include -// EXTERNAL INCLUDES -#include - namespace Dali { namespace Toolkit @@ -32,21 +32,20 @@ namespace Toolkit namespace Internal { +class BatchImageVisual; +typedef IntrusivePtr< BatchImageVisual > BatchImageVisualPtr; + class BatchImageVisual: public Visual::Base, public ConnectionTracker { public: /** - * @brief Constructor. + * @brief Create a new batch-image visual. * - * @param[in] factoryCache The VisualFactoryCache object - */ - BatchImageVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - ~BatchImageVisual(); + static BatchImageVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -78,9 +77,21 @@ public: // from Visual protected: /** - * @copydoc Visua::Base::DoInitialize + * @brief Constructor. + * + * @param[in] factoryCache The VisualFactoryCache object + */ + BatchImageVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + ~BatchImageVisual(); + + /** + * @copydoc Visua::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index d9cb845..21bbc63 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include "image-visual.h" +#include // EXTERNAL HEADER #include // for strncasecmp @@ -186,7 +186,26 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS return geometry; } -} //unnamed namespace +} // unnamed namespace + +ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache ) +{ + return new ImageVisual( factoryCache ); +} + +ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size, + FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode ) +{ + return new ImageVisual( factoryCache, imageUrl, size, fittingMode, samplingMode ); +} + +ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, const Image& image ) +{ + return new ImageVisual( factoryCache, image ); +} ImageVisual::ImageVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), @@ -199,9 +218,7 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache ) mFittingMode( FittingMode::DEFAULT ), mSamplingMode( SamplingMode::DEFAULT ), mWrapModeU( WrapMode::DEFAULT ), - mWrapModeV( WrapMode::DEFAULT ), - mNativeFragmentShaderCode(), - mNativeImageFlag( false ) + mWrapModeV( WrapMode::DEFAULT ) { } @@ -220,9 +237,7 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, mFittingMode( fittingMode ), mSamplingMode( samplingMode ), mWrapModeU( WrapMode::DEFAULT ), - mWrapModeV( WrapMode::DEFAULT ), - mNativeFragmentShaderCode(), - mNativeImageFlag( false ) + mWrapModeV( WrapMode::DEFAULT ) { } @@ -237,30 +252,16 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const Image& image ) mFittingMode( FittingMode::DEFAULT ), mSamplingMode( SamplingMode::DEFAULT ), mWrapModeU( WrapMode::DEFAULT ), - mWrapModeV( WrapMode::DEFAULT ), - mNativeFragmentShaderCode(), - mNativeImageFlag( false ) + mWrapModeV( WrapMode::DEFAULT ) { - NativeImage newNativeImage = NativeImage::DownCast( image ); - if( newNativeImage ) - { - SetNativeFragmentShaderCode( newNativeImage ); - mNativeImageFlag = true; - } - else - { - mNativeImageFlag = false; - } } ImageVisual::~ImageVisual() { } -void ImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void ImageVisual::DoSetProperties( const Property::Map& propertyMap ) { - std::string oldImageUrl = mImageUrl; - Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME ); if( imageURLValue ) { @@ -273,13 +274,17 @@ void ImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) Property::Value* fittingValue = propertyMap.Find( Toolkit::ImageVisual::Property::FITTING_MODE, IMAGE_FITTING_MODE ); if( fittingValue ) { - Scripting::GetEnumerationProperty( *fittingValue, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, mFittingMode ); + int value; + Scripting::GetEnumerationProperty( *fittingValue, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, value ); + mFittingMode = Dali::FittingMode::Type( value ); } Property::Value* samplingValue = propertyMap.Find( Toolkit::ImageVisual::Property::SAMPLING_MODE, IMAGE_SAMPLING_MODE ); if( samplingValue ) { - Scripting::GetEnumerationProperty( *samplingValue, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, mSamplingMode ); + int value; + Scripting::GetEnumerationProperty( *samplingValue, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, value ); + mSamplingMode = Dali::SamplingMode::Type( value ); } int desiredWidth = 0; @@ -305,13 +310,17 @@ void ImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) Property::Value* wrapModeValueU = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_U, IMAGE_WRAP_MODE_U ); if( wrapModeValueU ) { - Scripting::GetEnumerationProperty( *wrapModeValueU, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, mWrapModeU ); + int value; + Scripting::GetEnumerationProperty( *wrapModeValueU, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value ); + mWrapModeU = Dali::WrapMode::Type( value ); } Property::Value* wrapModeValueV = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_V, IMAGE_WRAP_MODE_V ); if( wrapModeValueV ) { - Scripting::GetEnumerationProperty( *wrapModeValueV, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, mWrapModeV ); + int value; + Scripting::GetEnumerationProperty( *wrapModeValueV, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value ); + mWrapModeV = Dali::WrapMode::Type( value ); } mDesiredSize = ImageDimensions( desiredWidth, desiredHeight ); @@ -325,32 +334,18 @@ void ImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) if( sync ) { mImpl->mFlags |= Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; + // if sync loading is required, the loading should start immediately when new image url is set or the actor is off stage + // ( for on-stage actor with image url unchanged, resource loading is already finished) + if( imageURLValue ) + { + LoadResourceSynchronously(); + } } else { mImpl->mFlags &= ~Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; } } - - // if sync loading is required, the loading should start immediately when new image url is set or the actor is off stage - // ( for on-stage actor with image url unchanged, resource loading is already finished) - if( imageURLValue && IsSynchronousResourceLoading() ) - { - LoadResourceSynchronously(); - } - - NativeImage nativeImage = NativeImage::DownCast( mImage ); - - if( nativeImage ) - { - SetNativeFragmentShaderCode( nativeImage ); - } - - // if actor is on stage, create new renderer and apply to actor - if( actor && actor.OnStage() ) - { - SetOnStage( actor ); - } } void ImageVisual::GetNaturalSize( Vector2& naturalSize ) const @@ -378,18 +373,11 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize ) const naturalSize = Vector2::ZERO; } -Renderer ImageVisual::CreateRenderer() const +void ImageVisual::CreateRenderer( TextureSet& textures ) { Geometry geometry; Shader shader; - // If mImage is nativeImage with custom sampler or prefix, mNativeFragmentShaderCode will be applied. - // Renderer can't be shared between NativeImage and other image types. - if( !mNativeFragmentShaderCode.empty() ) - { - return CreateNativeImageRenderer(); - } - if( !mImpl->mCustomShader ) { geometry = CreateGeometry( mFactoryCache, ImageDimensions( 1, 1 ) ); @@ -403,7 +391,7 @@ Renderer ImageVisual::CreateRenderer() const geometry = CreateGeometry( mFactoryCache, mImpl->mCustomShader->mGridSize ); if( mImpl->mCustomShader->mVertexShader.empty() && mImpl->mCustomShader->mFragmentShader.empty() ) { - shader = GetImageShader(mFactoryCache, false, true); + shader = GetImageShader( mFactoryCache, false, true ); } else { @@ -417,28 +405,49 @@ Renderer ImageVisual::CreateRenderer() const } } - Renderer renderer = Renderer::New( geometry, shader ); - - return renderer; + mImpl->mRenderer = Renderer::New( geometry, shader ); + DALI_ASSERT_DEBUG( textures ); + mImpl->mRenderer.SetTextures( textures ); } -Renderer ImageVisual::CreateNativeImageRenderer() const +void ImageVisual::CreateNativeImageRenderer( NativeImage& nativeImage ) { Geometry geometry; Shader shader; + std::string fragmentShader; + const char* fragmentPreFix = nativeImage.GetCustomFragmentPreFix(); + const char* customSamplerTypename = nativeImage.GetCustomSamplerTypename(); + if( fragmentPreFix ) + { + fragmentShader = fragmentPreFix; + fragmentShader += "\n"; + } + if( mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty() ) + { + fragmentShader += mImpl->mCustomShader->mFragmentShader; + } + else + { + fragmentShader += FRAGMENT_SHADER_NO_ATLAS; + } + if( customSamplerTypename ) + { + fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen( DEFAULT_SAMPLER_TYPENAME ), customSamplerTypename ); + } + if( !mImpl->mCustomShader ) { geometry = CreateGeometry( mFactoryCache, ImageDimensions( 1, 1 ) ); - shader = Shader::New( VERTEX_SHADER, mNativeFragmentShaderCode ); + shader = Shader::New( VERTEX_SHADER, fragmentShader ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); } else { geometry = CreateGeometry( mFactoryCache, mImpl->mCustomShader->mGridSize ); shader = Shader::New( mImpl->mCustomShader->mVertexShader.empty() ? VERTEX_SHADER : mImpl->mCustomShader->mVertexShader, - mNativeFragmentShaderCode, + fragmentShader, mImpl->mCustomShader->mHints ); if( mImpl->mCustomShader->mVertexShader.empty() ) { @@ -446,10 +455,7 @@ Renderer ImageVisual::CreateNativeImageRenderer() const } } - TextureSet textureSet = TextureSet::New(); - Renderer renderer = Renderer::New( geometry, shader ); - renderer.SetTextures( textureSet ); - return renderer; + mImpl->mRenderer = Renderer::New( geometry, shader ); } @@ -468,28 +474,7 @@ void ImageVisual::LoadResourceSynchronously() } } -Image ImageVisual::LoadImage( const std::string& url, bool synchronousLoading ) -{ - if( synchronousLoading ) - { - if( !mPixels ) - { - // use broken image - return VisualFactoryCache::GetBrokenVisualImage(); - } - Atlas image = Atlas::New( mPixels.GetWidth(), mPixels.GetHeight(), mPixels.GetPixelFormat() ); - image.Upload( mPixels, 0, 0 ); - return image; - } - else - { - ResourceImage resourceImage = Dali::ResourceImage::New( url, mDesiredSize, mFittingMode, mSamplingMode ); - resourceImage.LoadingFinishedSignal().Connect( this, &ImageVisual::OnImageLoaded ); - return resourceImage; - } -} - -TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading ) +TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading, bool attemptAtlasing ) { TextureSet textureSet; textureRect = FULL_TEXTURE_RECT; @@ -503,23 +488,30 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::strin } else { - textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, mPixels ); - mImpl->mFlags |= Impl::IS_ATLASING_APPLIED; - if( !textureSet ) // big image, no atlasing + if( attemptAtlasing ) + { + textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, mPixels ); + mImpl->mFlags |= Impl::IS_ATLASING_APPLIED; + } + if( !textureSet ) // big image, no atlasing or atlasing failed { mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED; - Atlas image = Atlas::New( mPixels.GetWidth(), mPixels.GetHeight(), mPixels.GetPixelFormat() ); - image.Upload( mPixels, 0, 0 ); + Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, mPixels.GetPixelFormat(), + mPixels.GetWidth(), mPixels.GetHeight() ); + texture.Upload( mPixels ); textureSet = TextureSet::New(); - TextureSetImage( textureSet, 0u, image ); + textureSet.SetTexture( 0u, texture ); } } } else { - textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, url, mDesiredSize, mFittingMode, true, this ); - mImpl->mFlags |= Impl::IS_ATLASING_APPLIED; - if( !textureSet ) // big image, no atlasing + if( attemptAtlasing ) + { + textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, url, mDesiredSize, mFittingMode, true, this ); + mImpl->mFlags |= Impl::IS_ATLASING_APPLIED; + } + if( !textureSet ) // big image, no atlasing or atlasing failed { mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED; ResourceImage resourceImage = Dali::ResourceImage::New( url, mDesiredSize, mFittingMode, mSamplingMode ); @@ -535,7 +527,6 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::strin sampler.SetWrapMode( mWrapModeU, mWrapModeV ); textureSet.SetSampler( 0u, sampler ); } - return textureSet; } @@ -567,11 +558,10 @@ void ImageVisual::InitializeRenderer( const std::string& imageUrl ) if( !mImpl->mRenderer ) // new renderer is needed { Vector4 atlasRect; - TextureSet textureSet = CreateTextureSet(atlasRect, imageUrl, IsSynchronousResourceLoading() ); - Geometry geometry = CreateGeometry( mFactoryCache, ImageDimensions( 1, 1 ) ); - Shader shader( GetImageShader(mFactoryCache, mImpl->mFlags & Impl::IS_ATLASING_APPLIED, defaultWrapMode) ); - mImpl->mRenderer = Renderer::New( geometry, shader ); - mImpl->mRenderer.SetTextures( textureSet ); + // texture set has to be created first as we need to know if atlasing succeeded or not + // when selecting the shader + TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), true ); + CreateRenderer( textures ); if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) // the texture is packed inside atlas { @@ -595,9 +585,9 @@ void ImageVisual::InitializeRenderer( const std::string& imageUrl ) { // for custom shader or remote image, renderer is not cached and atlas is not applied mImpl->mFlags &= ~Impl::IS_FROM_CACHE; - mImpl->mRenderer = CreateRenderer(); - Image image = LoadImage( imageUrl, IsSynchronousResourceLoading() ); - ApplyImageToSampler( image ); + Vector4 atlasRect; // ignored in this case + TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), false ); + CreateRenderer( textures ); } } @@ -605,7 +595,21 @@ void ImageVisual::InitializeRenderer( const Image& image ) { mImpl->mFlags &= ~Impl::IS_FROM_CACHE; - mImpl->mRenderer = CreateRenderer(); + // don't reuse CreateTextureSet + TextureSet textures = TextureSet::New(); + // Renderer can't be shared if mImage is NativeImage + NativeImage nativeImage = NativeImage::DownCast( image ); + if( nativeImage ) + { + CreateNativeImageRenderer( nativeImage ); + DALI_ASSERT_DEBUG( textures ); + mImpl->mRenderer.SetTextures( textures ); + } + else + { + // reuse existing code for regular images + CreateRenderer( textures ); + } if( image ) { @@ -753,11 +757,8 @@ void ImageVisual::ApplyImageToSampler( const Image& image ) if( image ) { TextureSet textureSet = mImpl->mRenderer.GetTextures(); - if( !textureSet ) - { - textureSet = TextureSet::New(); - mImpl->mRenderer.SetTextures( textureSet ); - } + DALI_ASSERT_DEBUG( textureSet ); // texture set should always exist by this time + TextureSetImage( textureSet, 0u, image ); Sampler sampler = Sampler::New(); sampler.SetWrapMode( mWrapModeU, mWrapModeV ); @@ -781,8 +782,6 @@ void ImageVisual::CleanCache(const std::string& url) { if( IsFromCache() ) { - TextureSet textureSet = mImpl->mRenderer.GetTextures(); - Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f ); Property::Index index = mImpl->mRenderer.GetPropertyIndex( ATLAS_RECT_UNIFORM_NAME ); if( index != Property::INVALID_INDEX ) @@ -791,6 +790,7 @@ void ImageVisual::CleanCache(const std::string& url) atlasRectValue.Get( atlasRect ); } + TextureSet textureSet = mImpl->mRenderer.GetTextures(); mImpl->mRenderer.Reset(); if( mFactoryCache.CleanRendererCache( url ) && index != Property::INVALID_INDEX ) { @@ -799,32 +799,6 @@ void ImageVisual::CleanCache(const std::string& url) } } -void ImageVisual::SetNativeFragmentShaderCode( Dali::NativeImage& nativeImage ) -{ - const char* fragmentPreFix = nativeImage.GetCustomFragmentPreFix(); - const char* customSamplerTypename = nativeImage.GetCustomSamplerTypename(); - - if( fragmentPreFix ) - { - mNativeFragmentShaderCode = fragmentPreFix; - mNativeFragmentShaderCode += "\n"; - } - - if( mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty() ) - { - mNativeFragmentShaderCode += mImpl->mCustomShader->mFragmentShader; - } - else - { - mNativeFragmentShaderCode += FRAGMENT_SHADER_NO_ATLAS; - } - - if( customSamplerTypename ) - { - mNativeFragmentShaderCode.replace( mNativeFragmentShaderCode.find( DEFAULT_SAMPLER_TYPENAME ), strlen( DEFAULT_SAMPLER_TYPENAME ), customSamplerTypename ); - } -} - } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index 56b1ae1..c2eca0e 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -18,16 +18,17 @@ * */ -// INTERNAL INCLUDES -#include -#include - // EXTERNAL INCLUDES +#include #include #include #include #include +// INTERNAL INCLUDES +#include +#include + namespace Dali { @@ -79,14 +80,15 @@ class ImageVisual: public Visual::Base, public ConnectionTracker, public AtlasUp public: /** - * @brief Constructor. + * @brief Create a new image visual. * - * @param[in] factoryCache The VisualFactoryCache object + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - ImageVisual( VisualFactoryCache& factoryCache ); + static ImageVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief Constructor with a URL. + * @brief Create a new image visual with a URL. * * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage * @@ -96,24 +98,19 @@ public: * @param[in] fittingMode The FittingMode of the resource to load * @param[in] samplingMode The SamplingMode of the resource to load */ - ImageVisual( VisualFactoryCache& factoryCache, - const std::string& imageUrl, - ImageDimensions size=ImageDimensions(), - FittingMode::Type fittingMode = FittingMode::DEFAULT, - Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ); + static ImageVisualPtr New( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size = ImageDimensions(), + FittingMode::Type fittingMode = FittingMode::DEFAULT, + Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ); /** - * @brief Constructor with an Image type. + * @brief Create a new image visual with an Image type. * * @param[in] factoryCache The VisualFactoryCache object * @param[in] image The image to use */ - ImageVisual( VisualFactoryCache& factoryCache, const Image& image ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~ImageVisual(); + static ImageVisualPtr New( VisualFactoryCache& factoryCache, const Image& image ); public: // from Visual @@ -138,10 +135,48 @@ public: // from Visual virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index ); protected: + + /** + * @brief Constructor. + * + * @param[in] factoryCache The VisualFactoryCache object + */ + ImageVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief Constructor with a URL. + * + * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage + * + * @param[in] factoryCache The VisualFactoryCache object + * @param[in] imageUrl The URL of the image resource to use + * @param[in] size The width and height to fit the loaded image to. + * @param[in] fittingMode The FittingMode of the resource to load + * @param[in] samplingMode The SamplingMode of the resource to load + */ + ImageVisual( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size, + FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode ); + + /** + * @brief Constructor with an Image type. + * + * @param[in] factoryCache The VisualFactoryCache object + * @param[in] image The image to use + */ + ImageVisual( VisualFactoryCache& factoryCache, const Image& image ); + /** - * @copydoc Visual::Base::DoInitialize + * @brief A reference counted object may only be deleted by calling Unreference(). */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual ~ImageVisual(); + + /** + * @copydoc Visual::Base::DoSetProperties + */ + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage @@ -196,17 +231,15 @@ private: /** * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it - * - * @return Returns the created Dali::Renderer + * @param[in] textures to use */ - Renderer CreateRenderer() const; + void CreateRenderer( TextureSet& textures ); /** * @brief Creates the Dali::Renderer for NativeImage with custom sampler type and prefix, initializing it - * - * @return Returns the created Dali::Renderer + * @param NativeImageRenderer */ - Renderer CreateNativeImageRenderer() const; + void CreateNativeImageRenderer( NativeImage& nativeImage ); /** * @brief Query whether resources requires to be loaded synchronously. @@ -220,19 +253,14 @@ private: void LoadResourceSynchronously(); /** - * Load the image. + * Creates the texture set and adds the texture to it + * @param[out] textureRect The texture area of the texture in the atlas. * @param[in] url The URL of the image resource to use. * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously. + * @param[in] attemptAtlasing If true will attempt atlasing, otherwise create unique texture + * @return the texture set to use */ - Image LoadImage( const std::string& url, bool synchronousLoading ); - - /** - * Load the image and create a texture set to hold the texture, with automatic atlasing applied. - * @param [out] textureRect The texture area of the resource image in the atlas. - * @param[in] url The URL of the image resource to use. - * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously. - */ - TextureSet CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading ); + TextureSet CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading, bool attemptAtlasing ); /** * Callback function of image resource loading succeed @@ -251,26 +279,20 @@ private: */ void CleanCache(const std::string& url); - /** - * Set shader code for nativeimage if it exists - */ - void SetNativeFragmentShaderCode( Dali::NativeImage& nativeImage ); - private: + Image mImage; PixelData mPixels; Vector4 mPixelArea; WeakHandle mPlacementActor; - std::string mImageUrl; + Dali::ImageDimensions mDesiredSize; - Dali::FittingMode::Type mFittingMode; - Dali::SamplingMode::Type mSamplingMode; - Dali::WrapMode::Type mWrapModeU; - Dali::WrapMode::Type mWrapModeV; + Dali::FittingMode::Type mFittingMode:3; + Dali::SamplingMode::Type mSamplingMode:4; + Dali::WrapMode::Type mWrapModeU:3; + Dali::WrapMode::Type mWrapModeV:3; - std::string mNativeFragmentShaderCode; - bool mNativeImageFlag; }; } // namespace Internal diff --git a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp index 5f8d4e0..3e94f9e 100644 --- a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp +++ b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp @@ -288,7 +288,12 @@ const char* NORMAL_MAP_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( }\n ); -} // namespace +} // unnamed namespace + +MeshVisualPtr MeshVisual::New( VisualFactoryCache& factoryCache ) +{ + return new MeshVisual( factoryCache ); +} MeshVisual::MeshVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), @@ -303,7 +308,7 @@ MeshVisual::~MeshVisual() { } -void MeshVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void MeshVisual::DoSetProperties( const Property::Map& propertyMap ) { Property::Value* objectUrl = propertyMap.Find( Toolkit::MeshVisual::Property::OBJECT_URL, OBJECT_URL_NAME ); if( !objectUrl || !objectUrl->Get( mObjectUrl ) ) diff --git a/dali-toolkit/internal/visuals/mesh/mesh-visual.h b/dali-toolkit/internal/visuals/mesh/mesh-visual.h index a05f848..4c0441a 100644 --- a/dali-toolkit/internal/visuals/mesh/mesh-visual.h +++ b/dali-toolkit/internal/visuals/mesh/mesh-visual.h @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -36,6 +37,9 @@ namespace Toolkit namespace Internal { +class MeshVisual; +typedef IntrusivePtr< MeshVisual > MeshVisualPtr; + /** * The visual which renders a 3D object to the control's quad * @@ -56,16 +60,12 @@ class MeshVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new mesh visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - MeshVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - virtual ~MeshVisual(); + static MeshVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -92,9 +92,21 @@ public: // from Visual protected: /** - * @copydoc Visual::Base::DoInitialize + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + MeshVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~MeshVisual(); + + /** + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 1a3f640..da73b33 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -200,35 +200,35 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co /////////////////NPatchVisual//////////////// -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mImage(), - mCroppedImage(), - mImageUrl(), - mStretchPixelsX(), - mStretchPixelsY(), - mImageSize(), - mBorderOnly( false ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache ) { + return new NPatchVisual( factoryCache ); } -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly ) -: Visual::Base( factoryCache ), - mImage(), - mCroppedImage(), - mImageUrl( imageUrl ), - mStretchPixelsX(), - mStretchPixelsY(), - mImageSize(), - mBorderOnly( borderOnly ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly ) { - NinePatchImage nPatch = NinePatchImage::New( mImageUrl ); - InitializeFromImage( nPatch ); + NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache, borderOnly ); + nPatchVisual->mImageUrl = imageUrl; + + NinePatchImage image = NinePatchImage::New( imageUrl ); + nPatchVisual->InitializeFromImage( image ); + + return nPatchVisual; } -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly ) +{ + NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache, borderOnly ); + nPatchVisual->mImage = image; + + nPatchVisual->InitializeFromImage( image ); + + return nPatchVisual; +} + +NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly ) : Visual::Base( factoryCache ), - mImage( image ), + mImage(), mCroppedImage(), mImageUrl(), mStretchPixelsX(), @@ -236,14 +236,13 @@ NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage ima mImageSize(), mBorderOnly( borderOnly ) { - InitializeFromImage( image ); } NPatchVisual::~NPatchVisual() { } -void NPatchVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void NPatchVisual::DoSetProperties( const Property::Map& propertyMap ) { Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME ); if( imageURLValue ) diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index e178eb8..b3210b9 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -18,10 +18,8 @@ * */ -// INTERNAL INCLUDES -#include - // EXTERNAL INCLUDES +#include #include #include #include @@ -29,6 +27,9 @@ #include #include +// INTERNAL INCLUDES +#include + namespace Dali { @@ -38,6 +39,9 @@ namespace Toolkit namespace Internal { +class NPatchVisual; +typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr; + /** * The visual which renders an 9 patch image to the control's quad * @@ -54,14 +58,15 @@ class NPatchVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new n-patch visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - NPatchVisual( VisualFactoryCache& factoryCache ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief Constructor which creates an N-patch visual using an image URL. + * @brief Create an N-patch visual using an image URL. * * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage * @@ -69,21 +74,16 @@ public: * @param[in] imageUrl The URL to 9 patch image resource to use * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border */ - NPatchVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly = false ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly = false ); /** - * @brief Constructor which creates an N-patch viusal with a NinePatchImage resource. + * @brief Create an N-patch visual with a NinePatchImage resource. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object * @param[in] image The NinePatchImage to use * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border */ - NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly = false ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~NPatchVisual(); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly = false ); public: // from Visual @@ -110,9 +110,22 @@ public: // from Visual protected: /** - * @copydoc Visual::Base::DoInitialize + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border + */ + NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly = false ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~NPatchVisual(); + + /** + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp index 956714b..6938eef 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp @@ -160,7 +160,12 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( }\n ); -} // namespace +} // unnamed namespace + +PrimitiveVisualPtr PrimitiveVisual::New( VisualFactoryCache& factoryCache ) +{ + return new PrimitiveVisual( factoryCache ); +} PrimitiveVisual::PrimitiveVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), @@ -182,7 +187,7 @@ PrimitiveVisual::~PrimitiveVisual() { } -void PrimitiveVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void PrimitiveVisual::DoSetProperties( const Property::Map& propertyMap ) { //Find out which shape to renderer. Property::Value* primitiveTypeValue = propertyMap.Find( Toolkit::PrimitiveVisual::Property::SHAPE, PRIMITIVE_SHAPE ); diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.h b/dali-toolkit/internal/visuals/primitive/primitive-visual.h index 04f1d3d..c06d55c 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.h +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.h @@ -44,6 +44,8 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +// EXTERNAL INCLUDES +#include // INTERNAL INCLUDES #include @@ -58,6 +60,9 @@ namespace Toolkit namespace Internal { +class PrimitiveVisual; +typedef IntrusivePtr< PrimitiveVisual > PrimitiveVisualPtr; + /** * The visual which renders a simple 3D shape to the control's quad * @@ -97,16 +102,12 @@ class PrimitiveVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new primitive visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - PrimitiveVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - virtual ~PrimitiveVisual(); + static PrimitiveVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -138,9 +139,21 @@ public: // from Visual protected: /** - * @copydoc Visual::Base::DoInitialize + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + PrimitiveVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~PrimitiveVisual(); + + /** + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 46b6a62..efa3582 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -53,18 +53,19 @@ namespace Toolkit namespace Internal { -SvgVisual::SvgVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mAtlasRect( FULL_TEXTURE_RECT ), - mImageUrl(), - mParsedImage( NULL ), - mPlacementActor() +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache ) { - // the rasterized image is with pre-multiplied alpha format - mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; + return new SvgVisual( factoryCache ); +} + +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size ) +{ + SvgVisual* svgVisual = new SvgVisual( factoryCache ); + svgVisual->ParseFromUrl( imageUrl, size ); + return svgVisual; } -SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size ) +SvgVisual::SvgVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mAtlasRect( FULL_TEXTURE_RECT ), mImageUrl(), @@ -73,8 +74,6 @@ SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, const std::string& image { // the rasterized image is with pre-multiplied alpha format mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; - - ParseFromUrl( imageUrl, size ); } SvgVisual::~SvgVisual() @@ -85,7 +84,7 @@ SvgVisual::~SvgVisual() } } -void SvgVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void SvgVisual::DoSetProperties( const Property::Map& propertyMap ) { Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME ); if( imageURLValue ) diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.h b/dali-toolkit/internal/visuals/svg/svg-visual.h index 8fd9165..0456bb5 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.h +++ b/dali-toolkit/internal/visuals/svg/svg-visual.h @@ -18,7 +18,8 @@ * */ -//EXTERNAL INCLUDES +// EXTERNAL INCLUDES +#include #include // INTERNAL INCLUDES @@ -35,6 +36,9 @@ namespace Toolkit namespace Internal { +class SvgVisual; +typedef IntrusivePtr< SvgVisual > SvgVisualPtr; + /** * The visual which renders a svg image * @@ -50,27 +54,24 @@ class SvgVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new SVG visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - SvgVisual( VisualFactoryCache& factoryCache ); + static SvgVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief Constructor which creates the SVG Visual using the image URL. + * @brief Create the SVG Visual using the image URL. * * The visual will parse the SVG image once it is set. * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object * @param[in] imageUrl The URL to svg resource to use + * @param[in] size The required size for the SVG */ - SvgVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~SvgVisual(); + static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); public: // from Visual @@ -102,9 +103,21 @@ public: // from Visual protected: /** - * @copydoc Visual::Base::DoInitialize + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + SvgVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~SvgVisual(); + + /** + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index e9278f9..31dc8bb 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -154,18 +154,11 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS return geometry; } -} // namespace +} // unnamed namespace -TextVisual::TextVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mController( Text::Controller::New() ), - mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ), - mHasBeenStaged( false ) -{ -} - -TextVisual::~TextVisual() +TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache ) { + return new TextVisual( factoryCache ); } void TextVisual::SetTextControlInterface( Text::ControlInterface* controlInterface ) @@ -254,10 +247,20 @@ void TextVisual::DoCreatePropertyMap( Property::Map& map ) const map.Insert( Toolkit::TextVisual::Property::BATCHING_ENABLED, false ); // TODO } -void TextVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +TextVisual::TextVisual( VisualFactoryCache& factoryCache ) +: Visual::Base( factoryCache ), + mController( Text::Controller::New() ), + mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ), + mHasBeenStaged( false ) { - mSelf = actor; +} +TextVisual::~TextVisual() +{ +} + +void TextVisual::DoSetProperties( const Property::Map& propertyMap ) +{ for( Property::Map::SizeType index = 0u, count = propertyMap.Count(); index < count; ++index ) { const KeyValuePair& keyValue = propertyMap.GetKeyValue( index ); @@ -807,6 +810,13 @@ Dali::Property::Value TextVisual::DoGetProperty( Dali::Property::Index index ) void TextVisual::RenderText() { + Actor self = mSelf.GetHandle(); + if( !self ) + { + // Nothing to do if the handle is not initialized. + return; + } + Actor renderableActor; if( mRenderer ) @@ -823,7 +833,7 @@ void TextVisual::RenderText() const Vector2& scrollOffset = mController->GetScrollPosition(); renderableActor.SetPosition( scrollOffset.x, scrollOffset.y ); - mSelf.Add( renderableActor ); + self.Add( renderableActor ); } mRenderableActor = renderableActor; @@ -844,6 +854,13 @@ void TextVisual::StopTextAutoScrolling() void TextVisual::SetUpAutoScrolling() { + Actor self = mSelf.GetHandle(); + if( !self ) + { + // Nothing to do if the handle is not initialized. + return; + } + const Text::ScrollerData* const data = mController->GetAutoScrollData(); if( NULL != data ) @@ -857,8 +874,8 @@ void TextVisual::SetUpAutoScrolling() mTextScroller->StartScrolling( mRenderableActor, *data ); - mSelf.Add( mTextScroller->GetScrollingText() ); - mSelf.Add( mTextScroller->GetSourceCamera() ); + self.Add( mTextScroller->GetScrollingText() ); + self.Add( mTextScroller->GetSourceCamera() ); } } diff --git a/dali-toolkit/internal/visuals/text/text-visual.h b/dali-toolkit/internal/visuals/text/text-visual.h index 9151ec7..47289d1 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.h +++ b/dali-toolkit/internal/visuals/text/text-visual.h @@ -18,6 +18,10 @@ * */ +// EXTERNAL INCLUDES +#include +#include + // INTERNAL INCLUDES #include #include @@ -69,19 +73,16 @@ class TextVisual : public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new text visual. * - * @param[in] factoryCache The VisualFactoryCache object + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - TextVisual( VisualFactoryCache& factoryCache ); + static TextVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~TextVisual(); - - /** - * + * @brief Sets the text control interface which is needed to communicate with a control. + * @param[in] controlInterface Pointer to the control-interface. */ void SetTextControlInterface( Text::ControlInterface* controlInterface ); @@ -107,11 +108,26 @@ public: // from Visual::Base */ virtual void DoCreatePropertyMap( Property::Map& map ) const; -protected: // from Visual::Base +protected: + + /** + * @brief Constructor. + * + * @param[in] factoryCache The VisualFactoryCache object + */ + TextVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~TextVisual(); + + // from Visual::Base + /** - * @copydoc Visual::Base::DoInitialize() + * @copydoc Visual::Base::DoSetProperties() */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage() @@ -153,7 +169,7 @@ private: private: Text::ControllerPtr mController; ///< The text's controller. - Actor mSelf; + WeakHandle mSelf; Text::RendererPtr mRenderer; Text::TextScrollerPtr mTextScroller; 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..8ccb354 --- /dev/null +++ b/dali-toolkit/internal/visuals/transition-data-impl.cpp @@ -0,0 +1,385 @@ +/* + * 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 ) + { + if( value.GetType() == Property::ARRAY ) + { + bool valid = true; + Vector4 controlPoints; + Property::Array *array = value.GetArray(); + if( array->Count() >= 4 ) + { + for( size_t vecIdx = 0; vecIdx < 4; ++vecIdx ) + { + Property::Value& v = array->GetElementAt(vecIdx); + if( v.GetType() == Property::FLOAT ) + { + controlPoints[vecIdx] = v.Get(); + } + else + { + valid = false; + break; + } + } + } + else + { + valid = false; + } + + if( valid ) + { + Vector2 controlPoint1( controlPoints.x, controlPoints.y ); + Vector2 controlPoint2( controlPoints.z, controlPoints.w ); + animator->alphaFunction = AlphaFunction( controlPoint1, controlPoint2 ); + } + else + { + animator->animate = false; + } + } + else if( value.GetType() == Property::VECTOR4 ) + { + Vector4 controlPoints = value.Get(); + Vector2 controlPoint1( controlPoints.x, controlPoints.y ); + Vector2 controlPoint2( controlPoints.z, controlPoints.w ); + animator->alphaFunction = AlphaFunction( controlPoint1, controlPoint2 ); + } + else if( value.GetType() == Property::STRING ) + { + std::string alphaFunctionValue = value.Get< std::string >(); + + if( alphaFunctionValue == "LINEAR" ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::LINEAR); + } + else if( ! alphaFunctionValue.compare(0, 5, "EASE_" ) ) + { + if( alphaFunctionValue == "EASE_IN" ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_IN); + } + else if( alphaFunctionValue == "EASE_OUT" ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_OUT); + } + else if( ! alphaFunctionValue.compare( 5, 3, "IN_" ) ) + { + if( ! alphaFunctionValue.compare(8, -1, "SQUARE" )) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_IN_SQUARE); + } + else if( ! alphaFunctionValue.compare(8, -1, "OUT" )) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_IN_OUT); + } + else if( ! alphaFunctionValue.compare(8, -1, "OUT_SINE" )) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_IN_OUT_SINE); + } + else if( ! alphaFunctionValue.compare(8, -1, "SINE" )) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_IN_SINE); + } + } + else if( ! alphaFunctionValue.compare( 5, 4, "OUT_" ) ) + { + if( ! alphaFunctionValue.compare(9, -1, "SQUARE" ) ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_OUT_SQUARE); + } + else if( ! alphaFunctionValue.compare(9, -1, "SINE" ) ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_OUT_SINE); + } + else if( ! alphaFunctionValue.compare(9, -1, "BACK" ) ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::EASE_OUT_BACK); + } + } + } + else if( alphaFunctionValue == "REVERSE" ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::REVERSE); + } + else if( alphaFunctionValue == "BOUNCE" ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::BOUNCE); + } + else if( alphaFunctionValue == "SIN" ) + { + animator->alphaFunction = AlphaFunction(AlphaFunction::SIN); + } + } + else + { + animator->animate = false; + } + } + 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 ) + { + Property::Map animateMap; + + if( animator->alphaFunction.GetMode() == AlphaFunction::BUILTIN_FUNCTION ) + { + animateMap.Add(TOKEN_ALPHA_FUNCTION, GetEnumerationName( animator->alphaFunction.GetBuiltinFunction(), + ALPHA_FUNCTION_BUILTIN_TABLE, + ALPHA_FUNCTION_BUILTIN_TABLE_COUNT )); + } + else if( animator->alphaFunction.GetMode() == AlphaFunction::BEZIER ) + { + Vector4 controlPoints = animator->alphaFunction.GetBezierControlPoints(); + animateMap.Add( TOKEN_ALPHA_FUNCTION, controlPoints ); + } + animateMap.Add(TOKEN_TIME_PERIOD, Property::Map() + .Add( TOKEN_DELAY, animator->timePeriodDelay ) + .Add( TOKEN_DURATION, animator->timePeriodDuration )); + + map[TOKEN_ANIMATOR] = animateMap; + } + + 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..9ca8193 --- /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 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..d152a7f 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -55,11 +55,11 @@ void Visual::Base::SetCustomShader( const Property::Map& shaderMap ) } else { - mImpl->mCustomShader = new Impl::CustomShader( shaderMap ); + mImpl->mCustomShader = new Impl::CustomShader( shaderMap ); } } -void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap ) +void Visual::Base::SetProperties( const Property::Map& propertyMap ) { Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER ); if( customShaderValue ) @@ -71,7 +71,17 @@ void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap ) } } - DoInitialize( actor, propertyMap ); + DoSetProperties( 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 ) diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 3334842..432a3f2 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -19,6 +19,7 @@ */ // EXTERNAL INCLUDES +#include #include #include #include @@ -65,14 +66,20 @@ class Base : public BaseObject public: /** - * Initialisation of the visual, this API should only called by the VisualFactory: - * request the geometry and shader from the cache, if not available, create and save to the cache for sharing; - * record the property values. - * - * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor + * Setting the properties of the visual, this API should only called by the VisualFactory * @param[in] propertyMap The properties for the requested Visual object. */ - void Initialize( Actor& actor, const Property::Map& propertyMap ); + void SetProperties( 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 @@ -173,12 +180,11 @@ protected: virtual void DoCreatePropertyMap( Property::Map& map ) const = 0; /** - * @brief Called by Initialize() allowing sub classes to respond to the Initialize event + * @brief Called by SetProperties() allowing sub classes to set their properties * - * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor * @param[in] propertyMap The properties for the requested Visual object. */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {} + virtual void DoSetProperties( const Property::Map& propertyMap ) = 0; protected: @@ -246,6 +252,8 @@ protected: VisualFactoryCache& mFactoryCache; }; +typedef IntrusivePtr BasePtr; + } // namspace Visual } // namespace Internal diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 76d0ba7..67311b0 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -100,10 +100,10 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property // Return a new WireframeVisual if we have debug enabled if( mDebugEnabled ) { - return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) ); + return Toolkit::Visual::Base( WireframeVisual::New( *( mFactoryCache.Get() ) ).Get() ); } - Visual::Base* visualPtr = NULL; + Visual::BasePtr visualPtr; Property::Value* typeValue = propertyMap.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE ); Toolkit::Visual::Type visualType = Toolkit::Visual::IMAGE; // Default to IMAGE type. @@ -116,19 +116,19 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property { case Toolkit::Visual::BORDER: { - visualPtr = new BorderVisual( *( mFactoryCache.Get() ) ); + visualPtr = BorderVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::COLOR: { - visualPtr = new ColorVisual( *( mFactoryCache.Get() ) ); + visualPtr = ColorVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::GRADIENT: { - visualPtr = new GradientVisual( *( mFactoryCache.Get() ) ); + visualPtr = GradientVisual::New( *( mFactoryCache.Get() ) ); break; } @@ -142,11 +142,11 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property UrlType::Type type = ResolveUrlType( imageUrl ); if( UrlType::N_PATCH == type ) { - visualPtr = new NPatchVisual( *( mFactoryCache.Get() ) ); + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ) ); } else if( UrlType::SVG == type ) { - visualPtr = new SvgVisual( *( mFactoryCache.Get() ) ); + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ) ); } else // Regular image { @@ -159,12 +159,12 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property if( batchingEnabled ) { - visualPtr = new BatchImageVisual( *( mFactoryCache.Get() ) ); + visualPtr = BatchImageVisual::New( *( mFactoryCache.Get() ) ); break; } else { - visualPtr = new ImageVisual( *( mFactoryCache.Get() ) ); + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ) ); } } } @@ -174,41 +174,39 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property case Toolkit::Visual::MESH: { - visualPtr = new MeshVisual( *( mFactoryCache.Get() ) ); + visualPtr = MeshVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::PRIMITIVE: { - visualPtr = new PrimitiveVisual( *( mFactoryCache.Get() ) ); + visualPtr = PrimitiveVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::WIREFRAME: { - visualPtr = new WireframeVisual( *( mFactoryCache.Get() ) ); + visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::TEXT: { - visualPtr = new TextVisual( *( mFactoryCache.Get() ) ); + visualPtr = TextVisual::New( *( mFactoryCache.Get() ) ); break; } - } if( visualPtr ) { - Actor actor; - visualPtr->Initialize( actor, propertyMap ); + visualPtr->SetProperties( propertyMap ); } else { DALI_LOG_ERROR( "Renderer type unknown\n" ); } - return Toolkit::Visual::Base( visualPtr ); + return Toolkit::Visual::Base( visualPtr.Get() ); } Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image ) @@ -220,20 +218,22 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image ) if( mDebugEnabled ) { - return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) ); + return Toolkit::Visual::Base( WireframeVisual::New( *( mFactoryCache.Get() ) ).Get() ); } + Visual::BasePtr visualPtr; + NinePatchImage npatchImage = NinePatchImage::DownCast( image ); if( npatchImage ) { - NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ), npatchImage ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage ); } else { - ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), image ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image ); } + + return Toolkit::Visual::Base( visualPtr.Get() ); } Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, ImageDimensions size ) @@ -245,26 +245,27 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image if( mDebugEnabled ) { - return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) ); + return Toolkit::Visual::Base( WireframeVisual::New( *( mFactoryCache.Get() ) ).Get() ); } + Visual::BasePtr visualPtr; + // first resolve url type to know which visual to create UrlType::Type type = ResolveUrlType( url ); if( UrlType::N_PATCH == type ) { - NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ), url ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), url ); } else if( UrlType::SVG == type ) { - SvgVisual* visualPtr = new SvgVisual( *( mFactoryCache.Get() ), url, size ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url, size ); } else // Regular image { - ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), url, size ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), url, size ); } + + return Toolkit::Visual::Base( visualPtr.Get() ); } } // namespace Internal diff --git a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp index 551e14f..b65f67c 100644 --- a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp +++ b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp @@ -64,6 +64,10 @@ void main()\n } +WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache ) +{ + return new WireframeVisual( factoryCache ); +} WireframeVisual::WireframeVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ) @@ -71,7 +75,13 @@ WireframeVisual::WireframeVisual( VisualFactoryCache& factoryCache ) } WireframeVisual::~WireframeVisual() -{} +{ +} + +void WireframeVisual::DoSetProperties( const Property::Map& propertyMap ) +{ + // no properties supported at the moment +} void WireframeVisual::DoSetOnStage( Actor& actor ) { diff --git a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h index 805e2c7..3756e00 100644 --- a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h +++ b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include @@ -30,15 +33,27 @@ namespace Toolkit namespace Internal { +class WireframeVisual; +typedef IntrusivePtr< WireframeVisual > WireframeVisualPtr; + /** - * The visual which renders a wireframe outline to the control's quad. - * + * @brief Renders a wireframe outline to the control's quad. */ class WireframeVisual: public Visual::Base { public: /** + * @brief Create a new wireframe visual. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. + */ + static WireframeVisualPtr New( VisualFactoryCache& factoryCache ); + +protected: + + /** * @brief Constructor. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object @@ -50,7 +65,10 @@ public: */ virtual ~WireframeVisual(); -protected: + /** + * @copydoc Visual::Base::DoSetProperties() + */ + virtual void DoSetProperties( const Property::Map& propertyMap ); /** * @copydoc Visual::Base::DoSetOnStage 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/dali-toolkit-version.cpp b/dali-toolkit/public-api/dali-toolkit-version.cpp index c15604b..8c9ed00 100644 --- a/dali-toolkit/public-api/dali-toolkit-version.cpp +++ b/dali-toolkit/public-api/dali-toolkit-version.cpp @@ -31,7 +31,7 @@ namespace Toolkit const unsigned int TOOLKIT_MAJOR_VERSION = 1; const unsigned int TOOLKIT_MINOR_VERSION = 2; -const unsigned int TOOLKIT_MICRO_VERSION = 10; +const unsigned int TOOLKIT_MICRO_VERSION = 11; const char * const TOOLKIT_BUILD_DATE = __DATE__ " " __TIME__; #ifdef DEBUG_ENABLED 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 diff --git a/packaging/dali-addon.spec b/packaging/dali-addon.spec index 0da6d86..b5a63b2 100644 --- a/packaging/dali-addon.spec +++ b/packaging/dali-addon.spec @@ -1,6 +1,6 @@ Name: dali-addon Summary: DALi module for Node.JS -Version: 1.2.10 +Version: 1.2.11 Release: 1 Group: Development/Libraries License: Apache License, Version 2.0 diff --git a/packaging/dali-csharp-wrapper.spec b/packaging/dali-csharp-wrapper.spec index dca178a..788769d 100755 --- a/packaging/dali-csharp-wrapper.spec +++ b/packaging/dali-csharp-wrapper.spec @@ -1,6 +1,6 @@ Name: NDalic Summary: dali wrapper -Version: 1.0.0 +Version: 1.2.11 Release: 1 Group: uifw/graphic License: TO_BE_FILLED_IN diff --git a/packaging/dali-toolkit.spec b/packaging/dali-toolkit.spec index f4e8ae0..bae76d7 100644 --- a/packaging/dali-toolkit.spec +++ b/packaging/dali-toolkit.spec @@ -1,6 +1,6 @@ Name: dali-toolkit Summary: The OpenGLES Canvas Core Library Toolkit -Version: 1.2.10 +Version: 1.2.11 Release: 1 Group: System/Libraries License: Apache-2.0 and BSD-2-Clause and MIT diff --git a/plugins/dali-swig/SWIG/alphafunction.i b/plugins/dali-swig/SWIG/alphafunction.i new file mode 100644 index 0000000..26003be --- /dev/null +++ b/plugins/dali-swig/SWIG/alphafunction.i @@ -0,0 +1,25 @@ +/* + * 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. + * + */ + +%typemap(cscode) Dali::AlphaFunction %{ + public AlphaFunction(Dali.Constants.AlphaFunction.BuiltinFunction function) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_1((int)function), true){ + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } +%} + + + diff --git a/plugins/dali-swig/SWIG/dali-operator.i b/plugins/dali-swig/SWIG/dali-operator.i index f6bbe4d..894b34f 100644 --- a/plugins/dali-swig/SWIG/dali-operator.i +++ b/plugins/dali-swig/SWIG/dali-operator.i @@ -252,7 +252,13 @@ * This is because from C# we can't wrap the operator BooleanType() function */ %extend Dali::BaseHandle { - bool IsHandleEmpty() const { + bool HasBody() const { + + // C++ code. DALi uses Handle <-> Body design pattern. + // This function checks the Handle to see if it has a body attached ( possible to have empty handles). + // Handles in DALi can be converted into a boolean type + // to check if the handle has a valid body attached to it. + // Internally checking *$self will checks IntrusivePtr mObjectHandle in BaseHandle; if( *$self ) { return true; @@ -262,6 +268,21 @@ return false; } } + + // Check if two handles point to the same body / ref-object. + bool IsEqual( const BaseHandle& rhs ) const { + + // C++ code. Check if two handles reference the same implemtion + if( *$self == rhs) + { + return true; + } + else + { + return false; + } + } + }; /** @@ -274,21 +295,114 @@ */ %typemap(cscode) Dali::BaseHandle %{ - public static bool operator true(BaseHandle handle) - { - if( handle!= null ) - { - return handle.IsHandleEmpty(); - } - else - { - return false; - } - } - public static bool operator false(BaseHandle handle) - { - return handle.IsHandleEmpty(); - } -%} + // Returns the bool value true to indicate that an operand is true and returns false otherwise. + public static bool operator true(BaseHandle handle) + { + // if the C# object is null, return false + if( BaseHandle.ReferenceEquals( handle, null ) ) + { + return false; + } + // returns true if the handle has a body, false otherwise + return handle.HasBody(); + } + + // Returns the bool false to indicate that an operand is false and returns true otherwise. + public static bool operator false(BaseHandle handle) + { + // if the C# object is null, return true + if( BaseHandle.ReferenceEquals( handle, null ) ) + { + return true; + } + return !handle.HasBody(); + } + + // Explicit conversion from Handle to bool. + public static explicit operator bool(BaseHandle handle) + { + // if the C# object is null, return false + if( BaseHandle.ReferenceEquals( handle, null ) ) + { + return false; + } + // returns true if the handle has a body, false otherwise + return handle.HasBody(); + } + // Equality operator + public static bool operator == (BaseHandle x, BaseHandle y) + { + // if the C# objects are the same return true + if( BaseHandle.ReferenceEquals( x, y ) ) + { + return true; + } + if ( !BaseHandle.ReferenceEquals( x, null ) && !BaseHandle.ReferenceEquals( y, null ) ) + { + // drop into native code to see if both handles point to the same body + return x.IsEqual( y) ; + } + return false; + + } + + // Inequality operator. Returns Null if either operand is Null + public static bool operator !=(BaseHandle x, BaseHandle y) + { + return !(x==y); + } + + // Logical AND operator for && + // It's possible when doing a && this function (opBitwiseAnd) is never called due + // to short circuiting. E.g. + // If you perform x && y What actually is called is + // BaseHandle.op_False( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseAnd(x,y) ) + // + public static BaseHandle operator &(BaseHandle x, BaseHandle y) + { + if( x == y ) + { + return x; + } + return null; + } + + // Logical OR operator for || + // It's possible when doing a || this function (opBitwiseOr) is never called due + // to short circuiting. E.g. + // If you perform x || y What actually is called is + // BaseHandle.op_True( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseOr(x,y) ) + public static BaseHandle operator |(BaseHandle x, BaseHandle y) + { + if ( !BaseHandle.ReferenceEquals( x, null ) || !BaseHandle.ReferenceEquals( y, null ) ) + { + if( x.HasBody() ) + { + return x; + } + if( y.HasBody() ) + { + return y; + } + return null; + } + return null; + } + + // Logical ! operator + public static bool operator !(BaseHandle x) + { + // if the C# object is null, return true + if( BaseHandle.ReferenceEquals( x, null ) ) + { + return true; + } + if( x.HasBody() ) + { + return false; + } + return true; + } +%} \ No newline at end of file diff --git a/plugins/dali-swig/SWIG/dali.i b/plugins/dali-swig/SWIG/dali.i index e76ba22..a48c274 100755 --- a/plugins/dali-swig/SWIG/dali.i +++ b/plugins/dali-swig/SWIG/dali.i @@ -200,6 +200,7 @@ using namespace Dali::Toolkit; %include events/pangesture-event.i %include events/propertynotification-event.i %include events/longpressgesture-event.i +%include events/rectinteger.i %include events/resourceimage-event.i %include events/scrollable-event.i %include events/scrollbar-event.i @@ -213,6 +214,8 @@ using namespace Dali::Toolkit; %include events/timer-event.i %include events/videoview-event.i +%include alphafunction.i + %include dali-operator.i %include dali-core.i %include dali-adaptor.i diff --git a/plugins/dali-swig/SWIG/events/actor-event.i b/plugins/dali-swig/SWIG/events/actor-event.i index 4a5f51f..1deccbc 100644 --- a/plugins/dali-swig/SWIG/events/actor-event.i +++ b/plugins/dali-swig/SWIG/events/actor-event.i @@ -26,555 +26,6 @@ %define ACTOR_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName) %typemap(cscode) NameSpace::ClassName %{ - - /** - * @brief Event arguments that passed via Touch signal - * - */ - public class TouchEventArgs : EventArgs - { - private Actor _actor; - private TouchData _touchData; - - /** - * @brief Actor - is the actor that is being touched - * - */ - public Actor Actor - { - get - { - return _actor; - } - set - { - _actor = value; - } - } - - /** - * @brief TouchData - contains the information of touch points - * - */ - public TouchData TouchData - { - get - { - return _touchData; - } - set - { - _touchData = value; - } - } - } - - /** - * @brief Event arguments that passed via Hover signal - * - */ - public class HoverEventArgs : EventArgs - { - private Actor _actor; - private HoverEvent _hoverEvent; - - /** - * @brief Actor - is the actor that is being hovered - * - */ - public Actor Actor - { - get - { - return _actor; - } - set - { - _actor = value; - } - } - - /** - * @brief HoverEvent - contains touch points that represent the points - * that are currently being hovered or the points where a hover has stopped - * - */ - public HoverEvent HoverEvent - { - get - { - return _hoverEvent; - } - set - { - _hoverEvent = value; - } - } - } - - /** - * @brief Event arguments that passed via Wheel signal - * - */ - public class WheelEventArgs : EventArgs - { - private Actor _actor; - private WheelEvent _wheelEvent; - - /** - * @brief Actor - is the actor that is being wheeled - * - */ - public Actor Actor - { - get - { - return _actor; - } - set - { - _actor = value; - } - } - - /** - * @brief WheelEvent - store a wheel rolling type : MOUSE_WHEEL or CUSTOM_WHEEL - * - */ - public WheelEvent WheelEvent - { - get - { - return _wheelEvent; - } - set - { - _wheelEvent = value; - } - } - } - - /** - * @brief Event arguments that passed via OnStage signal - * - */ - public class OnStageEventArgs : EventArgs - { - private Actor _actor; - - /** - * @brief Actor - is the actor that is being connected to the stage - * - */ - public Actor Actor - { - get - { - return _actor; - } - set - { - _actor = value; - } - } - } - - /** - * @brief Event arguments that passed via OffStage signal - * - */ - public class OffStageEventArgs : EventArgs - { - private Actor _actor; - - /** - * @brief Actor - is the actor that is being disconnected from the stage - * - */ - public Actor Actor - { - get - { - return _actor; - } - set - { - _actor = value; - } - } - } - - /** - * @brief Event arguments that passed via OnRelayout signal - * - */ - public class OnRelayoutEventArgs : EventArgs - { - private Actor _actor; - - /** - * @brief Actor - is the actor that is being resized upon relayout - * - */ - public Actor Actor - { - get - { - return _actor; - } - set - { - _actor = value; - } - } - } - - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate bool TouchCallbackDelegate(IntPtr actor, IntPtr touchData); - private DaliEventHandlerWithReturnType _actorTouchDataEventHandler; - private TouchCallbackDelegate _actorTouchDataCallbackDelegate; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate bool HoverEventCallbackDelegate(IntPtr actor, IntPtr hoverEvent); - private DaliEventHandlerWithReturnType _actorHoverEventHandler; - private HoverEventCallbackDelegate _actorHoverEventCallbackDelegate; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate bool WheelEventCallbackDelegate(IntPtr actor, IntPtr wheelEvent); - private DaliEventHandlerWithReturnType _actorWheelEventHandler; - private WheelEventCallbackDelegate _actorWheelEventCallbackDelegate; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void OnStageEventCallbackDelegate(IntPtr actor); - private DaliEventHandler _actorOnStageEventHandler; - private OnStageEventCallbackDelegate _actorOnStageEventCallbackDelegate; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void OffStageEventCallbackDelegate(IntPtr actor); - private DaliEventHandler _actorOffStageEventHandler; - private OffStageEventCallbackDelegate _actorOffStageEventCallbackDelegate; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void OnRelayoutEventCallbackDelegate(IntPtr actor); - private DaliEventHandler _actorOnRelayoutEventHandler; - private OnRelayoutEventCallbackDelegate _actorOnRelayoutEventCallbackDelegate; - - /** - * @brief Event for Touched signal which can be used to subscribe/unsubscribe the event handler - * (in the type of TouchEventHandler-DaliEventHandlerWithReturnType) - * provided by the user. Touched signal is emitted when touch input is received. - */ - public event DaliEventHandlerWithReturnType Touched - { - add - { - lock(this) - { - // Restricted to only one listener - if (_actorTouchDataEventHandler == null) - { - _actorTouchDataEventHandler += value; - - _actorTouchDataCallbackDelegate = new TouchCallbackDelegate(OnTouch); - this.TouchSignal().Connect(_actorTouchDataCallbackDelegate); - } - } - } - - remove - { - lock(this) - { - if (_actorTouchDataEventHandler != null) - { - this.TouchSignal().Disconnect(_actorTouchDataCallbackDelegate); - } - - _actorTouchDataEventHandler -= value; - } - } - } - - // Callback for Actor TouchSignal - private bool OnTouch(IntPtr actor, IntPtr touchData) - { - TouchEventArgs e = new TouchEventArgs(); - - // Populate all members of "e" (TouchEventArgs) with real data - e.Actor = Actor.GetActorFromPtr(actor); - e.TouchData = Dali.TouchData.GetTouchDataFromPtr(touchData); - - if (_actorTouchDataEventHandler != null) - { - //here we send all data to user event handlers - return _actorTouchDataEventHandler(this, e); - } - - return false; - } - - /** - * @brief Event for Hovered signal which can be used to subscribe/unsubscribe the event handler - * (in the type of HoverEventHandler-DaliEventHandlerWithReturnType) - * provided by the user. Hovered signal is emitted when hover input is received. - */ - public event DaliEventHandlerWithReturnType Hovered - { - add - { - lock(this) - { - // Restricted to only one listener - if (_actorHoverEventHandler == null) - { - _actorHoverEventHandler += value; - - _actorHoverEventCallbackDelegate = new HoverEventCallbackDelegate(OnHoverEvent); - this.HoveredSignal().Connect(_actorHoverEventCallbackDelegate); - } - } - } - - remove - { - lock(this) - { - if (_actorHoverEventHandler != null) - { - this.HoveredSignal().Disconnect(_actorHoverEventCallbackDelegate); - } - - _actorHoverEventHandler -= value; - } - } - } - - // Callback for Actor Hover signal - private bool OnHoverEvent(IntPtr actor, IntPtr hoverEvent) - { - HoverEventArgs e = new HoverEventArgs(); - - // Populate all members of "e" (HoverEventArgs) with real data - e.Actor = Actor.GetActorFromPtr(actor); - e.HoverEvent = Dali.HoverEvent.GetHoverEventFromPtr(hoverEvent); - - if (_actorHoverEventHandler != null) - { - //here we send all data to user event handlers - return _actorHoverEventHandler(this, e); - } - - return false; - } - - /** - * @brief Event for WheelMoved signal which can be used to subscribe/unsubscribe the event handler - * (in the type of WheelEventHandler-DaliEventHandlerWithReturnType) - * provided by the user. WheelMoved signal is emitted when wheel event is received. - */ - public event DaliEventHandlerWithReturnType WheelMoved - { - add - { - lock(this) - { - // Restricted to only one listener - if (_actorWheelEventHandler == null) - { - _actorWheelEventHandler += value; - - _actorWheelEventCallbackDelegate = new WheelEventCallbackDelegate(OnWheelEvent); - this.WheelEventSignal().Connect(_actorWheelEventCallbackDelegate); - } - } - } - - remove - { - lock(this) - { - if (_actorWheelEventHandler != null) - { - this.WheelEventSignal().Disconnect(_actorWheelEventCallbackDelegate); - } - - _actorWheelEventHandler -= value; - } - } - } - - // Callback for Actor Wheel signal - private bool OnWheelEvent(IntPtr actor, IntPtr wheelEvent) - { - WheelEventArgs e = new WheelEventArgs(); - - // Populate all members of "e" (WheelEventArgs) with real data - e.Actor = Actor.GetActorFromPtr(actor); - e.WheelEvent = Dali.WheelEvent.GetWheelEventFromPtr(wheelEvent); - - if (_actorWheelEventHandler != null) - { - //here we send all data to user event handlers - return _actorWheelEventHandler(this, e); - } - - return false; - } - - /** - * @brief Event for OnStage signal which can be used to subscribe/unsubscribe the event handler - * (in the type of OnStageEventHandler) provided by the user. - * OnStage signal is emitted after the actor has been connected to the stage. - */ - public event DaliEventHandler OnStageEvent - { - add - { - lock(this) - { - // Restricted to only one listener - if (_actorOnStageEventHandler == null) - { - _actorOnStageEventHandler += value; - - _actorOnStageEventCallbackDelegate = new OnStageEventCallbackDelegate(OnStage); - this.OnStageSignal().Connect(_actorOnStageEventCallbackDelegate); - } - } - } - - remove - { - lock(this) - { - if (_actorOnStageEventHandler != null) - { - this.OnStageSignal().Disconnect(_actorOnStageEventCallbackDelegate); - } - - _actorOnStageEventHandler -= value; - } - } - } - - // Callback for Actor OnStage signal - private void OnStage(IntPtr data) - { - OnStageEventArgs e = new OnStageEventArgs(); - - // Populate all members of "e" (OnStageEventArgs) with real data - e.Actor = Actor.GetActorFromPtr(data); - - if (_actorOnStageEventHandler != null) - { - //here we send all data to user event handlers - _actorOnStageEventHandler(this, e); - } - } - - /** - * @brief Event for OffStage signal which can be used to subscribe/unsubscribe the event handler - * (in the type of OffStageEventHandler) provided by the user. - * OffStage signal is emitted after the actor has been disconnected from the stage. - */ - public event DaliEventHandler OffStageEvent - { - add - { - lock(this) - { - // Restricted to only one listener - if (_actorOffStageEventHandler == null) - { - _actorOffStageEventHandler += value; - - _actorOffStageEventCallbackDelegate = new OffStageEventCallbackDelegate(OffStage); - this.OnStageSignal().Connect(_actorOffStageEventCallbackDelegate); - } - } - } - - remove - { - lock(this) - { - if (_actorOffStageEventHandler != null) - { - this.OnStageSignal().Disconnect(_actorOffStageEventCallbackDelegate); - } - - _actorOffStageEventHandler -= value; - } - } - } - - // Callback for Actor OffStage signal - private void OffStage(IntPtr data) - { - OffStageEventArgs e = new OffStageEventArgs(); - - // Populate all members of "e" (OffStageEventArgs) with real data - e.Actor = Actor.GetActorFromPtr(data); - - if (_actorOffStageEventHandler != null) - { - //here we send all data to user event handlers - _actorOffStageEventHandler(this, e); - } - } - - /** - * @brief Event for OnRelayout signal which can be used to subscribe/unsubscribe the event handler - * (in the type of OnRelayoutEventHandler) provided by the user. - * OnRelayout signal is emitted after the size has been set on the actor during relayout. - */ - public event DaliEventHandler OnRelayoutEvent - { - add - { - lock(this) - { - // Restricted to only one listener - if (_actorOnRelayoutEventHandler == null) - { - _actorOnRelayoutEventHandler += value; - - _actorOnRelayoutEventCallbackDelegate = new OnRelayoutEventCallbackDelegate(OnRelayout); - this.OnRelayoutSignal().Connect(_actorOnRelayoutEventCallbackDelegate); - } - } - } - - remove - { - lock(this) - { - if (_actorOnRelayoutEventHandler != null) - { - this.OnRelayoutSignal().Disconnect(_actorOnRelayoutEventCallbackDelegate); - } - - _actorOnRelayoutEventHandler -= value; - } - } - } - - // Callback for Actor OnRelayout signal - private void OnRelayout(IntPtr data) - { - OnRelayoutEventArgs e = new OnRelayoutEventArgs(); - - // Populate all members of "e" (OnRelayoutEventArgs) with real data - e.Actor = Actor.GetActorFromPtr(data); - - if (_actorOnRelayoutEventHandler != null) - { - //here we send all data to user event handlers - _actorOnRelayoutEventHandler(this, e); - } - } - public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) { ClassName ret = new ClassName(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -595,7 +46,7 @@ } } - public bool Vibility + public bool Visibility { get { @@ -610,16 +61,12 @@ { SetOpacity(value); } - } - - public float CurrentOpacity - { get { float ret = GetCurrentOpacity(); return ret; } - } + } public bool StateFocusEnable { @@ -634,6 +81,16 @@ } } + public void Show() + { + SetVisible(true); + } + + public void Hide() + { + SetVisible(false); + } + %} %enddef diff --git a/plugins/dali-swig/SWIG/events/animation-event.i b/plugins/dali-swig/SWIG/events/animation-event.i index e921f76..4690317 100644 --- a/plugins/dali-swig/SWIG/events/animation-event.i +++ b/plugins/dali-swig/SWIG/events/animation-event.i @@ -26,6 +26,63 @@ using System.Runtime.InteropServices; %define Animation_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName) %typemap(cscode) NameSpace::ClassName %{ + public static readonly int PARENT_ORIGIN = NDalicPINVOKE.Actor_Property_PARENT_ORIGIN_get(); + public static readonly int PARENT_ORIGIN_X = NDalicPINVOKE.Actor_Property_PARENT_ORIGIN_X_get(); + public static readonly int PARENT_ORIGIN_Y = NDalicPINVOKE.Actor_Property_PARENT_ORIGIN_Y_get(); + public static readonly int PARENT_ORIGIN_Z = NDalicPINVOKE.Actor_Property_PARENT_ORIGIN_Z_get(); + public static readonly int ANCHOR_POINT = NDalicPINVOKE.Actor_Property_ANCHOR_POINT_get(); + public static readonly int ANCHOR_POINT_X = NDalicPINVOKE.Actor_Property_ANCHOR_POINT_X_get(); + public static readonly int ANCHOR_POINT_Y = NDalicPINVOKE.Actor_Property_ANCHOR_POINT_Y_get(); + public static readonly int ANCHOR_POINT_Z = NDalicPINVOKE.Actor_Property_ANCHOR_POINT_Z_get(); + public static readonly int SIZE = NDalicPINVOKE.Actor_Property_SIZE_get(); + public static readonly int SIZE_WIDTH = NDalicPINVOKE.Actor_Property_SIZE_WIDTH_get(); + public static readonly int SIZE_HEIGHT = NDalicPINVOKE.Actor_Property_SIZE_HEIGHT_get(); + public static readonly int SIZE_DEPTH = NDalicPINVOKE.Actor_Property_SIZE_DEPTH_get(); + public static readonly int POSITION = NDalicPINVOKE.Actor_Property_POSITION_get(); + public static readonly int POSITION_X = NDalicPINVOKE.Actor_Property_POSITION_X_get(); + public static readonly int POSITION_Y = NDalicPINVOKE.Actor_Property_POSITION_Y_get(); + public static readonly int POSITION_Z = NDalicPINVOKE.Actor_Property_POSITION_Z_get(); + public static readonly int WORLD_POSITION = NDalicPINVOKE.Actor_Property_WORLD_POSITION_get(); + public static readonly int WORLD_POSITION_X = NDalicPINVOKE.Actor_Property_WORLD_POSITION_X_get(); + public static readonly int WORLD_POSITION_Y = NDalicPINVOKE.Actor_Property_WORLD_POSITION_Y_get(); + public static readonly int WORLD_POSITION_Z = NDalicPINVOKE.Actor_Property_WORLD_POSITION_Z_get(); + public static readonly int ORIENTATION = NDalicPINVOKE.Actor_Property_ORIENTATION_get(); + public static readonly int WORLD_ORIENTATION = NDalicPINVOKE.Actor_Property_WORLD_ORIENTATION_get(); + public static readonly int SCALE = NDalicPINVOKE.Actor_Property_SCALE_get(); + public static readonly int SCALE_X = NDalicPINVOKE.Actor_Property_SCALE_X_get(); + public static readonly int SCALE_Y = NDalicPINVOKE.Actor_Property_SCALE_Y_get(); + public static readonly int SCALE_Z = NDalicPINVOKE.Actor_Property_SCALE_Z_get(); + public static readonly int WORLD_SCALE = NDalicPINVOKE.Actor_Property_WORLD_SCALE_get(); + public static readonly int VISIBLE = NDalicPINVOKE.Actor_Property_VISIBLE_get(); + public static readonly int COLOR = NDalicPINVOKE.Actor_Property_COLOR_get(); + public static readonly int COLOR_RED = NDalicPINVOKE.Actor_Property_COLOR_RED_get(); + public static readonly int COLOR_GREEN = NDalicPINVOKE.Actor_Property_COLOR_GREEN_get(); + public static readonly int COLOR_BLUE = NDalicPINVOKE.Actor_Property_COLOR_BLUE_get(); + public static readonly int COLOR_ALPHA = NDalicPINVOKE.Actor_Property_COLOR_ALPHA_get(); + public static readonly int WORLD_COLOR = NDalicPINVOKE.Actor_Property_WORLD_COLOR_get(); + public static readonly int WORLD_MATRIX = NDalicPINVOKE.Actor_Property_WORLD_MATRIX_get(); + public static readonly int NAME = NDalicPINVOKE.Actor_Property_NAME_get(); + public static readonly int SENSITIVE = NDalicPINVOKE.Actor_Property_SENSITIVE_get(); + public static readonly int LEAVE_REQUIRED = NDalicPINVOKE.Actor_Property_LEAVE_REQUIRED_get(); + public static readonly int INHERIT_ORIENTATION = NDalicPINVOKE.Actor_Property_INHERIT_ORIENTATION_get(); + public static readonly int INHERIT_SCALE = NDalicPINVOKE.Actor_Property_INHERIT_SCALE_get(); + public static readonly int COLOR_MODE = NDalicPINVOKE.Actor_Property_COLOR_MODE_get(); + public static readonly int POSITION_INHERITANCE = NDalicPINVOKE.Actor_Property_POSITION_INHERITANCE_get(); + public static readonly int DRAW_MODE = NDalicPINVOKE.Actor_Property_DRAW_MODE_get(); + public static readonly int SIZE_MODE_FACTOR = NDalicPINVOKE.Actor_Property_SIZE_MODE_FACTOR_get(); + public static readonly int WIDTH_RESIZE_POLICY = NDalicPINVOKE.Actor_Property_WIDTH_RESIZE_POLICY_get(); + public static readonly int HEIGHT_RESIZE_POLICY = NDalicPINVOKE.Actor_Property_HEIGHT_RESIZE_POLICY_get(); + public static readonly int SIZE_SCALE_POLICY = NDalicPINVOKE.Actor_Property_SIZE_SCALE_POLICY_get(); + public static readonly int WIDTH_FOR_HEIGHT = NDalicPINVOKE.Actor_Property_WIDTH_FOR_HEIGHT_get(); + public static readonly int HEIGHT_FOR_WIDTH = NDalicPINVOKE.Actor_Property_HEIGHT_FOR_WIDTH_get(); + public static readonly int PADDING = NDalicPINVOKE.Actor_Property_PADDING_get(); + public static readonly int MINIMUM_SIZE = NDalicPINVOKE.Actor_Property_MINIMUM_SIZE_get(); + public static readonly int MAXIMUM_SIZE = NDalicPINVOKE.Actor_Property_MAXIMUM_SIZE_get(); + public static readonly int INHERIT_POSITION = NDalicPINVOKE.Actor_Property_INHERIT_POSITION_get(); + public static readonly int CLIPPING_MODE = NDalicPINVOKE.Actor_Property_CLIPPING_MODE_get(); + public static readonly int BATCH_PARENT = NDalicPINVOKE.Actor_Property_BATCH_PARENT_get(); + + /** * @brief Event arguments that passed via Finished signal * @@ -150,6 +207,123 @@ using System.Runtime.InteropServices; } } + public int LoopCount + { + set + { + SetLoopCount(value); + } + get + { + int ret = GetLoopCount(); + return ret; + } + } + + public void AnimateBy(Actor target, T propertyIndex, U relativeValue) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(relativeValue); + AnimateBy(new Property(target, var), new Property.Value(obj)); + } + + public void AnimateBy(Actor target, T propertyIndex, U relativeValue, AlphaFunction alpha) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(relativeValue); + AnimateBy(new Property(target, var), new Property.Value(obj), alpha); + } + + public void AnimateBy(Actor target, T propertyIndex, U relativeValue, TimePeriod period) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(relativeValue); + AnimateBy(new Property(target, var), new Property.Value(obj), period); + } + + public void AnimateBy(Actor target, T propertyIndex, U relativeValue, AlphaFunction alpha, TimePeriod period) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(relativeValue); + AnimateBy(new Property(target, var), new Property.Value(obj), alpha, period); + } + + public void AnimateTo(Actor target, T propertyIndex, U destinationValue) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(destinationValue); + AnimateTo(new Property(target, var), new Property.Value(obj)); + } + + public void AnimateTo(Actor target, T propertyIndex, U destinationValue, AlphaFunction alpha) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(destinationValue); + AnimateTo(new Property(target, var), new Property.Value(obj), alpha); + } + + public void AnimateTo(Actor target, T propertyIndex, U destinationValue, TimePeriod period) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(destinationValue); + AnimateTo(new Property(target, var), new Property.Value(obj), period); + } + + public void AnimateTo(Actor target, T propertyIndex, U destinationValue, AlphaFunction alpha, TimePeriod period) + { + dynamic var = (object)(propertyIndex); + dynamic obj = (object)(destinationValue); + AnimateTo(new Property(target, var), new Property.Value(obj), alpha, period); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames, Animation.Interpolation interpolation) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames, interpolation); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames, AlphaFunction alpha) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames, alpha); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames, AlphaFunction alpha, Animation.Interpolation interpolation) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames, alpha, interpolation); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames, TimePeriod period) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames, period); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames, TimePeriod period, Animation.Interpolation interpolation) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames, period, interpolation); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames, AlphaFunction alpha, TimePeriod period) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames, alpha, period); + } + + public void AnimateBetween(Actor target, U propertyIndex, KeyFrames keyFrames, AlphaFunction alpha, TimePeriod period, Animation.Interpolation interpolation) + { + dynamic var = (object)(propertyIndex); + AnimateBetween(new Property(target, var), keyFrames, alpha, period, interpolation); + } + %} %enddef diff --git a/plugins/dali-swig/SWIG/events/control-event.i b/plugins/dali-swig/SWIG/events/control-event.i index 9f7d02f..489af5a 100644 --- a/plugins/dali-swig/SWIG/events/control-event.i +++ b/plugins/dali-swig/SWIG/events/control-event.i @@ -16,297 +16,845 @@ */ %define CONTROL_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName) -%typemap(csimports) NameSpace::ClassName %{ -using System; -using System.Runtime.InteropServices; + %typemap(csimports) NameSpace::ClassName %{ + using System; + using System.Runtime.InteropServices; -%} + %} -%enddef + %enddef %define CONTROL_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName) -%typemap(cscode) NameSpace::ClassName %{ + %typemap(cscode) NameSpace::ClassName %{ -/** - * @brief Event arguments that passed via KeyInputFocusGained signal - * - */ -public class KeyInputFocusGainedEventArgs : EventArgs -{ - private View _view; - - /** - * @brief View - is the view that gets Key Input Focus + /** + * @brief Event arguments that passed via KeyInputFocusGained signal * */ - public View View - { - get + public class KeyInputFocusGainedEventArgs : EventArgs + { + private View _view; + + /** + * @brief View - is the view that gets Key Input Focus + * + */ + public View View { - return _view; + get + { + return _view; + } + set + { + _view = value; + } } - set + } + + /** + * @brief Event arguments that passed via KeyInputFocusLost signal + * + */ + public class KeyInputFocusLostEventArgs : EventArgs + { + private View _view; + + /** + * @brief View - is the view that loses Key Input Focus + * + */ + public View View { - _view = value; + get + { + return _view; + } + set + { + _view = value; + } } - } -} - -/** - * @brief Event arguments that passed via KeyInputFocusLost signal - * - */ -public class KeyInputFocusLostEventArgs : EventArgs -{ - private View _view; + } - /** - * @brief View - is the view that loses Key Input Focus + /** + * @brief Event arguments that passed via KeyEvent signal * */ - public View View - { - get + public class KeyEventArgs : EventArgs + { + private View _view; + private KeyEvent _keyEvent; + + /** + * @brief View - is the view that recieves the keyevent. + * + */ + public View View { - return _view; + get + { + return _view; + } + set + { + _view = value; + } } - set + + /** + * @brief KeyEvent - is the keyevent sent to the View. + * + */ + public KeyEvent KeyEvent { - _view = value; + get + { + return _keyEvent; + } + set + { + _keyEvent = value; + } + } + } + + /** + * @brief Event arguments that passed via OnRelayout signal + * + */ + public class OnRelayoutEventArgs : EventArgs + { + private View _view; + + /** + * @brief View - is the view that is being resized upon relayout + * + */ + public View View + { + get + { + return _view; + } + set + { + _view = value; + } + } + } + + + /** + * @brief Event arguments that passed via Touch signal + * + */ + public class TouchEventArgs : EventArgs + { + private View _view; + private TouchData _touchData; + + /** + * @brief View - is the view that is being touched + * + */ + public View View + { + get + { + return _view; + } + set + { + _view = value; + } } - } -} -/** - * @brief Event arguments that passed via KeyEvent signal - * - */ -public class KeyEventArgs : EventArgs -{ - private View _view; - private KeyEvent _keyEvent; + /** + * @brief TouchData - contains the information of touch points + * + */ + public TouchData TouchData + { + get + { + return _touchData; + } + set + { + _touchData = value; + } + } + } + + /** + * @brief Event arguments that passed via Hover signal + * + */ + public class HoverEventArgs : EventArgs + { + private View _view; + private HoverEvent _hoverEvent; + + /** + * @brief View - is the view that is being hovered + * + */ + public View View + { + get + { + return _view; + } + set + { + _view = value; + } + } - /** - * @brief View - is the view that recieves the keyevent. - * + /** + * @brief HoverEvent - contains touch points that represent the points + * that are currently being hovered or the points where a hover has stopped + * + */ + public HoverEvent HoverEvent + { + get + { + return _hoverEvent; + } + set + { + _hoverEvent = value; + } + } + } + + /** + * @brief Event arguments that passed via Wheel signal + * + */ + public class WheelEventArgs : EventArgs + { + private View _view; + private WheelEvent _wheelEvent; + + /** + * @brief View - is the view that is being wheeled + * + */ + public View View + { + get + { + return _view; + } + set + { + _view = value; + } + } + + /** + * @brief WheelEvent - store a wheel rolling type : MOUSE_WHEEL or CUSTOM_WHEEL + * + */ + public WheelEvent WheelEvent + { + get + { + return _wheelEvent; + } + set + { + _wheelEvent = value; + } + } + } + + /** + * @brief Event arguments that passed via OnStage signal + * + */ + public class OnStageEventArgs : EventArgs + { + private View _view; + + /** + * @brief View - is the view that is being connected to the stage + * + */ + public View View + { + get + { + return _view; + } + set + { + _view = value; + } + } + } + + /** + * @brief Event arguments that passed via OffStage signal + * + */ + public class OffStageEventArgs : EventArgs + { + private View _view; + + /** + * @brief View - is the view that is being disconnected from the stage + * + */ + public View View + { + get + { + return _view; + } + set + { + _view = value; + } + } + } + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void KeyInputFocusGainedCallbackDelegate(IntPtr control); + private DaliEventHandler _KeyInputFocusGainedEventHandler; + private KeyInputFocusGainedCallbackDelegate _KeyInputFocusGainedCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void KeyInputFocusLostCallbackDelegate(IntPtr control); + private DaliEventHandler _KeyInputFocusLostEventHandler; + private KeyInputFocusLostCallbackDelegate _KeyInputFocusLostCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate bool KeyCallbackDelegate(IntPtr control, IntPtr keyEvent); + private DaliEventHandlerWithReturnType _KeyEventHandler; + private KeyCallbackDelegate _KeyCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void OnRelayoutEventCallbackDelegate(IntPtr control); + private DaliEventHandler _viewOnRelayoutEventHandler; + private OnRelayoutEventCallbackDelegate _viewOnRelayoutEventCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate bool TouchCallbackDelegate(IntPtr view, IntPtr touchData); + private DaliEventHandlerWithReturnType _viewTouchDataEventHandler; + private TouchCallbackDelegate _viewTouchDataCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate bool HoverEventCallbackDelegate(IntPtr view, IntPtr hoverEvent); + private DaliEventHandlerWithReturnType _viewHoverEventHandler; + private HoverEventCallbackDelegate _viewHoverEventCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate bool WheelEventCallbackDelegate(IntPtr view, IntPtr wheelEvent); + private DaliEventHandlerWithReturnType _viewWheelEventHandler; + private WheelEventCallbackDelegate _viewWheelEventCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void OnStageEventCallbackDelegate(IntPtr control); + private DaliEventHandler _viewOnStageEventHandler; + private OnStageEventCallbackDelegate _viewOnStageEventCallbackDelegate; + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void OffStageEventCallbackDelegate(IntPtr control); + private DaliEventHandler _viewOffStageEventHandler; + private OffStageEventCallbackDelegate _viewOffStageEventCallbackDelegate; + + /** + * @brief Event for KeyInputFocusGained signal which can be used to subscribe/unsubscribe the event handler + * (in the type of KeyInputFocusGainedEventHandler-DaliEventHandler) + * provided by the user. KeyInputFocusGained signal is emitted when the control gets Key Input Focus. */ - public View View - { - get + public event DaliEventHandler KeyInputFocusGained + { + add + { + lock(this) + { + // Restricted to only one listener + if (_KeyInputFocusGainedEventHandler == null) + { + _KeyInputFocusGainedEventHandler += value; + Console.WriteLine("View Keyevent EVENT Locked...."); + _KeyInputFocusGainedCallbackDelegate = new KeyInputFocusGainedCallbackDelegate(OnKeyInputFocusGained); + this.KeyInputFocusGainedSignal().Connect(_KeyInputFocusGainedCallbackDelegate); + } + } + } + + remove { - return _view; + lock(this) + { + if (_KeyInputFocusGainedEventHandler != null) + { + this.KeyInputFocusGainedSignal().Disconnect(_KeyInputFocusGainedCallbackDelegate); + } + + _KeyInputFocusGainedEventHandler -= value; + } } - set + } + + private void OnKeyInputFocusGained(IntPtr view) + { + KeyInputFocusGainedEventArgs e = new KeyInputFocusGainedEventArgs(); + Console.WriteLine("View Keyevent ...."); + // Populate all members of "e" (KeyInputFocusGainedEventArgs) with real data + e.View = Dali.View.GetViewFromPtr(view); + + if (_KeyInputFocusGainedEventHandler != null) { - _view = value; + //here we send all data to user event handlers + _KeyInputFocusGainedEventHandler(this, e); } - } - /** - * @brief KeyEvent - is the keyevent sent to the View. - * + } + + /** + * @brief Event for KeyInputFocusLost signal which can be used to subscribe/unsubscribe the event handler + * (in the type of KeyInputFocusLostEventHandler-DaliEventHandler) + * provided by the user. KeyInputFocusLost signal is emitted when the control loses Key Input Focus. */ - public KeyEvent KeyEvent - { - get + public event DaliEventHandler KeyInputFocusLost + { + add { - return _keyEvent; + lock(this) + { + // Restricted to only one listener + if (_KeyInputFocusLostEventHandler == null) + { + _KeyInputFocusLostEventHandler += value; + + _KeyInputFocusLostCallbackDelegate = new KeyInputFocusLostCallbackDelegate(OnKeyInputFocusLost); + this.KeyInputFocusLostSignal().Connect(_KeyInputFocusLostCallbackDelegate); + } + } } - set + + remove { - _keyEvent = value; + lock(this) + { + if (_KeyInputFocusLostEventHandler != null) + { + this.KeyInputFocusLostSignal().Disconnect(_KeyInputFocusLostCallbackDelegate); + } + + _KeyInputFocusLostEventHandler -= value; + } + } + } + + private void OnKeyInputFocusLost(IntPtr view) + { + KeyInputFocusLostEventArgs e = new KeyInputFocusLostEventArgs(); + + // Populate all members of "e" (KeyInputFocusLostEventArgs) with real data + e.View = Dali.View.GetViewFromPtr(view); + + if (_KeyInputFocusLostEventHandler != null) + { + //here we send all data to user event handlers + _KeyInputFocusLostEventHandler(this, e); + } + } + + /** + * @brief Event for KeyPressed signal which can be used to subscribe/unsubscribe the event handler + * (in the type of KeyEventEventHandler-DaliEventHandlerWithReturnType) + * provided by the user. KeyPressed signal is emitted when key event is received. + */ + public event DaliEventHandlerWithReturnType KeyPressed + { + add + { + lock(this) + { + // Restricted to only one listener + if (_KeyEventHandler == null) + { + _KeyEventHandler += value; + + _KeyCallbackDelegate = new KeyCallbackDelegate(OnKeyEvent); + this.KeyEventSignal().Connect(_KeyCallbackDelegate); + } + } } - } -} - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void KeyInputFocusGainedCallbackDelegate(IntPtr control); - private DaliEventHandler _KeyInputFocusGainedEventHandler; - private KeyInputFocusGainedCallbackDelegate _KeyInputFocusGainedCallbackDelegate; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void KeyInputFocusLostCallbackDelegate(IntPtr control); - private DaliEventHandler _KeyInputFocusLostEventHandler; - private KeyInputFocusLostCallbackDelegate _KeyInputFocusLostCallbackDelegate; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate bool KeyCallbackDelegate(IntPtr control, IntPtr keyEvent); - private DaliEventHandlerWithReturnType _KeyEventHandler; - private KeyCallbackDelegate _KeyCallbackDelegate; - - /** - * @brief Event for KeyInputFocusGained signal which can be used to subscribe/unsubscribe the event handler - * (in the type of KeyInputFocusGainedEventHandler-DaliEventHandler) - * provided by the user. KeyInputFocusGained signal is emitted when the control gets Key Input Focus. - */ - public event DaliEventHandler KeyInputFocusGained - { - add - { + remove + { lock(this) { - // Restricted to only one listener - if (_KeyInputFocusGainedEventHandler == null) - { - _KeyInputFocusGainedEventHandler += value; + if (_KeyEventHandler != null) + { + this.KeyEventSignal().Disconnect(_KeyCallbackDelegate); + } + + _KeyEventHandler -= value; + } + } + } + + private bool OnKeyEvent(IntPtr view, IntPtr keyEvent) + { + KeyEventArgs e = new KeyEventArgs(); + + // Populate all members of "e" (KeyEventArgs) with real data + e.View = Dali.View.GetViewFromPtr(view); + e.KeyEvent = Dali.KeyEvent.GetKeyEventFromPtr(keyEvent); - _KeyInputFocusGainedCallbackDelegate = new KeyInputFocusGainedCallbackDelegate(OnKeyInputFocusGained); - this.KeyInputFocusGainedSignal().Connect(_KeyInputFocusGainedCallbackDelegate); - } + if (_KeyEventHandler != null) + { + //here we send all data to user event handlers + return _KeyEventHandler(this, e); + } + return false; + + } + + /** + * @brief Event for OnRelayout signal which can be used to subscribe/unsubscribe the event handler + * (in the type of OnRelayoutEventHandler) provided by the user. + * OnRelayout signal is emitted after the size has been set on the view during relayout. + */ + public event DaliEventHandler OnRelayoutEvent + { + add + { + lock(this) + { + // Restricted to only one listener + if (_viewOnRelayoutEventHandler == null) + { + _viewOnRelayoutEventHandler += value; + Console.WriteLine("View OnRelayoutEventArgs Locked...."); + _viewOnRelayoutEventCallbackDelegate = new OnRelayoutEventCallbackDelegate(OnRelayout); + this.OnRelayoutSignal().Connect(_viewOnRelayoutEventCallbackDelegate); + } } - } + } - remove - { + remove + { lock(this) { - if (_KeyInputFocusGainedEventHandler != null) - { - this.KeyInputFocusGainedSignal().Disconnect(_KeyInputFocusGainedCallbackDelegate); - } + if (_viewOnRelayoutEventHandler != null) + { + this.OnRelayoutSignal().Disconnect(_viewOnRelayoutEventCallbackDelegate); + } - _KeyInputFocusGainedEventHandler -= value; + _viewOnRelayoutEventHandler -= value; } - } - } + } + } + + // Callback for View OnRelayout signal + private void OnRelayout(IntPtr data) + { + OnRelayoutEventArgs e = new OnRelayoutEventArgs(); + Console.WriteLine("View OnRelayoutEventArgs...."); + // Populate all members of "e" (OnRelayoutEventArgs) with real data + e.View = View.GetViewFromPtr(data); - private void OnKeyInputFocusGained(IntPtr view) - { - KeyInputFocusGainedEventArgs e = new KeyInputFocusGainedEventArgs(); + if (_viewOnRelayoutEventHandler != null) + { + //here we send all data to user event handlers + _viewOnRelayoutEventHandler(this, e); + } + } + + /** + * @brief Event for Touched signal which can be used to subscribe/unsubscribe the event handler + * (in the type of TouchEventHandler-DaliEventHandlerWithReturnType) + * provided by the user. Touched signal is emitted when touch input is received. + */ + public event DaliEventHandlerWithReturnType Touched + { + add + { + lock(this) + { + // Restricted to only one listener + if (_viewTouchDataEventHandler == null) + { + _viewTouchDataEventHandler += value; + Console.WriteLine("View Touch EVENT LOCKED...."); + _viewTouchDataCallbackDelegate = new TouchCallbackDelegate(OnTouch); + this.TouchSignal().Connect(_viewTouchDataCallbackDelegate); + } + } + } - // Populate all members of "e" (KeyInputFocusGainedEventArgs) with real data - e.View = Dali.View.GetViewFromPtr(view); + remove + { + lock(this) + { + if (_viewTouchDataEventHandler != null) + { + this.TouchSignal().Disconnect(_viewTouchDataCallbackDelegate); + } - if (_KeyInputFocusGainedEventHandler != null) - { - //here we send all data to user event handlers - _KeyInputFocusGainedEventHandler(this, e); - } + _viewTouchDataEventHandler -= value; + } + } + } + + // Callback for View TouchSignal + private bool OnTouch(IntPtr view, IntPtr touchData) + { + TouchEventArgs e = new TouchEventArgs(); + Console.WriteLine("View Touch EVENT...."); + // Populate all members of "e" (TouchEventArgs) with real data + e.View = View.GetViewFromPtr(view); + e.TouchData = Dali.TouchData.GetTouchDataFromPtr(touchData); + + if (_viewTouchDataEventHandler != null) + { + //here we send all data to user event handlers + return _viewTouchDataEventHandler(this, e); + } - } + return false; + } + + /** + * @brief Event for Hovered signal which can be used to subscribe/unsubscribe the event handler + * (in the type of HoverEventHandler-DaliEventHandlerWithReturnType) + * provided by the user. Hovered signal is emitted when hover input is received. + */ + public event DaliEventHandlerWithReturnType Hovered + { + add + { + lock(this) + { + // Restricted to only one listener + if (_viewHoverEventHandler == null) + { + _viewHoverEventHandler += value; + + _viewHoverEventCallbackDelegate = new HoverEventCallbackDelegate(OnHoverEvent); + this.HoveredSignal().Connect(_viewHoverEventCallbackDelegate); + } + } + } - /** - * @brief Event for KeyInputFocusLost signal which can be used to subscribe/unsubscribe the event handler - * (in the type of KeyInputFocusLostEventHandler-DaliEventHandler) - * provided by the user. KeyInputFocusLost signal is emitted when the control loses Key Input Focus. - */ - public event DaliEventHandler KeyInputFocusLost - { - add - { + remove + { lock(this) { - // Restricted to only one listener - if (_KeyInputFocusLostEventHandler == null) - { - _KeyInputFocusLostEventHandler += value; + if (_viewHoverEventHandler != null) + { + this.HoveredSignal().Disconnect(_viewHoverEventCallbackDelegate); + } - _KeyInputFocusLostCallbackDelegate = new KeyInputFocusLostCallbackDelegate(OnKeyInputFocusLost); - this.KeyInputFocusLostSignal().Connect(_KeyInputFocusLostCallbackDelegate); - } + _viewHoverEventHandler -= value; } - } + } + } + + // Callback for View Hover signal + private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent) + { + HoverEventArgs e = new HoverEventArgs(); + + // Populate all members of "e" (HoverEventArgs) with real data + e.View = View.GetViewFromPtr(view); + e.HoverEvent = Dali.HoverEvent.GetHoverEventFromPtr(hoverEvent); + + if (_viewHoverEventHandler != null) + { + //here we send all data to user event handlers + return _viewHoverEventHandler(this, e); + } - remove - { + return false; + } + + /** + * @brief Event for WheelMoved signal which can be used to subscribe/unsubscribe the event handler + * (in the type of WheelEventHandler-DaliEventHandlerWithReturnType) + * provided by the user. WheelMoved signal is emitted when wheel event is received. + */ + public event DaliEventHandlerWithReturnType WheelMoved + { + add + { lock(this) { - if (_KeyInputFocusLostEventHandler != null) - { - this.KeyInputFocusLostSignal().Disconnect(_KeyInputFocusLostCallbackDelegate); - } - - _KeyInputFocusLostEventHandler -= value; - } - } - } - - private void OnKeyInputFocusLost(IntPtr view) - { - KeyInputFocusLostEventArgs e = new KeyInputFocusLostEventArgs(); - - // Populate all members of "e" (KeyInputFocusLostEventArgs) with real data - e.View = Dali.View.GetViewFromPtr(view); - - if (_KeyInputFocusLostEventHandler != null) - { - //here we send all data to user event handlers - _KeyInputFocusLostEventHandler(this, e); - } - } - - /** - * @brief Event for KeyPressed signal which can be used to subscribe/unsubscribe the event handler - * (in the type of KeyEventEventHandler-DaliEventHandlerWithReturnType) - * provided by the user. KeyPressed signal is emitted when key event is received. - */ - public event DaliEventHandlerWithReturnType KeyPressed - { - add - { + // Restricted to only one listener + if (_viewWheelEventHandler == null) + { + _viewWheelEventHandler += value; + Console.WriteLine("View Wheel EVENT LOCKED...."); + _viewWheelEventCallbackDelegate = new WheelEventCallbackDelegate(OnWheelEvent); + this.WheelEventSignal().Connect(_viewWheelEventCallbackDelegate); + } + } + } + + remove + { lock(this) { - // Restricted to only one listener - if (_KeyEventHandler == null) - { - _KeyEventHandler += value; + if (_viewWheelEventHandler != null) + { + this.WheelEventSignal().Disconnect(_viewWheelEventCallbackDelegate); + } + + _viewWheelEventHandler -= value; + } + } + } + + // Callback for View Wheel signal + private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent) + { + WheelEventArgs e = new WheelEventArgs(); + Console.WriteLine("View Wheel EVENT ...."); + // Populate all members of "e" (WheelEventArgs) with real data + e.View = View.GetViewFromPtr(view); + e.WheelEvent = Dali.WheelEvent.GetWheelEventFromPtr(wheelEvent); + + if (_viewWheelEventHandler != null) + { + //here we send all data to user event handlers + return _viewWheelEventHandler(this, e); + } - _KeyCallbackDelegate = new KeyCallbackDelegate(OnKeyEvent); - this.KeyEventSignal().Connect(_KeyCallbackDelegate); - } + return false; + } + + /** + * @brief Event for OnStage signal which can be used to subscribe/unsubscribe the event handler + * (in the type of OnStageEventHandler) provided by the user. + * OnStage signal is emitted after the view has been connected to the stage. + */ + public event DaliEventHandler OnStageEvent + { + add + { + lock(this) + { + // Restricted to only one listener + if (_viewOnStageEventHandler == null) + { + _viewOnStageEventHandler += value; + + _viewOnStageEventCallbackDelegate = new OnStageEventCallbackDelegate(OnStage); + this.OnStageSignal().Connect(_viewOnStageEventCallbackDelegate); + } } - } + } - remove - { + remove + { lock(this) { - if (_KeyEventHandler != null) - { - this.KeyEventSignal().Disconnect(_KeyCallbackDelegate); - } + if (_viewOnStageEventHandler != null) + { + this.OnStageSignal().Disconnect(_viewOnStageEventCallbackDelegate); + } + + _viewOnStageEventHandler -= value; + } + } + } + + // Callback for View OnStage signal + private void OnStage(IntPtr data) + { + OnStageEventArgs e = new OnStageEventArgs(); - _KeyEventHandler -= value; + // Populate all members of "e" (OnStageEventArgs) with real data + e.View = View.GetViewFromPtr(data); + + if (_viewOnStageEventHandler != null) + { + //here we send all data to user event handlers + _viewOnStageEventHandler(this, e); + } + } + + /** + * @brief Event for OffStage signal which can be used to subscribe/unsubscribe the event handler + * (in the type of OffStageEventHandler) provided by the user. + * OffStage signal is emitted after the view has been disconnected from the stage. + */ + public event DaliEventHandler OffStageEvent + { + add + { + lock(this) + { + // Restricted to only one listener + if (_viewOffStageEventHandler == null) + { + _viewOffStageEventHandler += value; + + _viewOffStageEventCallbackDelegate = new OffStageEventCallbackDelegate(OffStage); + this.OnStageSignal().Connect(_viewOffStageEventCallbackDelegate); + } } - } - } + } + + remove + { + lock(this) + { + if (_viewOffStageEventHandler != null) + { + this.OnStageSignal().Disconnect(_viewOffStageEventCallbackDelegate); + } - private bool OnKeyEvent(IntPtr view, IntPtr keyEvent) - { - KeyEventArgs e = new KeyEventArgs(); + _viewOffStageEventHandler -= value; + } + } + } - // Populate all members of "e" (KeyEventArgs) with real data - e.View = Dali.View.GetViewFromPtr(view); - e.KeyEvent = Dali.KeyEvent.GetKeyEventFromPtr(keyEvent); + // Callback for View OffStage signal + private void OffStage(IntPtr data) + { + OffStageEventArgs e = new OffStageEventArgs(); - if (_KeyEventHandler != null) - { - //here we send all data to user event handlers - return _KeyEventHandler(this, e); - } - return false; + // Populate all members of "e" (OffStageEventArgs) with real data + e.View = View.GetViewFromPtr(data); - } + if (_viewOffStageEventHandler != null) + { + //here we send all data to user event handlers + _viewOffStageEventHandler(this, e); + } + } - public static View GetViewFromPtr(global::System.IntPtr cPtr) { - View ret = new View(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } + public static View GetViewFromPtr(global::System.IntPtr cPtr) { + View ret = new View(cPtr, false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } -%} + %} -%enddef + %enddef %define DALI_CONTROL_EVENTHANDLER_PARAM( NameSpace, ClassName) CONTROL_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName); CONTROL_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName); -%enddef + %enddef -namespace Dali + namespace Dali { DALI_CONTROL_EVENTHANDLER_PARAM( Dali::Toolkit, Control); } diff --git a/plugins/dali-swig/SWIG/events/rectinteger.i b/plugins/dali-swig/SWIG/events/rectinteger.i new file mode 100644 index 0000000..b89d1f5 --- /dev/null +++ b/plugins/dali-swig/SWIG/events/rectinteger.i @@ -0,0 +1,76 @@ +/* + * 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. + * + */ + +%define DALI_RECTINTEGER_PROPERTY_PARAM(NameSpace,ClassName) + %typemap(cscode) NameSpace::ClassName %{ + + public int X { + set { + NDalicPINVOKE.RectInteger_x_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get { + int ret = NDalicPINVOKE.RectInteger_x_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + public int Y { + set { + NDalicPINVOKE.RectInteger_y_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get { + int ret = NDalicPINVOKE.RectInteger_y_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + public int W { + set { + NDalicPINVOKE.RectInteger_width_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get { + int ret = NDalicPINVOKE.RectInteger_width_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + public int H { + set { + NDalicPINVOKE.RectInteger_height_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get { + int ret = NDalicPINVOKE.RectInteger_height_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + +%} + +%enddef + +namespace Dali +{ + DALI_RECTINTEGER_PROPERTY_PARAM( Dali, Rect); +} diff --git a/plugins/dali-swig/examples/dali-test.cs b/plugins/dali-swig/examples/dali-test.cs index ac4bc85..491bd95 100644 --- a/plugins/dali-swig/examples/dali-test.cs +++ b/plugins/dali-swig/examples/dali-test.cs @@ -39,6 +39,9 @@ namespace MyCSharpExample public void Initialize(object source, AUIApplicationInitEventArgs e) { + + OperatorTests(); + Handle handle = new Handle(); int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE); float myProperty = 0.0f; @@ -162,6 +165,181 @@ namespace MyCSharpExample Console.WriteLine( " Vector4 r = " + vector4.r + ", g = " + vector4.g + ", b = " + vector4.b + ", a = " + vector4.a ); } + + public void OperatorTests() + { + Actor actor = new Actor(); + Actor differentActor = new Actor(); + Actor actorSame = actor; + Actor nullActor = null; + + // test the true operator + if ( actor ) + { + Console.WriteLine ("BaseHandle Operator true (actor) : test passed "); + } + else + { + Console.WriteLine ("BaseHandle Operator true (actor): test failed "); + } + + Actor parent = actor.GetParent (); + + if ( parent ) + { + Console.WriteLine ("Handle with Empty body :failed "); + } + else + { + Console.WriteLine ("Valid with Empty body :passed "); + } + + actor.Add( differentActor ); + // here we test two different C# objects, which on the native side have the same body/ ref-object + if ( actor == differentActor.GetParent() ) + { + Console.WriteLine ("actor == differentActor.GetParent() :passed "); + } + else + { + Console.WriteLine ("actor == differentActor.GetParent() :failed "); + } + + if ( differentActor == differentActor.GetParent() ) + { + Console.WriteLine ("differentActor == differentActor.GetParent() :failed "); + } + else + { + Console.WriteLine ("differentActor == differentActor.GetParent() :passed "); + } + + + if ( nullActor ) + { + Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed "); + } + else + { + Console.WriteLine ("BaseHandle Operator true (nullActor): test passed "); + } + + // ! operator + if ( !actor ) + { + Console.WriteLine ("BaseHandle Operator !(actor) : test failed "); + } + else + { + Console.WriteLine ("BaseHandle Operator !(actor): test passed "); + } + + if ( !nullActor ) + { + Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed "); + } + else + { + Console.WriteLine ("BaseHandle Operator !(nullActor): test failed "); + } + + // Note: operator false only used inside & operator + // test equality operator == + if ( actor == actorSame ) + { + Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed"); + } + + if ( actor == differentActor ) + { + Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed"); + } + + if ( actor == nullActor ) + { + Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed"); + } + + if ( nullActor == nullActor ) + { + Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed"); + } + + // test || operator + if ( actor || actorSame ) + { + Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed"); + } + + if ( actor || nullActor ) + { + Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed"); + } + + if ( nullActor || nullActor ) + { + Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed"); + } + + + // test && operator + if ( actor && actorSame ) + { + Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed"); + } + + if ( actor && nullActor ) + { + Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed"); + } + + if ( nullActor && nullActor ) + { + Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed"); + } + else + { + Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed"); + } + + } + public void MainLoop() { _application.MainLoop (); diff --git a/plugins/dali-swig/examples/firstscreen/App.cs b/plugins/dali-swig/examples/firstscreen/App.cs new file mode 100644 index 0000000..5f5819f --- /dev/null +++ b/plugins/dali-swig/examples/firstscreen/App.cs @@ -0,0 +1,392 @@ +using Dali; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; + +namespace FirstScreen +{ + public class FirstScreenApp + { + private int _currentPostersContainerID; + private int _totalPostersContainers; + + private Application _application; + private Stage _stage; + private Vector2 _stageSize; + + private List _postersContainer; + + private ScrollContainer _menuContainer; + private Vector3 _menuItemSize; + + private Layer _bottomClipLayer; + private Layer _topClipLayer; + private View _topContainer; + private View _bottomContainer; + + private FocusEffect _focusEffect; + private string _imagePath; + + private ImageView _keyboardFocusIndicator; + private ImageView _launcherSeparator; + private ImageView[] launcherIcon; + private Animation _showBottomContainerAnimation; + private Animation _hideBottomContainerAnimation; + + public FirstScreenApp(Application application) + { + _application = application; + _application.Initialized += OnInitialize; + } + + public static void Run() + { + FirstScreenApp tVApp = new FirstScreenApp(Application.NewApplication()); + tVApp.MainLoop(); + } + + public void MainLoop() + { + _application.MainLoop(); + } + + // Create Items for Poster ScrollContainer + private void CreatePosters() + { + for (int j = 0; j < _totalPostersContainers; j++) + { + View posterContainer = _postersContainer[j].Container; + for (int i = 0; i < Constants.PostersItemsCount; i++) + { + if (j % _totalPostersContainers == 0) + { + View item = new ImageView(_imagePath + "/poster"+j+"/"+ (i % 6)+ ".jpg"); + item.SetName ("poster-item-" + _postersContainer[j].ItemCount); + _postersContainer[j].AddItem(item); + } + else + { + View item = new ImageView(_imagePath + "/poster"+j+"/"+ (i % 6)+ ".jpg"); + item.SetName ("poster-item-" + _postersContainer[j].ItemCount); + _postersContainer[j].AddItem(item); + } + } + + if (j == 0) + { + _postersContainer[j].Show(); + } + else + { + _postersContainer[j].Hide(); + } + + _postersContainer[j].SetFocused(false); + } + + _currentPostersContainerID = 0; + } + + // Create Items for Menu ScrollContainer + private void CreateMenu() + { + View menuContainer = _menuContainer.Container; + menuContainer.Position = new Vector3(Constants.LauncherWidth, 0.0f, 0.0f); + + for(int i = 0; i < Constants.MenuItemsCount; i++) + { + View menuItem = new ImageView(_imagePath + "/menu/" + i % 7 + ".png"); + menuItem.SetName("menu-item-" + _menuContainer.ItemCount); + _menuContainer.AddItem(menuItem); + } + } + + private Actor OnKeyboardPreFocusChangeSignal(object source, KeyboardFocusManager.PreFocusChangeEventArgs e) + { + Actor actor = _menuContainer.ItemRoot; + + if (e.Direction == View.KeyboardFocus.Direction.UP) + { + // Move the Focus to Poster ScrollContainer and hide Bottom Container (Menu ScrollContainer) + if (_menuContainer.IsFocused) + { + actor = _postersContainer[_currentPostersContainerID].GetCurrentFocusedActor(); + _menuContainer.SetFocused(false); + _postersContainer[_currentPostersContainerID].SetFocused(true); + HideBottomContainer(); + + // Also apply Focus animation on Focused item on Poster ScrollContainer + _postersContainer[_currentPostersContainerID].FocusAnimation(_focusEffect, FocusEffectDirection.BottomToTop); + } + } + else if (e.Direction == View.KeyboardFocus.Direction.DOWN) + { + // Show Bottom Container (Menu ScrollContainer) and move the Focus to it + if (!_menuContainer.IsFocused) + { + ShowBottomContainer(); + actor = _menuContainer.GetCurrentFocusedActor(); + _postersContainer[_currentPostersContainerID].SetFocused(false); + _menuContainer.SetFocused(true); + + // Also apply Focus animation on Focused item on Menu ScrollContainer + _menuContainer.FocusAnimation(_focusEffect, FocusEffectDirection.TopToBottom); + } + } + else if (e.Direction == View.KeyboardFocus.Direction.LEFT) + { + if (_menuContainer.IsFocused) + { + // Move the Focus to the left item/image of currently focused item on Menu ScrollContainer + actor = _menuContainer.FocusPrevious(); + + int id = _menuContainer.FocusedItemID % _totalPostersContainers; + if (id != _currentPostersContainerID) + { + _postersContainer[_currentPostersContainerID].Hide(); + _currentPostersContainerID = id; + + _postersContainer[_currentPostersContainerID].Show(); + } + } + else + { + // Move the Focus to the left item/image of currently focused item on Poster ScrollContainer + actor = _postersContainer[_currentPostersContainerID].FocusPrevious(); + } + } + else if (e.Direction == View.KeyboardFocus.Direction.RIGHT) + { + if (_menuContainer.IsFocused) + { + // Move the Focus to the right item/image of currently focused item on Menu ScrollContainer + actor = _menuContainer.FocusNext(); + + int id = _menuContainer.FocusedItemID % _totalPostersContainers; + if (id != _currentPostersContainerID) + { + _postersContainer[_currentPostersContainerID].Hide(); + _currentPostersContainerID = id; + _postersContainer[_currentPostersContainerID].Show(); + } + } + else + { + // Move the Focus to the right item/image of currently focused item on Poster ScrollContainer + actor = _postersContainer[_currentPostersContainerID].FocusNext(); + } + } + + return actor; + } + + // Hide Bottom Container (Menu ScrollContainer) when it is not focused + private void HideBottomContainer() + { + _topClipLayer.ClippingBox = new RectInteger(0, + Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor), + Convert.ToInt32((_stageSize.width)), + Convert.ToInt32((_stageSize.height * Constants.TopClipLayerExpandHeightFactor))); // X, Y, Width, Height + + _hideBottomContainerAnimation.AnimateTo(new Property(_bottomContainer, Actor.Property.POSITION), + new Property.Value(new Vector3(0.0f, _stageSize.height * Constants.BottomContainerHidePositionFactor, 0.0f)), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + _hideBottomContainerAnimation.Play(); + } + + // Show (unhide) Bottom Container (Menu ScrollContainer) when it is focused + private void ShowBottomContainer() + { + _topClipLayer.ClippingBox = new RectInteger(0, + Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor), + Convert.ToInt32((_stageSize.width)), + Convert.ToInt32((_stageSize.height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height + + _showBottomContainerAnimation.AnimateTo(new Property(_bottomContainer, Actor.Property.POSITION), + new Property.Value(new Vector3(0.0f, _stageSize.height * Constants.BottomContainerShowPositionFactor, 0.0f)), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + _showBottomContainerAnimation.Play(); + } + + // First screen demo Application initialisation + private void OnInitialize(object source, AUIApplicationInitEventArgs e) + { + _stage = Stage.GetCurrent(); + _stageSize = _stage.GetSize(); +// _stage.SetBackgroundColor(NDalic.TRANSPARENT); + + _totalPostersContainers = Constants.TotalPostersContainers; + _imagePath = "./images/"; // Desktop +// _imagePath = "/home/owner/apps_rw/org.tizen.firstscreen/res/images/"; // Target + + _postersContainer = new List (); + _menuContainer = new ScrollContainer (); + + _hideBottomContainerAnimation = new Animation(0.25f); + _showBottomContainerAnimation = new Animation(0.25f); + + // Create a Top Container for poster items + _topContainer = new View(); + _topContainer.Size = new Vector3(_stageSize.width, _stageSize.height * Constants.TopContainerHeightFactor, 0.0f); + _topContainer.Position = new Vector3(0.0f, _stageSize.y * Constants.TopContainerPositionFactor, 0.0f); + _topContainer.ParentOrigin = NDalic.ParentOriginTopLeft; + _topContainer.AnchorPoint = NDalic.AnchorPointTopLeft; + + // Add a background to Top container + Property.Map visual = new Property.Map(); + visual.Insert(NDalic.VISUAL_PROPERTY_TYPE, new Property.Value((int)VisualType.IMAGE)); + visual.Insert(NDalic.IMAGE_VISUAL_URL, new Property.Value(_imagePath + "/background.png")); + _topContainer.Background = visual; + _topContainer.Name = "TopControl"; + + // Create a Bottom Container + _bottomContainer = new View(); + _bottomContainer.Size = new Vector3(_stageSize.width, _stageSize.height * Constants.BottomContainerHeightFactor, 0.0f); + _bottomContainer.Position = new Vector3(0.0f, _stageSize.height * Constants.BottomContainerHidePositionFactor, 0.0f); + _bottomContainer.ParentOrigin = NDalic.ParentOriginTopLeft; + _bottomContainer.AnchorPoint = NDalic.AnchorPointTopLeft; + + // Add a background to Bottom Container + visual = new Property.Map(); + visual.Insert(NDalic.VISUAL_PROPERTY_TYPE, new Property.Value((int)VisualType.IMAGE)); + visual.Insert(NDalic.IMAGE_VISUAL_URL, new Property.Value(_imagePath + "/background.png")); + _bottomContainer.Background = visual; + _bottomContainer.Name = "BottomControl"; + + // Add both Top and Bottom Containers to Stage + _stage.Add(_topContainer); + _stage.Add(_bottomContainer); + + // Add a clip layer to Top Container + _topClipLayer = new Layer(); + _topClipLayer.AnchorPoint = NDalic.AnchorPointBottomCenter; + _topClipLayer.ParentOrigin = NDalic.ParentOriginBottomCenter; + _topClipLayer.ClippingEnable = true; + _topClipLayer.ClippingBox = new RectInteger(0, + Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor), + Convert.ToInt32((_stageSize.width)), + Convert.ToInt32((_stageSize.height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height + _topContainer.Add(_topClipLayer); + + // Create a SpotLight for items / images of both Poster and Menu ScrollContainers + ImageView spotLight = new ImageView(_imagePath + "/highlight_spot.png"); + spotLight.WidthResizePolicy = "USE_NATURAL_SIZE"; + spotLight.HeightResizePolicy = "USE_NATURAL_SIZE"; + spotLight.ParentOrigin = NDalic.ParentOriginCenter; + spotLight.AnchorPoint = NDalic.AnchorPointCenter; + spotLight.Name = "spotLight"; + + // Create a shadowBorder for items / images of Poster ScrollContainers + ImageView shadowBorder = new ImageView(_imagePath + "/thumbnail_shadow.9.png"); + shadowBorder.ParentOrigin = NDalic.ParentOriginCenter; + shadowBorder.AnchorPoint = NDalic.AnchorPointCenter; + shadowBorder.WidthResizePolicy = "SIZE_FIXED_OFFSET_FROM_PARENT"; + shadowBorder.HeightResizePolicy = "SIZE_FIXED_OFFSET_FROM_PARENT"; + shadowBorder.SetSizeModeFactor(new Vector3(32.0f, 41.0f, 0.0f)); + shadowBorder.Name = "poster shadowBorder"; + + // Create Poster Containers and add them to Top Clip layer + for (int i = 0; i < _totalPostersContainers; i++) + { + _postersContainer.Add(new ScrollContainer()); + _postersContainer[i].Container.Name = "poster" + i; + if (i == 0) + { + _postersContainer[i].ItemSize = new Vector3((_stageSize.width * Constants.Poster0ItemWidthFactor) - Constants.PostersContainerPadding, + _stageSize.height * Constants.PostersItemHeightFactor, 0.0f); + } + else + { + _postersContainer[i].ItemSize = new Vector3(_stageSize.width * Constants.Poster1ItemWidthFactor, + _stageSize.height * Constants.PostersItemHeightFactor, 0.0f); + } + _postersContainer[i].Padding = Constants.PostersContainerPadding; + _postersContainer[i].MarginX = Constants.PostersContainerMargin; + _postersContainer[i].OffsetY = Constants.PostersContainerOffsetYFactor; + _postersContainer[i].Width = _stageSize.width; + _postersContainer[i].Height = _stageSize.height * Constants.PostersContainerHeightFactor; + _postersContainer[i].ShadowBorder = shadowBorder; + _postersContainer[i].ShadowBorder.Position = new Vector3(0.0f, 4.0f, 0.0f); + _postersContainer[i].SpotLight = spotLight; + _topClipLayer.Add(_postersContainer[i].Container); + } + + // Add a clip layer to Bottom Container + _bottomClipLayer = new Layer(); + _bottomClipLayer.AnchorPoint = NDalic.AnchorPointBottomCenter; + _bottomClipLayer.ParentOrigin = NDalic.ParentOriginBottomCenter; + _bottomClipLayer.ClippingEnable = true; + _bottomClipLayer.ClippingBox = new RectInteger(Convert.ToInt32(Constants.LauncherWidth), + Convert.ToInt32(_stageSize.height * Constants.BottomContainerShowPositionFactor), + Convert.ToInt32((_stageSize.width)), + Convert.ToInt32((_stageSize.height - (_stageSize.height * Constants.BottomClipLayerHeightFactor)))); // X, Y, Width, Height + _bottomContainer.Add(_bottomClipLayer); + + // Add Launcher items to Bottom Container. Launcher is used to display three images on left of Menu ScrollContainer + launcherIcon = new ImageView[Convert.ToInt32(Constants.LauncherItemsCount)]; + for (int launcherIndex = 0; launcherIndex < Constants.LauncherItemsCount; launcherIndex++) + { + launcherIcon[launcherIndex] = new ImageView(_imagePath + "/" + launcherIndex + "-normal.png"); + launcherIcon[launcherIndex].Name = "launcherIcon" + launcherIndex; + launcherIcon[launcherIndex].WidthResizePolicy = "USE_NATURAL_SIZE"; + launcherIcon[launcherIndex].HeightResizePolicy = "USE_NATURAL_SIZE"; + launcherIcon[launcherIndex].ParentOrigin = NDalic.ParentOriginCenterLeft; + launcherIcon[launcherIndex].AnchorPoint = NDalic.AnchorPointCenterLeft; + launcherIcon[launcherIndex].Position = new Vector3(Constants.LauncherIconWidth * launcherIndex + Constants.LauncherLeftMargin, 0.0f, 0.0f); + _bottomContainer.Add(launcherIcon[launcherIndex]); + } + + // Add a shadow seperator image between last Launcher icon and Menu ScrollContainer + _launcherSeparator = new ImageView(_imagePath + "/focus_launcher_shadow_n.png"); + _launcherSeparator.Name = "launcherSeparator"; + _launcherSeparator.WidthResizePolicy = "USE_NATURAL_SIZE"; + _launcherSeparator.HeightResizePolicy = "FILL_TO_PARENT"; + _launcherSeparator.ParentOrigin = NDalic.ParentOriginCenterLeft; + _launcherSeparator.AnchorPoint = NDalic.AnchorPointCenterLeft; + _launcherSeparator.Position = new Vector3(Constants.LauncherIconWidth * Constants.LauncherItemsCount + Constants.LauncherLeftMargin, 0.0f, 0.0f); + _bottomContainer.Add(_launcherSeparator); + + // Create Menu Container and add it to Bottom Clip Layer + _menuItemSize = new Vector3((_stageSize.width * Constants.MenuItemWidthFactor) - Constants.MenuContainerPadding, + _stageSize.height * Constants.MenuItemHeightFactor, 0.0f); + _menuContainer.Container.Name = "menu"; + _menuContainer.ItemSize = _menuItemSize; + _menuContainer.Padding = Constants.MenuContainerPadding; + _menuContainer.MarginX = Constants.MenuContainerMargin; + _menuContainer.OffsetY = Constants.MenuContainerOffsetYFactor; + _menuContainer.OffsetX = Constants.LauncherWidth; + _menuContainer.Width = _stageSize.width - Constants.LauncherWidth; + _menuContainer.Height = _stageSize.height * Constants.MenuContainerHeightFactor; + _menuContainer.ShadowBorder = new ImageView(_imagePath + "/focus_launcher_shadow.9.png"); + _menuContainer.ShadowBorder.Name = "_menuContainer.ShadowBorder"; + _menuContainer.ShadowBorder.Size = new Vector3(_menuContainer.ItemSize.width + 40.0f, _menuContainer.ItemSize.height + 50.0f, 0.0f); + _menuContainer.ShadowBorder.Position = new Vector3(0.0f, 5.0f, 0.0f); + _menuContainer.ShadowBorder.ParentOrigin = NDalic.ParentOriginCenter; + _menuContainer.ShadowBorder.AnchorPoint = NDalic.AnchorPointCenter; + _menuContainer.SpotLight = spotLight; + _bottomClipLayer.Add(_menuContainer.Container); + + CreatePosters(); // Create Items for Poster ScrollContainer + CreateMenu(); // Create Items for Menu ScrollContainer + + // Initialize PreFocusChange event of KeyboardFocusManager + KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.Get(); + keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChangeSignal; + + _keyboardFocusIndicator = new ImageView(_imagePath + "/highlight_stroke.9.png"); + _keyboardFocusIndicator.ParentOrigin = NDalic.ParentOriginCenter; + _keyboardFocusIndicator.AnchorPoint = NDalic.AnchorPointCenter; + _keyboardFocusIndicator.WidthResizePolicy = "FILL_TO_PARENT"; + _keyboardFocusIndicator.HeightResizePolicy = "FILL_TO_PARENT"; + + keyboardFocusManager.SetFocusIndicatorActor(_keyboardFocusIndicator); + + _focusEffect = new FocusEffect(); + + // Move Fcous to Bottom Container (Menu ScrollContainer) + ShowBottomContainer(); + _menuContainer.SetFocused(true); + } + } +} + diff --git a/plugins/dali-swig/examples/firstscreen/Constants.cs b/plugins/dali-swig/examples/firstscreen/Constants.cs new file mode 100644 index 0000000..7ada417 --- /dev/null +++ b/plugins/dali-swig/examples/firstscreen/Constants.cs @@ -0,0 +1,43 @@ +using System; + +namespace FirstScreen +{ + public class Constants + { + public const int TotalPostersContainers = 2; // Number of Poster ScrollContainers to be added on Top Container + + public const float TopContainerHeightFactor = 0.38f; // Height Factor of stage height used for Top Container total height + public const float TopContainerPositionFactor = 0.50f; // Position Factor of stage height used for Top Container position + public const float TopClipLayerHeightFactor = 0.34f; // Height Factor of stage height used for Top Clip layer height + public const float TopClipLayerExpandHeightFactor = 0.36f; // Expanded Height Factor of stage height used for Top Clip layer height (used when Bottom container is hidden) + public const float PostersContainerHeightFactor = 0.32f; // Height Factor of stage height used for Poster ScrollContainers + public const float PostersContainerPadding = 2.0f; // Padding size used between items / images in Poster ScrollContainer + public const float PostersContainerMargin = 60.0f; // Extra margin Padding size used between items / images in Poster ScrollContainer when item / image is focused + public const float PostersContainerOffsetYFactor = 0.17f; // Position Factor of Poster item height used for Poster items / images position + + public const float BottomContainerHeightFactor = 0.16f; // Height Factor of stage height used for Bottom Container total height + public const float BottomContainerHidePositionFactor = 0.88f; // Position Factor of stage height used for Bottom Container position when bottom container is hidden (not focused) + public const float BottomContainerShowPositionFactor = 0.84f; // Position Factor of stage height used for Bottom Container position when bottom container is not hidden (focused) + public const float MenuContainerHeightFactor = 0.16f; // Height Factor of stage height used for Bottom ScrollContainers + public const float BottomClipLayerHeightFactor = 0.84f; // Height Factor of stage height used for Bottom Clip layer height + public const float MenuContainerPadding = 10.0f; // Padding size used between items / images in Menu ScrollContainer + public const float MenuContainerMargin = 25.0f; // Extra margin Padding size used between items / images in Menu ScrollContainer when item / image is focused + public const float MenuContainerOffsetYFactor = 0.35f; // Position Factor of Poster item height used for Menu items / images position + + public const float MenuItemWidthFactor = 0.125f; // Width Factor (1/8) of stage Width used for Menu items / images Width + public const float MenuItemHeightFactor = 0.10f; // Height Factor of stage height used for Menu items / images Height + public const float MenuItemsCount = 14; // Number of Menu items / images used in a Menu ScrollContainer + + public const float Poster0ItemWidthFactor = 0.25f; // Width Factor (1/4) of stage Width used for Poster items / images Width in a Poster ScrollContainer 0 + public const float Poster1ItemWidthFactor = 0.24f; // Width Factor of stage Width used for Poster items / images Width in a Poster ScrollContainer 1 + public const float PostersItemHeightFactor = 0.24f; // Height Factor of stage height used for Poster items / images Height + public const float PostersItemsCount = 24; // Number of Menu items / images used in a Poster ScrollContainer + + public const float LauncherWidth = 280.0f; // Width of Launcher. Launcher is used to display three images on left of Menu ScrollContainer + public const float LauncherLeftMargin = 40.0f; // Extra Spaces to the left of first Launcher item / image + public const float LauncherSeparatorWidth = 20.0f; // Extra area / space to the left of Menu ScrollContainer used for a speration shadow image + public const float LauncherItemsCount = 3.0f; // Total number of Launcher items / images + public const float LauncherIconWidth = (LauncherWidth - LauncherLeftMargin - LauncherSeparatorWidth) / LauncherItemsCount; // Width of each Launcher item / image + } +} + diff --git a/plugins/dali-swig/examples/firstscreen/FocusData.cs b/plugins/dali-swig/examples/firstscreen/FocusData.cs new file mode 100644 index 0000000..b1ee188 --- /dev/null +++ b/plugins/dali-swig/examples/firstscreen/FocusData.cs @@ -0,0 +1,106 @@ +using Dali; +using System; + +namespace FirstScreen +{ + public class FocusData + { + private string _name; // Name used for FocusData object (mainly to differentiate key frame animation ) + private string _imageName; // Image File Name (to be loaded from disk) used for ImageView used in key frame animation + private Vector3 _parentOrigin; // ParentOrigin applied to ImageView + private Vector3 _initSize; // InitSize used for key frame animation + private Vector3 _targetSize; // TargetSize used for key frame animation + private float _keyFrameStart; // KeyFrameStart used for key frame animation + private float _keyFrameEnd; // KeyFrameEnd used for key frame animation + private Direction _direction; // Direction used for key frame animation + private ImageView _imageFocus; // ImageView used in key frame animation + + // Initialize FocusData used for key frame animation + public FocusData(string name, string imageName, Direction direction, Vector3 parentOrigin, Vector3 initSize, + Vector3 targetSize, float keyFrameStart, float keyFrameEnd) + { + _name = name; + _imageName = imageName; + _parentOrigin = parentOrigin; + _initSize = initSize; + _targetSize = targetSize; + _keyFrameStart = keyFrameStart; + _keyFrameEnd = keyFrameEnd; + _direction = direction; + + _imageFocus = new ImageView("./images/focuseffect/" + _imageName); // Desktop +// _imageFocus = new ImageView("/home/owner/apps_rw/org.tizen.firstscreen/res/images/focuseffect/" + _imageName); // Target + + _imageFocus.ParentOrigin = _parentOrigin; + _imageFocus.AnchorPoint = NDalic.AnchorPointCenter; + _imageFocus.Name = _name; + } + + public enum Direction + { + Horizontal, + Vertical + }; + + public Direction FocusDirection + { + get {return _direction;} + set {_direction = value;} + } + + public string Name + { + get {return _name;} + set {_name = value;} + } + + public string ImageName + { + get {return _imageName;} + set {_imageName = value;} + } + + public Vector3 ParentOrigin + { + get + { + return _parentOrigin; + } + set + { + _parentOrigin = value; + _imageFocus.ParentOrigin = _parentOrigin; + } + } + + public Vector3 InitSize + { + get {return _initSize;} + set {_initSize = value;} + } + + public Vector3 TargetSize + { + get {return _targetSize;} + set {_targetSize = value;} + } + + public float KeyFrameStart + { + get {return _keyFrameStart;} + set {_keyFrameStart = value;} + } + + public float KeyFrameEnd + { + get {return _keyFrameEnd;} + set {_keyFrameEnd = value;} + } + + public ImageView ImageItem + { + get {return _imageFocus;} + } + } +} + diff --git a/plugins/dali-swig/examples/firstscreen/FocusEffect.cs b/plugins/dali-swig/examples/firstscreen/FocusEffect.cs new file mode 100644 index 0000000..d02e483 --- /dev/null +++ b/plugins/dali-swig/examples/firstscreen/FocusEffect.cs @@ -0,0 +1,203 @@ +using Dali; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; + +namespace FirstScreen +{ + public class FocusEffect : IFocusEffect + { + private float _frameThickness; + private FocusData[] _focusData; // Each FocusData is used for one key frame animation (total 6 key frame animations needed for EddenEffect) + private Animation _animation; // Animation used to apply all six key frame animations + + public FocusEffect() + { + _frameThickness = 10.0f; + float _bottomFrameTime = 0.6f; // complete the halo/bottom animation 60% of the way through + float _sideFrameTime = 0.8f; // Start the side frame animation after the bottom animation and complete at 80% of the way through + float _topFrameTime = 1.0f; // start the top frame animation after the side frame animation and complete at 100% way through + + // Six key frame animations (FocusData objects) needed for EddenEffect + // Two key frame animations for top horizontal effect + // Two key frame animations for bottom horizontal effect + // Two key frame animations for vertical horizontal effect + _focusData = new FocusData[6]; + + FocusData focusData = new FocusData("halo", "halo.png", FocusData.Direction.Horizontal, NDalic.ParentOriginTopCenter, + new Vector3(50,20,0), new Vector3(0.0f, 100.0f , 0.0f), 0.0f, _bottomFrameTime); + _focusData[0] = focusData; + + focusData = new FocusData("bottom", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginTopCenter, + new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), 0.0f, _bottomFrameTime); + _focusData[1] = focusData; + + focusData = new FocusData("left", "verticalFrame.png", FocusData.Direction.Vertical, NDalic.ParentOriginBottomLeft, + new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime); + _focusData[2] = focusData; + + focusData = new FocusData("right", "verticalFrame.png", FocusData.Direction.Vertical, NDalic.ParentOriginBottomRight, + new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime); + _focusData[3] = focusData; + + focusData = new FocusData("top-left", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginBottomLeft, + new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f ,_frameThickness, 0.0f), _sideFrameTime, _topFrameTime); + _focusData[4] = focusData; + + focusData = new FocusData("top-right", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginBottomRight, + new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), _sideFrameTime, _topFrameTime); + _focusData[5] = focusData; + } + + public void FocusAnimation(View parentItem, Vector3 itemSize, float duration, FocusEffectDirection direction) + { + var itemWidth = itemSize.x + _frameThickness / 2; + var itemHeight = itemSize.y + _frameThickness / 3; + + if (_animation) + { + _animation.Clear(); + _animation.Reset(); + } + _animation = new Animation(duration); + + if (direction == FocusEffectDirection.BottomToTop) + { + _focusData[0].ParentOrigin = NDalic.ParentOriginBottomCenter; + _focusData[1].ParentOrigin = NDalic.ParentOriginBottomCenter; + _focusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft; + _focusData[3].ParentOrigin = NDalic.ParentOriginBottomRight; + _focusData[4].ParentOrigin = NDalic.ParentOriginTopLeft; + _focusData[5].ParentOrigin = NDalic.ParentOriginTopRight; + } + else + { + _focusData[0].ParentOrigin = NDalic.ParentOriginTopCenter; + _focusData[1].ParentOrigin = NDalic.ParentOriginTopCenter; + _focusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft; + _focusData[3].ParentOrigin = NDalic.ParentOriginBottomRight; + _focusData[4].ParentOrigin = NDalic.ParentOriginBottomLeft; + _focusData[5].ParentOrigin = NDalic.ParentOriginBottomRight; + } + + foreach (FocusData focusData in _focusData) + { + var currentParent = focusData.ImageItem.GetParent(); + + // first parent the controls + if (parentItem != currentParent) + { + parentItem.Add(focusData.ImageItem); + } + + focusData.ImageItem.Size = new Vector3(100.0f,100.0f, 0.0f); + parentItem.Add(focusData.ImageItem); + + Vector3 targetSize = focusData.TargetSize; + Vector3 initSize = focusData.InitSize; + + if (focusData.FocusDirection == FocusData.Direction.Horizontal) + { + // adjust the width to match the parent + targetSize.x = itemWidth; + } + else // vertical frame + { + // adjust the height to match the parent + targetSize.y = itemHeight; + } + + // half the size for the top frame as we come out from both left / right sides + if (focusData.Name == "top-right" || focusData.Name == "top-left") + { + targetSize.x = itemWidth - _frameThickness; + } + + KeyFrames keyFrames = new KeyFrames(); + + keyFrames.Add(0.0f, new Property.Value(initSize)); + keyFrames.Add(focusData.KeyFrameStart, new Property.Value(initSize)); + keyFrames.Add(focusData.KeyFrameEnd, new Property.Value(targetSize)); + + // for halo add an extra keyframe to shrink it ( in 20% of time after it has finished) + if (focusData.Name =="halo") + { + keyFrames.Add(focusData.KeyFrameEnd + 0.2f, new Property.Value(initSize)); + } + + _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.SIZE), keyFrames, + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + + // Simulate the vertical frame growing from the top. + // Vertical items are anchored to the bottom of the parent... so when they grow + // we need to move them to the middle of the parent ( otherwise they stick out the bottom) + if (focusData.FocusDirection == FocusData.Direction.Vertical) + { + //animate position as well so it looks like animation is coming from bottom + KeyFrames keyFramesV = new KeyFrames(); + + if (direction == FocusEffectDirection.BottomToTop) + { + keyFramesV.Add(0.0f, new Property.Value(0.0f)); + keyFramesV.Add(focusData.KeyFrameStart, new Property.Value(0.0f)); + } + else + { + keyFramesV.Add(0.0f, new Property.Value(-itemHeight)); + keyFramesV.Add(focusData.KeyFrameStart, new Property.Value(-itemHeight)); + } + + keyFramesV.Add(focusData.KeyFrameEnd, new Property.Value(-itemHeight / 2)); // animate to halfway up the control + + _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_Y), keyFramesV, + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + + // Simulate the top frame growing from the sides. + if (focusData.Name == "top-left") + { + KeyFrames keyFramesTL = new KeyFrames(); + + keyFramesTL.Add(0.0f, new Property.Value(0.0f)); + keyFramesTL.Add(focusData.KeyFrameStart, new Property.Value(0.0f)); + keyFramesTL.Add(focusData.KeyFrameEnd, new Property.Value(itemWidth / 2)); // animate to halfway up the control + + // grow these from the left or right + _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_X), keyFramesTL, + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + + if (focusData.Name == "top-right") + { + KeyFrames keyFramesTR = new KeyFrames(); + + keyFramesTR.Add(0.0f, new Property.Value(0.0f)); + keyFramesTR.Add(focusData.KeyFrameStart, new Property.Value(0.0f)); + keyFramesTR.Add(focusData.KeyFrameEnd, new Property.Value(-itemWidth / 2)); // animate to halfway up the control + + // grow these from the left or right + _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_X), keyFramesTR, + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + + _animation.Finished += OnAnimationFinished; + + _animation.Play(); + } + } + + private void OnAnimationFinished(object source, Animation.FinishedEventArgs e) + { + foreach (FocusData focusData in _focusData) + { + var currentParent = focusData.ImageItem.GetParent(); + + if (currentParent) + { + currentParent.Remove(focusData.ImageItem); + } + } + } + } +} + diff --git a/plugins/dali-swig/examples/firstscreen/IFocusEffect.cs b/plugins/dali-swig/examples/firstscreen/IFocusEffect.cs new file mode 100644 index 0000000..222c2ed --- /dev/null +++ b/plugins/dali-swig/examples/firstscreen/IFocusEffect.cs @@ -0,0 +1,17 @@ +using Dali; +using System; + +namespace FirstScreen +{ + public enum FocusEffectDirection + { + TopToBottom, + BottomToTop + }; + + public interface IFocusEffect + { + void FocusAnimation(View parentItem, Vector3 itemSize, float duration, FocusEffectDirection direction); + } +} + diff --git a/plugins/dali-swig/examples/firstscreen/Program.cs b/plugins/dali-swig/examples/firstscreen/Program.cs new file mode 100644 index 0000000..d33c1f6 --- /dev/null +++ b/plugins/dali-swig/examples/firstscreen/Program.cs @@ -0,0 +1,14 @@ +using System; + +namespace FirstScreen +{ + public class MainClass + { + [STAThread] + static void Main(string[] args) + { + FirstScreenApp.Run(); + } + } +} + diff --git a/plugins/dali-swig/examples/firstscreen/ScrollContainer.cs b/plugins/dali-swig/examples/firstscreen/ScrollContainer.cs new file mode 100644 index 0000000..633af05 --- /dev/null +++ b/plugins/dali-swig/examples/firstscreen/ScrollContainer.cs @@ -0,0 +1,744 @@ +using Dali; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; + + +namespace FirstScreen +{ + public class ScrollContainer + { + private View _container; + private Actor _itemRoot; + private Vector3 _itemSize; + private List _itemList; + private int _itemCount; + private int _focusedItem; + private PanGestureDetector _panGestureDetector; + private float _scrollDisplacement; + private float _currentScrollPosition; + private float _padding; + private float _width; + private float _height; + private bool _isFocused; + private float _marginX; + private float _marginY; + private float _offsetY; + private float _offsetX; + private Stage _stage; + private Vector2 _stageSize; + private ImageView _shadowBorder; + private ImageView _spotLight; + private Animation _spotLightAnimation; + private Animation _showAnimation; + private Animation _hideAnimation; + private Animation _focusAnimation; + private Animation _scrollAnimation; + private Animation _focusTransitionAnimation; + private Path _circularPath; + private bool _shouldHide; + + public ScrollContainer() + { + _itemSize = new Vector3(0.0f, 0.0f, 0.0f); + _padding = 0.0f; + _width = 0.0f; + _height = 0.0f; + _currentScrollPosition = 0.0f; + _itemCount = 0; + _focusedItem = -1; + _isFocused = false; + _marginX = 50.0f; + _marginY = 0.0f; + _offsetY = 0.0f; + _offsetX = 0.0f; + + _shouldHide = true; + + _container = new View(); + _itemRoot = new Actor(); + _container.Add(_itemRoot); + + _itemList = new List(); + + if (_panGestureDetector == null) + { + _panGestureDetector = new PanGestureDetector(); + _panGestureDetector.Attach(_container); + + _panGestureDetector.Detected += OnPan; + } + + _container.ParentOrigin = NDalic.ParentOriginTopLeft; + _container.AnchorPoint = NDalic.AnchorPointTopLeft; + _itemRoot.ParentOrigin = NDalic.ParentOriginTopLeft; + _itemRoot.AnchorPoint = NDalic.AnchorPointTopLeft; + + _container.WidthResizePolicy = "FILL_TO_PARENT"; + _container.HeightResizePolicy = "FILL_TO_PARENT"; + _itemRoot.WidthResizePolicy = "FILL_TO_PARENT"; + _itemRoot.HeightResizePolicy = "FILL_TO_PARENT"; + + _stage = Stage.GetCurrent(); + _stageSize = _stage.GetSize(); + + _spotLightAnimation = new Animation(5.0f); + _focusTransitionAnimation = new Animation (0.35f); + _focusAnimation = new Animation (0.35f); + _focusAnimation.SetEndAction(Animation.EndAction.BakeFinal); + _scrollAnimation = new Animation (0.35f); + _scrollAnimation.SetEndAction(Animation.EndAction.BakeFinal); + } + + public bool IsFocused + { + get + { + return _isFocused; + } + } + + public Dali.View Container + { + get + { + return _container; + } + } + + public int ItemCount + { + get + { + return _itemCount; + } + } + + public Actor ItemRoot + { + get + { + return _itemRoot; + } + } + + public Vector3 ItemSize + { + get + { + return _itemSize; + } + + set + { + _itemSize = value; + + Vector3 topLeft = new Vector3(-0.25f * _itemSize.width, -0.25f * _itemSize.height, 0.0f); + Vector3 topRight = new Vector3(0.25f * _itemSize.width, -0.25f * _itemSize.height, 0.0f); + Vector3 bottomRight = new Vector3(0.25f * _itemSize.width, 0.25f * _itemSize.height, 0.0f); + Vector3 bottomLeft = new Vector3(-0.25f * _itemSize.width, 0.25f * _itemSize.height, 0.0f); + + _circularPath = new Path(); + _circularPath.AddPoint(topLeft); + _circularPath.AddPoint(topRight); + _circularPath.AddPoint(bottomRight); + _circularPath.AddPoint(bottomLeft); + _circularPath.AddPoint(topLeft); + _circularPath.GenerateControlPoints(0.5f); + } + } + + public float Padding + { + get + { + return _padding; + } + + set + { + _padding = value; + } + } + + public float MarginX + { + get + { + return _marginX; + } + + set + { + _marginX = value; + } + } + + public float OffsetY + { + get + { + return _offsetY; + } + + set + { + _offsetY = value; + } + } + + public float OffsetX + { + get + { + return _offsetX; + } + + set + { + _offsetX = value; + } + } + + public float MarginY + { + get + { + return _marginY; + } + + set + { + _marginY = value; + } + } + + public float Width + { + get + { + return _width; + } + + set + { + _width = value; + } + } + + public float Height + { + get + { + return _height; + } + + set + { + _height = value; + } + } + + public ImageView ShadowBorder + { + get + { + return _shadowBorder; + } + + set + { + _shadowBorder = value; + } + } + + public ImageView SpotLight + { + get + { + return _spotLight; + } + + set + { + _spotLight = value; + } + } + + public int FocusedItemID + { + get + { + if (_focusedItem < 0) + { + _focusedItem = 0; + } + + return _focusedItem; + } + } + + public Actor GetCurrentFocusedActor() + { + if (_focusedItem < 0) + { + _focusedItem = 0; + } + + return _itemList[_focusedItem]; + } + + public void AddItem(View item) + { + item.AnchorPoint = NDalic.AnchorPointBottomCenter; + item.ParentOrigin = NDalic.ParentOriginBottomCenter; + + item.Size = _itemSize; + item.SetKeyboardFocusable(true); + item.Position = GetItemPosition(_itemCount, _currentScrollPosition); + + item.Name = _itemCount.ToString(); + +// item.ClippingMode = "CLIP_CHILDREN"; + + _itemRoot.Add(item); + _itemList.Add(item); + _panGestureDetector.Attach(item); + _itemCount++; + } + + // Perform Show animation on ScrollContainer (used only for Poster Container) + public void Show() + { + Container.Add(ItemRoot); + + _shouldHide = false; + _showAnimation = new Animation (0.35f); + + _showAnimation.AnimateTo(new Property(_container, Actor.Property.COLOR_ALPHA), new Property.Value(1.0f)); + + _container.PositionY = _container.Position.y + 200.0f; + float targetPositionY = _container.Position.y - 200.0f; + _showAnimation.AnimateTo(new Property(_container, Actor.Property.POSITION_Y), new Property.Value(targetPositionY), + new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR)); + + _showAnimation.Play(); + } + + // Perform Hide animation on ScrollContainer (used only for Poster Container) + public void Hide() + { + if (_hideAnimation) + { + _hideAnimation.Clear(); + _hideAnimation.Reset(); + } + + float duration = 0.35f; + _hideAnimation = new Animation(duration); + + _hideAnimation.AnimateTo(new Property(_container, Actor.Property.COLOR_ALPHA), new Property.Value(0.0f), + new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.0f, duration * 0.75f)); + + _hideAnimation.Finished += OnHideAnimationFinished; + + _shouldHide = true; + _hideAnimation.Play(); + } + + public View Focus(int itemId) + { + if (itemId < 0) + { + itemId = 0; + } + else if (itemId >= _itemList.Count) + { + itemId = _itemList.Count - 1; + } + + _itemList[itemId].Add(_shadowBorder); + _itemList[itemId].Add(_spotLight); + + // Perform Spot Light animation + if(_focusedItem != itemId && _spotLight != null) + { + _spotLightAnimation.Clear(); + _spotLightAnimation.Animate( _spotLight, _circularPath, new Vector3(0.0f, 0.0f, 0.0f) ); + _spotLightAnimation.SetLooping(true); + _spotLightAnimation.Play(); + } + + _focusedItem = itemId; + + Vector3 itemPosition = GetItemPosition(_focusedItem, _currentScrollPosition); + + _focusAnimation.Clear(); + + float relativeItemPositionX = itemPosition.x - _itemSize.width * 0.5f + (_stageSize.width * 0.5f) + _offsetX; + if (relativeItemPositionX < _marginX + _offsetX + _padding) + { + float amount = _marginX + _offsetX + _padding - relativeItemPositionX; + Scroll(amount, itemId + 1); // Perform Scroll animation + } + else if (relativeItemPositionX + _itemSize.width + _padding + _marginX > _stageSize.width) + { + float amount = relativeItemPositionX + _marginX + _padding + _itemSize.width - _stageSize.width; + Scroll(-amount, itemId - 1); // Perform Scroll animation + } + else + { + for (int i = 0; i < _itemList.Count; ++i) + { + Vector3 targetPosition = GetItemPosition(i, _currentScrollPosition); + _focusAnimation.AnimateTo(new Property(_itemList[i], Actor.Property.POSITION), + new Property.Value(targetPosition), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + } + + for (int i = 0; i < _itemList.Count; ++i) + { + SetupItemRenderer(_itemList[i], false); + + // Perform Focus animation + if (i == _focusedItem) + { + _focusAnimation.AnimateTo(new Property(_itemList[i], Actor.Property.SCALE), + new Property.Value(new Vector3(1.2f, 1.2f, 1.2f)), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + else + { + _focusAnimation.AnimateTo(new Property(_itemList[i], Actor.Property.SCALE), + new Property.Value(new Vector3(1.0f, 1.0f, 1.0f)), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + } + + _focusAnimation.Play(); + + if (_isFocused && _focusedItem >= 0) + { + SetupItemRenderer(_itemList[_focusedItem], true); + SetupSpotLightRenderer(); + } + + return _itemList[_focusedItem]; + } + + // Perform EddenEffect animation on Focused Item specified + public void FocusAnimation(FocusEffect focusEffect, FocusEffectDirection direction) + { + focusEffect.FocusAnimation(_itemList[_focusedItem], _itemSize, 1.0f, direction); + } + + public void SetFocused(bool focused) + { + _isFocused = focused; + + // Perform Focus animation if the ScrollContainer is not focused already + if (!_isFocused) + { + Actor parent = _shadowBorder.GetParent(); + if (parent) + { + parent.Remove(_shadowBorder); + } + + parent = _spotLight.GetParent(); + if (parent) + { + parent.Remove(_spotLight); + } + + _focusTransitionAnimation.Clear(); + + for (int i = 0; i < _itemList.Count; ++i) + { + SetupItemRenderer(_itemList[i], false); + + Vector3 targetPosition = GetItemPosition(i, _currentScrollPosition); + _focusTransitionAnimation.AnimateTo(new Property(_itemList[i], Actor.Property.POSITION), + new Property.Value(targetPosition), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + + _focusTransitionAnimation.AnimateTo(new Property(_itemList[i], Actor.Property.SCALE), + new Property.Value(new Vector3(1.0f, 1.0f, 1.0f)), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + + _focusTransitionAnimation.Play(); + } + else + { + Focus(_focusedItem); + } + } + + // Obtain ID of first visible item/image on the screen of the ScrollContainer + public int GetFirstVisibleItemId() + { + int firstItemId = -1; + + if (_isFocused) + { + firstItemId = (int)Math.Floor((-1.0 * _currentScrollPosition + _marginX * 2.0f) / (_itemSize.x + _padding)); + } + else + { + firstItemId = (int)Math.Floor(-1.0 * _currentScrollPosition / (_itemSize.x + _padding)); + } + + if (firstItemId < 0) + { + firstItemId = 0; + } + + return firstItemId; + } + + // Obtain ID of last visible item/image on the screen of the ScrollContainer + public int GetLastVisibleItemId() + { + int lastItemId = -1; + + if (_isFocused) + { + lastItemId = (int)Math.Ceiling(((_width - _currentScrollPosition - _marginX * 2.0f) / _itemSize.x) - 1); + } + else + { + lastItemId = (int)Math.Ceiling(((_width - _currentScrollPosition) / _itemSize.x) - 1); + } + + if (lastItemId >= _itemList.Count) + { + + lastItemId = _itemList.Count - 1; + } + + return lastItemId; + } + + // Obtain Next item/image (Right of the currently focused item) of the ScrollContainer + public Actor FocusNext() + { + int nextItem = -1; + + if (_focusedItem < GetFirstVisibleItemId() || _focusedItem > GetLastVisibleItemId()) + { + nextItem = GetFirstVisibleItemId(); + } + else + { + nextItem = _focusedItem + 1; + } + + return Focus(nextItem); + } + + // Obtain Previous item/image (left of the currently focused item) of the ScrollContainer + public Actor FocusPrevious() + { + int previousItem = -1; + + if (_focusedItem < GetFirstVisibleItemId() || _focusedItem > GetLastVisibleItemId()) + { + previousItem = GetFirstVisibleItemId(); + } + else + { + previousItem = _focusedItem - 1; + } + + return Focus(previousItem); + } + + private void OnHideAnimationFinished(object source, Animation.FinishedEventArgs e) + { + var currentParent = ItemRoot.GetParent(); + if (_shouldHide && currentParent != null) + { + Container.Remove(ItemRoot); + } + } + + private void OnPan(object source, PanGestureDetector.DetectedEventArgs e) + { + switch (e.PanGesture.state) + { + case Gesture.State.Started: + _scrollDisplacement = 0.0f; + break; + + case Gesture.State.Continuing: + _scrollDisplacement = e.PanGesture.displacement.x; + break; + + case Gesture.State.Finished: + case Gesture.State.Cancelled: + float absScrollDistance = _scrollDisplacement; + if (absScrollDistance < 0.0f) + absScrollDistance = 0.0f - absScrollDistance; + + float scrollSpeed = e.PanGesture.velocity.x * e.PanGesture.velocity.x + e.PanGesture.velocity.y * e.PanGesture.velocity.y; + float maxScrollSpeed = 40.0f; // TBD + if (scrollSpeed > maxScrollSpeed) + scrollSpeed = maxScrollSpeed; + + if (absScrollDistance > 1.0f && scrollSpeed > 0.05f) // Threshold TBD + { + if (_scrollDisplacement > 0.0f) // scroll constant distance in constant speed. + { + Scroll((_itemSize.x + _padding) * 2, GetFirstVisibleItemId()); + } + else + { + Scroll(-(_itemSize.x + _padding) * 2, GetFirstVisibleItemId()); + } + } + break; + } + } + + // Perform ScrollAnimation on each item + private void Scroll(float amount, int baseItem) + { + float tagetScrollPosition = _currentScrollPosition + amount; + float totalItemSize = _itemList.Count * (_itemSize.width + _padding) + _padding + (_marginX * 2.0f); + + float maxScrollPosition = _width - totalItemSize; + + if (tagetScrollPosition < maxScrollPosition) + { + tagetScrollPosition = maxScrollPosition; + } + if (tagetScrollPosition > 0.0f) + { + tagetScrollPosition = 0.0f; + } + + _scrollAnimation.Clear(); + + for (int i = 0; i < _itemList.Count; ++i) + { + Vector3 targetPosition = GetItemPosition(i, tagetScrollPosition); + _scrollAnimation.AnimateTo(new Property(_itemList[i], Actor.Property.POSITION), + new Property.Value(targetPosition), + new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE)); + } + + _currentScrollPosition = tagetScrollPosition; + _scrollAnimation.Play(); + } + + // Calculate Position of any item/image of ScrollContainer + private Vector3 GetItemPosition(int itemId, float scrollPosition) + { + if (_isFocused) + { + // used (_itemSize.width * 0.5f) because of AnchorPointCenter + // used (_stageSize.width * 0.5f) because of ParentOriginCenter + if (_focusedItem > itemId) + { + float positionX = (_itemSize.width * itemId) + (_padding * (itemId + 1)) + scrollPosition + (_itemSize.width * 0.5f) - (_stageSize.width * 0.5f); + return new Vector3(positionX, -_itemSize.height * _offsetY, 0.0f); + } + else if (_focusedItem == itemId) + { + float positionX = (_itemSize.width * itemId) + (_padding * (itemId + 1)) + scrollPosition + _marginX + (_itemSize.width * 0.5f) - (_stageSize.width * 0.5f); + return new Vector3(positionX, -_itemSize.height * _offsetY, 0.0f); + } + else + { + float positionX = (_itemSize.width * itemId) + (_padding * (itemId + 1)) + scrollPosition + _marginX * 2.0f + (_itemSize.width * 0.5f) - (_stageSize.width * 0.5f); + return new Vector3(positionX, -_itemSize.height * _offsetY, 0.0f); + } + } + else + { + float positionX = (_itemSize.width * itemId) + (_padding * (itemId + 1)) + scrollPosition + (_itemSize.width * 0.5f) - (_stageSize.width * 0.5f); + return new Vector3(positionX, -_itemSize.height * _offsetY, 0.0f); + } + } + + // Used for SpotLight animation with clipping + private void SetupItemRenderer(Actor actor, bool stencilOn) + { + if (actor) + { + Renderer renderer = actor.GetRendererAt(0); + + if (renderer) + { + // Setup the renderer properties: + // The stencil plane is only for stencilling, so disable writing to color buffer. + + // Enable stencil. Draw to the stencil buffer (only). + if (stencilOn) + { + renderer.RenderMode = (int)RenderModeType.COLOR_STENCIL; + } + else + { + renderer.RenderMode = (int)RenderModeType.COLOR; + } + renderer.StencilFunction = (int)StencilFunctionType.ALWAYS; + renderer.StencilFunctionReference = 1; + renderer.StencilFunctionMask = 0xFF; + renderer.StencilOperationOnFail = (int)StencilOperationType.KEEP; + renderer.StencilOperationOnZFail = (int)StencilOperationType.KEEP; + renderer.StencilOperationOnZPass = (int)StencilOperationType.REPLACE; + renderer.StencilMask = 0xFF; + + // We don't want to write to the depth buffer. + renderer.DepthWriteMode = (int)DepthWriteModeType.OFF; + // We don't beed to test the depth buffer. + renderer.DepthTestMode = (int)DepthTestModeType.OFF; + + // This object must be rendered 1st. + renderer.DepthIndex = 10; + } + } + } + + // Used for SpotLight animation with clipping + private void SetupSpotLightRenderer() + { + if (_spotLight) + { + Renderer renderer = _spotLight.GetRendererAt(0); + + if (renderer) + { + // Setup the renderer properties: + // Write to color buffer so soptlight is visible + + // We use blending to blend the spotlight with the poster image. + renderer.BlendMode = (int)BlendModeType.ON; + renderer.BlendEquationRgb = (int)BlendEquationType.ADD; + renderer.BlendEquationAlpha = (int)BlendEquationType.ADD; + renderer.BlendFactorDestRgb = (int)BlendFactorType.ONE; + + // Enable stencil. Here we only draw to areas within the stencil. + renderer.RenderMode = (int)RenderModeType.COLOR_STENCIL; + renderer.StencilFunction = (int)StencilFunctionType.EQUAL; + renderer.StencilFunctionReference = 1; + renderer.StencilFunctionMask = 0xFF; + // Don't write to the stencil. + renderer.StencilMask = 0x00; + + // We don't need to write to the depth buffer. + renderer.DepthWriteMode = (int)DepthWriteModeType.OFF; + // We don't need to test the depth buffer. + renderer.DepthTestMode = (int)DepthTestModeType.OFF; + + // This object must be rendered last. + renderer.DepthIndex = 20; + } + } + } + } +} + diff --git a/plugins/dali-swig/examples/firstscreen/images/0-normal.png b/plugins/dali-swig/examples/firstscreen/images/0-normal.png new file mode 100644 index 0000000..ee755c3 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/0-normal.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/1-normal.png b/plugins/dali-swig/examples/firstscreen/images/1-normal.png new file mode 100644 index 0000000..432bf7f Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/1-normal.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/2-normal.png b/plugins/dali-swig/examples/firstscreen/images/2-normal.png new file mode 100644 index 0000000..c921918 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/2-normal.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/background.png b/plugins/dali-swig/examples/firstscreen/images/background.png new file mode 100644 index 0000000..7e4caad Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/background.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/focus_grid.9.png b/plugins/dali-swig/examples/firstscreen/images/focus_grid.9.png new file mode 100644 index 0000000..04ccb1f Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/focus_grid.9.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/focus_launcher_shadow.9.png b/plugins/dali-swig/examples/firstscreen/images/focus_launcher_shadow.9.png new file mode 100644 index 0000000..f989071 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/focus_launcher_shadow.9.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/focus_launcher_shadow_n.png b/plugins/dali-swig/examples/firstscreen/images/focus_launcher_shadow_n.png new file mode 100644 index 0000000..0805e9e Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/focus_launcher_shadow_n.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/focuseffect/halo.png b/plugins/dali-swig/examples/firstscreen/images/focuseffect/halo.png new file mode 100644 index 0000000..307f67e Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/focuseffect/halo.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/focuseffect/horizontalFrame.png b/plugins/dali-swig/examples/firstscreen/images/focuseffect/horizontalFrame.png new file mode 100644 index 0000000..abff4ec Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/focuseffect/horizontalFrame.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/focuseffect/verticalFrame.png b/plugins/dali-swig/examples/firstscreen/images/focuseffect/verticalFrame.png new file mode 100644 index 0000000..bdd372d Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/focuseffect/verticalFrame.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/highlight_spot.png b/plugins/dali-swig/examples/firstscreen/images/highlight_spot.png new file mode 100644 index 0000000..8caa716 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/highlight_spot.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/highlight_stroke.9.png b/plugins/dali-swig/examples/firstscreen/images/highlight_stroke.9.png new file mode 100644 index 0000000..493b206 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/highlight_stroke.9.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/menu/0.png b/plugins/dali-swig/examples/firstscreen/images/menu/0.png new file mode 100644 index 0000000..cf1135c Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/menu/0.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/menu/1.png b/plugins/dali-swig/examples/firstscreen/images/menu/1.png new file mode 100644 index 0000000..16d48e7 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/menu/1.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/menu/2.png b/plugins/dali-swig/examples/firstscreen/images/menu/2.png new file mode 100644 index 0000000..bf7f1e8 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/menu/2.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/menu/3.png b/plugins/dali-swig/examples/firstscreen/images/menu/3.png new file mode 100644 index 0000000..ba40892 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/menu/3.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/menu/4.png b/plugins/dali-swig/examples/firstscreen/images/menu/4.png new file mode 100644 index 0000000..ad580d8 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/menu/4.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/menu/5.png b/plugins/dali-swig/examples/firstscreen/images/menu/5.png new file mode 100644 index 0000000..599147c Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/menu/5.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/menu/6.png b/plugins/dali-swig/examples/firstscreen/images/menu/6.png new file mode 100644 index 0000000..5f215f6 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/menu/6.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/0.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/0.jpg new file mode 100644 index 0000000..5b234db Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/0.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/1.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/1.jpg new file mode 100644 index 0000000..f999f55 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/1.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/10.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/10.jpg new file mode 100644 index 0000000..e8be482 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/10.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/11.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/11.jpg new file mode 100644 index 0000000..2b97815 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/11.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/12.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/12.jpg new file mode 100644 index 0000000..8b7bda9 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/12.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/13.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/13.jpg new file mode 100644 index 0000000..ba8d61a Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/13.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/2.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/2.jpg new file mode 100644 index 0000000..dba62e1 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/2.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/3.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/3.jpg new file mode 100644 index 0000000..bd74752 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/3.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/4.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/4.jpg new file mode 100644 index 0000000..13581f8 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/4.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/5.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/5.jpg new file mode 100644 index 0000000..7526f22 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/5.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/6.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/6.jpg new file mode 100644 index 0000000..3882771 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/6.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/7.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/7.jpg new file mode 100644 index 0000000..7a0844b Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/7.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/8.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/8.jpg new file mode 100644 index 0000000..4798052 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/8.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster0/9.jpg b/plugins/dali-swig/examples/firstscreen/images/poster0/9.jpg new file mode 100644 index 0000000..5f160b3 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster0/9.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster1/0.jpg b/plugins/dali-swig/examples/firstscreen/images/poster1/0.jpg new file mode 100644 index 0000000..1d4b86b Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster1/0.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster1/1.jpg b/plugins/dali-swig/examples/firstscreen/images/poster1/1.jpg new file mode 100644 index 0000000..f95670d Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster1/1.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster1/2.jpg b/plugins/dali-swig/examples/firstscreen/images/poster1/2.jpg new file mode 100644 index 0000000..f4c0246 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster1/2.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster1/3.jpg b/plugins/dali-swig/examples/firstscreen/images/poster1/3.jpg new file mode 100644 index 0000000..49acd6a Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster1/3.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster1/4.jpg b/plugins/dali-swig/examples/firstscreen/images/poster1/4.jpg new file mode 100644 index 0000000..cb11761 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster1/4.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/poster1/5.jpg b/plugins/dali-swig/examples/firstscreen/images/poster1/5.jpg new file mode 100644 index 0000000..eba0c14 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/poster1/5.jpg differ diff --git a/plugins/dali-swig/examples/firstscreen/images/star-dim.png b/plugins/dali-swig/examples/firstscreen/images/star-dim.png new file mode 100644 index 0000000..38cc674 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/star-dim.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/star-highlight.png b/plugins/dali-swig/examples/firstscreen/images/star-highlight.png new file mode 100644 index 0000000..f99ee25 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/star-highlight.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/thumbnail_shadow.9.png b/plugins/dali-swig/examples/firstscreen/images/thumbnail_shadow.9.png new file mode 100644 index 0000000..61f5a99 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/thumbnail_shadow.9.png differ diff --git a/plugins/dali-swig/examples/firstscreen/images/white-pixel.png b/plugins/dali-swig/examples/firstscreen/images/white-pixel.png new file mode 100644 index 0000000..c63f333 Binary files /dev/null and b/plugins/dali-swig/examples/firstscreen/images/white-pixel.png differ diff --git a/plugins/dali-swig/examples/hello-test.cs b/plugins/dali-swig/examples/hello-test.cs old mode 100755 new mode 100644 index 61726aa..1f7962d --- a/plugins/dali-swig/examples/hello-test.cs +++ b/plugins/dali-swig/examples/hello-test.cs @@ -52,6 +52,14 @@ namespace MyCSharpExample { } + public Example(string stylesheet):base(stylesheet) + { + } + + public Example(string stylesheet, Dali.Application.WINDOW_MODE windowMode):base(stylesheet, windowMode) + { + } + private void Initialize() { // Connect the signal callback for stage touched signal @@ -111,7 +119,9 @@ namespace MyCSharpExample static void Main(string[] args) { Console.WriteLine("Hello mono world."); - Example example = new Example(); + //Example example = new Example(); + //Example example = new Example("stylesheet"); + Example example = new Example("stylesheet", Dali.Application.WINDOW_MODE.TRANSPARENT); example.Run(args); } } diff --git a/plugins/dali-swig/examples/hello-world.cs b/plugins/dali-swig/examples/hello-world.cs index 28fd1dd..cd9b72e 100755 --- a/plugins/dali-swig/examples/hello-world.cs +++ b/plugins/dali-swig/examples/hello-world.cs @@ -85,8 +85,9 @@ namespace MyCSharpExample _animation = new Animation(1.0f); // 1 second of duration - _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion( new Radian( new Degree( 180.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.0f, 0.5f)); - _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion( new Radian( new Degree( 0.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.5f, 0.5f)); + _animation.AnimateTo(_text, Animation.ORIENTATION, new Quaternion( new Radian( new Degree( 180.0f ) ), Vector3.XAXIS ), new AlphaFunction(Dali.Constants.AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.0f, 0.5f)); + + _animation.AnimateTo(_text, Animation.ORIENTATION, new Quaternion( new Radian( new Degree( 0.0f ) ), Vector3.XAXIS ), new AlphaFunction(Dali.Constants.AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.5f, 0.5f)); // Connect the signal callback for animaiton finished signal _animation.Finished += AnimationFinished; diff --git a/plugins/dali-swig/examples/scroll-view.cs b/plugins/dali-swig/examples/scroll-view.cs index 9710c0e..93554fc 100644 --- a/plugins/dali-swig/examples/scroll-view.cs +++ b/plugins/dali-swig/examples/scroll-view.cs @@ -21,125 +21,184 @@ using Dali; namespace MyCSharpExample { - class Example - { - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - delegate void CallbackDelegate(IntPtr data); + class Example + { + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + delegate void CallbackDelegate(IntPtr data); - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - delegate void ActorCallbackDelegate(IntPtr data); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + delegate void ActorCallbackDelegate(IntPtr data); - private Dali.Application _application; - private ScrollView _scrollView; - private ScrollBar _scrollBar; + private Dali.Application _application; + private ScrollView _scrollView; + private ScrollBar _scrollBar; + private Animation _animation; + private TextLabel _text; - public Example(Dali.Application application) - { - _application = application; - _application.Initialized += Initialize; - } + public Example(Dali.Application application) + { + _application = application; + _application.Initialized += Initialize; + } - public void Initialize(object source, AUIApplicationInitEventArgs e) - { - CreateScrollView(); - } + public void Initialize(object source, AUIApplicationInitEventArgs e) + { + CreateScrollView(); + } - private void CreateScrollView() + private void CreateScrollView() + { + Stage stage = Stage.GetCurrent(); + stage.BackgroundColor = NDalic.WHITE; + + // Create a scroll view + _scrollView = new ScrollView(); + Vector2 stageSize = stage.Size; + _scrollView.Size = new Vector3(stageSize.x, stageSize.y, 0.0f); + _scrollView.ParentOrigin = NDalic.ParentOriginCenter; + _scrollView.AnchorPoint = NDalic.AnchorPointCenter; + stage.Add(_scrollView); + + // Add actors to a scroll view with 3 pages + int pageRows = 1; + int pageColumns = 3; + for(int pageRow = 0; pageRow < pageRows; pageRow++) + { + for(int pageColumn = 0; pageColumn < pageColumns; pageColumn++) { - Stage stage = Stage.GetCurrent(); - stage.BackgroundColor = NDalic.WHITE; - - // Create a scroll view - _scrollView = new ScrollView(); - Vector2 stageSize = stage.Size; - _scrollView.Size = new Vector3(stageSize.x, stageSize.y, 0.0f); - _scrollView.ParentOrigin = NDalic.ParentOriginCenter; - _scrollView.AnchorPoint = NDalic.AnchorPointCenter; - stage.Add(_scrollView); - - // Add actors to a scroll view with 3 pages - int pageRows = 1; - int pageColumns = 3; - for(int pageRow = 0; pageRow < pageRows; pageRow++) + View pageActor = new View(); + pageActor.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.ALL_DIMENSIONS); + pageActor.ParentOrigin = NDalic.ParentOriginCenter; + pageActor.AnchorPoint = NDalic.AnchorPointCenter; + pageActor.Position = new Vector3(pageColumn * stageSize.x, pageRow * stageSize.y, 0.0f); + + // Add images in a 3x4 grid layout for each page + int imageRows = 4; + int imageColumns = 3; + float margin = 10.0f; + Vector3 imageSize = new Vector3((stageSize.x / imageColumns) - margin, (stageSize.y / imageRows) - margin, 0.0f); + + for(int row = 0; row < imageRows; row++) + { + for(int column = 0; column < imageColumns;column++) { - for(int pageColumn = 0; pageColumn < pageColumns; pageColumn++) - { - View pageActor = new View(); - pageActor.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.ALL_DIMENSIONS); - pageActor.ParentOrigin = NDalic.ParentOriginCenter; - pageActor.AnchorPoint = NDalic.AnchorPointCenter; - pageActor.Position = new Vector3(pageColumn * stageSize.x, pageRow * stageSize.y, 0.0f); - - // Add images in a 3x4 grid layout for each page - int imageRows = 4; - int imageColumns = 3; - float margin = 10.0f; - Vector3 imageSize = new Vector3((stageSize.x / imageColumns) - margin, (stageSize.y / imageRows) - margin, 0.0f); - - for(int row = 0; row < imageRows; row++) - { - for(int column = 0; column < imageColumns;column++) - { - int imageId = (row * imageColumns + column) % 2 + 1; - ImageView imageView = new ImageView("images/image-" + imageId + ".jpg"); - imageView.ParentOrigin = NDalic.ParentOriginCenter; - imageView.AnchorPoint = NDalic.AnchorPointCenter; - imageView.Size = imageSize; - imageView.Position = new Vector3( margin * 0.5f + (imageSize.x + margin) * column - stageSize.x * 0.5f + imageSize.x * 0.5f, - margin * 0.5f + (imageSize.y + margin) * row - stageSize.y * 0.5f + imageSize.y * 0.5f, 0.0f ); - pageActor.Add(imageView); - } - } - - _scrollView.Add(pageActor); - } + int imageId = (row * imageColumns + column) % 2 + 1; + ImageView imageView = new ImageView("images/image-" + imageId + ".jpg"); + imageView.ParentOrigin = NDalic.ParentOriginCenter; + imageView.AnchorPoint = NDalic.AnchorPointCenter; + imageView.Size = imageSize; + imageView.Position = new Vector3( margin * 0.5f + (imageSize.x + margin) * column - stageSize.x * 0.5f + imageSize.x * 0.5f, + margin * 0.5f + (imageSize.y + margin) * row - stageSize.y * 0.5f + imageSize.y * 0.5f, 0.0f ); + pageActor.Add(imageView); } + } - _scrollView.SetAxisAutoLock(true); - - // Set scroll view to have 3 pages in X axis and allow page snapping, - // and also disable scrolling in Y axis. - RulerPtr scrollRulerX = new RulerPtr(new FixedRuler(stageSize.width)); - RulerPtr scrollRulerY = new RulerPtr(new DefaultRuler()); - scrollRulerX.SetDomain(new RulerDomain(0.0f, stageSize.width * pageColumns, true)); - scrollRulerY.Disable(); - _scrollView.SetRulerX(scrollRulerX); - _scrollView.SetRulerY(scrollRulerY); - - // Create a horizontal scroll bar in the bottom of scroll view (which is optional) - _scrollBar = new ScrollBar(); - _scrollBar.ParentOrigin = NDalic.ParentOriginBottomLeft; - _scrollBar.AnchorPoint = NDalic.AnchorPointTopLeft; - _scrollBar.SetResizePolicy(ResizePolicyType.FIT_TO_CHILDREN, DimensionType.WIDTH); - _scrollBar.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT); - _scrollBar.Orientation = new Quaternion( new Radian( new Degree( 270.0f ) ), Vector3.ZAXIS ); - _scrollBar.SetScrollDirection(ScrollBar.Direction.Horizontal); - _scrollView.Add(_scrollBar); - - // Connect to the OnRelayout signal - _scrollView.OnRelayoutEvent += OnScrollViewRelayout; + _scrollView.Add(pageActor); } + } + + _scrollView.SetAxisAutoLock(true); + + // Set scroll view to have 3 pages in X axis and allow page snapping, + // and also disable scrolling in Y axis. + RulerPtr scrollRulerX = new RulerPtr(new FixedRuler(stageSize.width)); + RulerPtr scrollRulerY = new RulerPtr(new DefaultRuler()); + scrollRulerX.SetDomain(new RulerDomain(0.0f, stageSize.width * pageColumns, true)); + scrollRulerY.Disable(); + _scrollView.SetRulerX(scrollRulerX); + _scrollView.SetRulerY(scrollRulerY); + + // Create a horizontal scroll bar in the bottom of scroll view (which is optional) + _scrollBar = new ScrollBar(); + _scrollBar.ParentOrigin = NDalic.ParentOriginBottomLeft; + _scrollBar.AnchorPoint = NDalic.AnchorPointTopLeft; + _scrollBar.SetResizePolicy(ResizePolicyType.FIT_TO_CHILDREN, DimensionType.WIDTH); + _scrollBar.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT); + _scrollBar.Orientation = new Quaternion( new Radian( new Degree( 270.0f ) ), Vector3.ZAXIS ); + _scrollBar.SetScrollDirection(ScrollBar.Direction.Horizontal); + _scrollView.Add(_scrollBar); + + // Connect to the OnRelayout signal + _scrollView.OnRelayoutEvent += OnScrollViewRelayout; + _scrollView.Touched += OnTouch; + _scrollView.WheelMoved += Onwheel; + _scrollView.KeyInputFocusGained += OnKey; + _text = new TextLabel("View Touch Event Handler Test"); + _text.ParentOrigin = NDalic.ParentOriginCenter; + _text.AnchorPoint = NDalic.AnchorPointCenter; + _text.HorizontalAlignment = "CENTER"; + _text.PointSize = 48.0f; + + _scrollView.Add(_text); + } - private void OnScrollViewRelayout(object source, View.OnRelayoutEventArgs e) - { - // Set the correct scroll bar size after size negotiation of scroll view is done - _scrollBar.Size = new Vector3(0.0f, _scrollView.GetRelayoutSize(DimensionType.WIDTH), 0.0f); - } + // Callback for _animation finished signal handling + public void AnimationFinished(object source, Animation.FinishedEventArgs e) + { + Console.WriteLine("Customized Animation Finished Event handler"); + Console.WriteLine("Animation finished: duration = " + e.Animation.Duration); + } + private void OnKey(object source, View.KeyInputFocusGainedEventArgs e) + { + Console.WriteLine("View Keyevent EVENT callback...."); + } - public void MainLoop() - { - _application.MainLoop (); - } + private bool Onwheel(object source, View.WheelEventArgs e) + { + Console.WriteLine("View Wheel EVENT callback...."); + return true; + } - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main(string[] args) + private bool OnTouch(object source, View.TouchEventArgs e) + { + Console.WriteLine("View TOUCH EVENT callback...."); + + // Only animate the _text label when touch down happens + if( e.TouchData.GetState(0) == PointStateType.DOWN ) + { + Console.WriteLine("Customized Stage Touch event handler"); + // Create a new _animation + if( _animation ) { - Example example = new Example(Application.NewApplication()); - example.MainLoop (); + _animation.Reset(); } + + _animation = new Animation(1.0f); // 1 second of duration + + _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion( new Radian( new Degree( 180.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.0f, 0.5f)); + _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion( new Radian( new Degree( 0.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.5f, 0.5f)); + + // Connect the signal callback for animaiton finished signal + _animation.Finished += AnimationFinished; + + // Play the _animation + _animation.Play(); + } + return true; } + + private void OnScrollViewRelayout(object source, View.OnRelayoutEventArgs e) + { + Console.WriteLine("View OnRelayoutEventArgs EVENT callback...."); + + // Set the correct scroll bar size after size negotiation of scroll view is done + _scrollBar.Size = new Vector3(0.0f, _scrollView.GetRelayoutSize(DimensionType.WIDTH), 0.0f); + } + + public void MainLoop() + { + _application.MainLoop (); + } + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main(string[] args) + { + Example example = new Example(Application.NewApplication()); + example.MainLoop (); + } + } } diff --git a/plugins/dali-swig/manual/csharp/DaliEnumConstants.cs b/plugins/dali-swig/manual/csharp/DaliEnumConstants.cs new file mode 100644 index 0000000..e159317 --- /dev/null +++ b/plugins/dali-swig/manual/csharp/DaliEnumConstants.cs @@ -0,0 +1,94 @@ +/** 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. + * + */ +using System; + +namespace Dali { + namespace Constants{ + namespace AlphaFunction { + public enum BuiltinFunction { + Default = Dali.AlphaFunction.BuiltinFunction.DEFAULT, + Linear = Dali.AlphaFunction.BuiltinFunction.LINEAR, + Reverse = Dali.AlphaFunction.BuiltinFunction.REVERSE, + EaseInSquare = Dali.AlphaFunction.BuiltinFunction.EASE_IN_SQUARE, + EaseOutSquare = Dali.AlphaFunction.BuiltinFunction.EASE_OUT_SQUARE, + EaseIn = Dali.AlphaFunction.BuiltinFunction.EASE_IN, + EaseOut = Dali.AlphaFunction.BuiltinFunction.EASE_OUT, + EaseInOut = Dali.AlphaFunction.BuiltinFunction.EASE_IN_OUT, + EaseInSine = Dali.AlphaFunction.BuiltinFunction.EASE_IN_SINE, + EaseOutSine = Dali.AlphaFunction.BuiltinFunction.EASE_OUT_SINE, + EaseInOutSine = Dali.AlphaFunction.BuiltinFunction.EASE_IN_OUT_SINE, + Bounce = Dali.AlphaFunction.BuiltinFunction.BOUNCE, + Sin = Dali.AlphaFunction.BuiltinFunction.SIN, + EaseOutBack = Dali.AlphaFunction.BuiltinFunction.EASE_OUT_BACK, + Count = Dali.AlphaFunction.BuiltinFunction.COUNT + } + + + public enum Mode { + BuiltinFunction = Dali.AlphaFunction.Mode.BUILTIN_FUNCTION, + CustomFunction = Dali.AlphaFunction.Mode.CUSTOM_FUNCTION, + Bezier = Dali.AlphaFunction.Mode.BEZIER + } + + } // namespace AlphaFunction + + namespace FrameBuffer { + namespace Attachment { + public enum Mask { + None = Dali.FrameBuffer.Attachment.Mask.NONE, ///< No attachments are created initially @SINCE_1_1.45 + Depth = Dali.FrameBuffer.Attachment.Mask.DEPTH, ///< Depth buffer bit-mask value @SINCE_1_1.45 + Stencil = Dali.FrameBuffer.Attachment.Mask.STENCIL , ///< Stencil buffer bit-mask value @SINCE_1_1.45 + // Preset bit-mask combinations: + DepthStencil = Dali.FrameBuffer.Attachment.Mask.DEPTH_STENCIL ///< The Framebuffer will be created with depth and stencil buffer @SINCE_1_1.45 + } + } //namespace FrameBuffer + } // namespace Attachment + + + public enum TextureType { + Texture2D = Dali.TextureType.TEXTURE_2D, ///< One 2D image @SINCE_1_1.43 + TextureCube = Dali.TextureType.TEXTURE_CUBE ///< Six 2D images arranged in a cube-shape @SINCE_1_1.43 + } + + /** + * @brief Stereoscopic view modes + * @SINCE_1_0.0 + */ + public enum ViewMode { + Mono = Dali.ViewMode.MONO, ///< Monoscopic (single camera). This is the default @SINCE_1_0.0 + StereoHorizontal = Dali.ViewMode.STEREO_HORIZONTAL, ///< Stereoscopic. Frame buffer is split horizontally with the left and right camera views in their respective sides. @SINCE_1_0.0 + StereoVertical = Dali.ViewMode.STEREO_VERTICAL, ///< Stereoscopic. Frame buffer is split vertically with the left camera view at the top and the right camera view at the bottom. @SINCE_1_0.0 + StereoInterlaced = Dali.ViewMode.STEREO_INTERLACED ///< @DEPRECATED_1_1.19 @brief Stereoscopic. Left/Right camera views are rendered into the framebuffer on alternate frames. @SINCE_1_0.0 + } + + public enum MeshVisualShadingModeValue { + TexturelessWithDiffuseLighting = Dali.MeshVisualShadingModeValue.TEXTURELESS_WITH_DIFFUSE_LIGHTING, ///< *Simplest*. One color that is lit by ambient and diffuse lighting. @SINCE_1_1.45 + TexturedWithSpecularLigting = Dali.MeshVisualShadingModeValue.TEXTURED_WITH_SPECULAR_LIGHTING, ///< Uses only the visual image textures provided with specular lighting in addition to ambient and diffuse lighting. @SINCE_1_1.45 + TexturedWithDetailedSpecularLighting = Dali.MeshVisualShadingModeValue.TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING ///< Uses all textures provided including a gloss, normal and texture map along with specular, ambient and diffuse lighting. @SINCE_1_1.45 + } + + /** + * @brief Projection modes. + * @SINCE_1_0.0 + */ + public enum ProjectionMode { + PerspectiveProjection = Dali.ProjectionMode.PERSPECTIVE_PROJECTION, ///< Distance causes foreshortening; objects further from the camera appear smaller @SINCE_1_0.0 + OrthographicProjection = Dali.ProjectionMode.ORTHOGRAPHIC_PROJECTION ///< Relative distance from the camera does not affect the size of objects @SINCE_1_0.0 + } + + + } // namespace Constants +} // namesapce Dali diff --git a/plugins/dali-swig/manual/csharp/Tizen.Applications/DaliApplication.cs b/plugins/dali-swig/manual/csharp/Tizen.Applications/DaliApplication.cs old mode 100755 new mode 100644 index 06d7756..6791355 --- a/plugins/dali-swig/manual/csharp/Tizen.Applications/DaliApplication.cs +++ b/plugins/dali-swig/manual/csharp/Tizen.Applications/DaliApplication.cs @@ -28,13 +28,61 @@ namespace Tizen.Applications /// This application is created before OnCreate() or created event. And the DaliApplication will be terminated when this application is closed. /// protected Dali.Application application; + + /// + /// The instance of the Dali Application extension. + /// protected Dali.ApplicationExtensions applicationExt; /// + /// Store the stylesheet value. + /// + protected string m_stylesheet; + + /// + /// Store the window mode value. + /// + protected Dali.Application.WINDOW_MODE m_windowMode; + + /// + /// Store the app mode value. + /// + protected APP_MODE appMode; + + /// /// The instance of the Dali Stage. /// public Stage stage { get; private set; } + /// + /// The default constructor. + /// + public DaliApplication():base() + { + appMode = APP_MODE.DEFAULT; + } + + /// + /// The constructor with stylesheet. + /// + public DaliApplication(string stylesheet):base() + { + //handle the stylesheet + appMode = APP_MODE.STYLESHEETONLY; + m_stylesheet = stylesheet; + } + + /// + /// The constructor with stylesheet and window mode. + /// + public DaliApplication(string stylesheet, Dali.Application.WINDOW_MODE windowMode) + : base() + { + //handle the stylesheet and windowMode + appMode = APP_MODE.STYLESHEETWITHWINDOWMODE; + m_stylesheet = stylesheet; + m_windowMode = windowMode; + } /// /// Overrides this method if want to handle behavior before calling OnCreate(). @@ -42,8 +90,22 @@ namespace Tizen.Applications /// protected override void OnPreCreate() { - application = Dali.Application.NewApplication(); - applicationExt = new Dali::ApplicationExtensions(application); + switch(appMode) + { + case APP_MODE.DEFAULT: + application = Dali.Application.NewApplication(); + break; + case APP_MODE.STYLESHEETONLY: + application = Dali.Application.NewApplication(m_stylesheet); + break; + case APP_MODE.STYLESHEETWITHWINDOWMODE: + application = Dali.Application.NewApplication(m_stylesheet, m_windowMode); + break; + default: + break; + } + + applicationExt = new Dali.ApplicationExtensions(application); applicationExt.Init(); stage = Stage.GetCurrent(); @@ -85,5 +147,15 @@ namespace Tizen.Applications base.OnLocaleChanged(e); applicationExt.LanguageChange(); } + + /// + /// The mode of creating Dali application. + /// + protected enum APP_MODE + { + DEFAULT = 0, + STYLESHEETONLY = 1, + STYLESHEETWITHWINDOWMODE = 2 + } } }