diff --git a/build/tizen/CMakeLists.txt b/build/tizen/CMakeLists.txt index 2c4f052..e98c386 100644 --- a/build/tizen/CMakeLists.txt +++ b/build/tizen/CMakeLists.txt @@ -86,7 +86,7 @@ ENDFOREACH(flag) SET(DALI_DEMO_CFLAGS "-DDEMO_IMAGE_DIR=${DEMO_IMAGE_DIR} -DDEMO_MODEL_DIR=${DEMO_MODEL_DIR} -DDEMO_SCRIPT_DIR=${DEMO_SCRIPT_DIR} -DDEMO_THEME_PATH=${DEMO_THEME_PATH} -DDEMO_EXAMPLE_BIN=${DEMO_EXAMPLE_BIN} -DDEMO_LOCALE_DIR=${DEMO_LOCALE_DIR} -fvisibility=hidden -DHIDE_DALI_INTERNALS -DDEMO_LANG=${DEMO_LANG}") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${REQUIRED_CFLAGS} ${DALI_DEMO_CFLAGS} -Werror -Wall") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${REQUIRED_CFLAGS} ${DALI_DEMO_CFLAGS} -Werror -Wall -fPIE") SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") INCLUDE_DIRECTORIES(${ROOT_SRC_DIR}) diff --git a/build/tizen/demo/CMakeLists.txt b/build/tizen/demo/CMakeLists.txt index c5f967a..227bc50 100644 --- a/build/tizen/demo/CMakeLists.txt +++ b/build/tizen/demo/CMakeLists.txt @@ -3,7 +3,7 @@ SET(DEMO_SRC_DIR ${ROOT_SRC_DIR}/demo) AUX_SOURCE_DIRECTORY(${DEMO_SRC_DIR} DEMO_SRCS) ADD_EXECUTABLE(${PROJECT_NAME} ${DEMO_SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_PKGS_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_PKGS_LDFLAGS} -pie) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR}) diff --git a/build/tizen/examples/CMakeLists.txt b/build/tizen/examples/CMakeLists.txt index bab5ba4..7fa03fe 100644 --- a/build/tizen/examples/CMakeLists.txt +++ b/build/tizen/examples/CMakeLists.txt @@ -16,6 +16,6 @@ SUBDIRLIST(SUBDIRS ${EXAMPLES_SRC_DIR}) FOREACH(EXAMPLE ${SUBDIRS}) FILE(GLOB SRCS "${EXAMPLES_SRC_DIR}/${EXAMPLE}/*.cpp") ADD_EXECUTABLE(${EXAMPLE}.example ${SRCS}) - TARGET_LINK_LIBRARIES(${EXAMPLE}.example ${REQUIRED_PKGS_LDFLAGS}) + TARGET_LINK_LIBRARIES(${EXAMPLE}.example ${REQUIRED_PKGS_LDFLAGS} -pie) INSTALL(TARGETS ${EXAMPLE}.example DESTINATION ${BINDIR}) ENDFOREACH(EXAMPLE) diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 41ea452..513717d 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -142,10 +142,16 @@ - + + + + + + + diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index 680ef8d..bfc7d2c 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -24,7 +24,7 @@ using namespace Dali; -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { // Configure gettext for internalization bindtextdomain(DALI_DEMO_DOMAIN_LOCAL, DEMO_LOCALE_DIR); diff --git a/examples/atlas/atlas-example.cpp b/examples/atlas/atlas-example.cpp index 3d46680..3ba64ea 100644 --- a/examples/atlas/atlas-example.cpp +++ b/examples/atlas/atlas-example.cpp @@ -234,7 +234,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { gApplication = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/benchmark/benchmark.cpp b/examples/benchmark/benchmark.cpp index c4e9b83..470f9b9 100644 --- a/examples/benchmark/benchmark.cpp +++ b/examples/benchmark/benchmark.cpp @@ -225,9 +225,10 @@ Renderer CreateRenderer( unsigned int index ) const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; Image image = ResourceImage::New(imagePath); - Material material = Material::New( shader ); - material.AddTexture( image, "sTexture" ); - renderers[index] = Renderer::New( QuadMesh(), material ); + TextureSet textureSet = TextureSet::New(); + textureSet.SetImage( 0u, image ); + renderers[index] = Renderer::New( QuadMesh(), shader ); + renderers[index].SetTextures( textureSet ); renderers[index].SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::OFF ); } return renderers[index]; @@ -524,7 +525,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/blocks/blocks-example.cpp b/examples/blocks/blocks-example.cpp index c9c336a..61aed74 100644 --- a/examples/blocks/blocks-example.cpp +++ b/examples/blocks/blocks-example.cpp @@ -836,7 +836,7 @@ void RunTest(Application& app) app.MainLoop(); } -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); diff --git a/examples/bubble-effect/bubble-effect-example.cpp b/examples/bubble-effect/bubble-effect-example.cpp index d2f27dc..7127ba4 100644 --- a/examples/bubble-effect/bubble-effect-example.cpp +++ b/examples/bubble-effect/bubble-effect-example.cpp @@ -319,8 +319,7 @@ RunTest(Application& app) /*****************************************************************************/ -int -main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); diff --git a/examples/builder/examples.cpp b/examples/builder/examples.cpp index 233a2c6..e80c88b 100644 --- a/examples/builder/examples.cpp +++ b/examples/builder/examples.cpp @@ -607,7 +607,7 @@ private: // // //------------------------------------------------------------------------------ -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { if(argc > 2) { diff --git a/examples/buttons/buttons-example.cpp b/examples/buttons/buttons-example.cpp index d26e888..8f993fc 100644 --- a/examples/buttons/buttons-example.cpp +++ b/examples/buttons/buttons-example.cpp @@ -544,7 +544,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/compressed-texture-formats/compressed-texture-formats-example.cpp b/examples/compressed-texture-formats/compressed-texture-formats-example.cpp index 99dfe79..7fed128 100644 --- a/examples/compressed-texture-formats/compressed-texture-formats-example.cpp +++ b/examples/compressed-texture-formats/compressed-texture-formats-example.cpp @@ -131,7 +131,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/cube-transition-effect/cube-transition-effect-example.cpp b/examples/cube-transition-effect/cube-transition-effect-example.cpp index 38dbd4a..46d7fcd 100644 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@ -430,7 +430,7 @@ void CubeTransitionApp::OnKeyEvent(const KeyEvent& event) } // Entry point for Linux & Tizen applications -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); CubeTransitionApp test( application ); diff --git a/examples/dissolve-effect/dissolve-effect-example.cpp b/examples/dissolve-effect/dissolve-effect-example.cpp index e9b9493..cd927ae 100644 --- a/examples/dissolve-effect/dissolve-effect-example.cpp +++ b/examples/dissolve-effect/dissolve-effect-example.cpp @@ -441,7 +441,7 @@ bool DissolveEffectApp::OnTimerTick() } // Entry point for Linux & Tizen applications -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); DissolveEffectApp test( application ); diff --git a/examples/effects-view/effects-view-example.cpp b/examples/effects-view/effects-view-example.cpp index 214f538..ab78ec0 100644 --- a/examples/effects-view/effects-view-example.cpp +++ b/examples/effects-view/effects-view-example.cpp @@ -253,7 +253,7 @@ static void RunTest( Application& application ) /*****************************************************************************/ -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); diff --git a/examples/flex-container/flex-container-example.cpp b/examples/flex-container/flex-container-example.cpp new file mode 100644 index 0000000..cd72351 --- /dev/null +++ b/examples/flex-container/flex-container-example.cpp @@ -0,0 +1,384 @@ +/* + * 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 "shared/view.h" + +#include +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace +{ + +const int NUM_FLEX_ITEMS = 8; + +const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-default.png" ); +const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); + +const DemoHelper::ViewStyle VIEW_STYLE( 0.08f, 0.45f, 80.f, 4.f ); + +const std::string FLEX_DIRECTION[] = { + "column", + "columnReverse", + "row", + "rowReverse" +}; + +const unsigned int NUM_FLEX_DIRECTION = sizeof(FLEX_DIRECTION) / sizeof(std::string); + +const std::string FLEX_WRAP[] = { + "noWrap", + "Wrap" +}; + +const unsigned int NUM_FLEX_WRAP = sizeof(FLEX_WRAP) / sizeof(std::string); + +const std::string CONTENT_DIRECTION[] = { + "inherit", + "LTR", + "RTL" +}; + +const unsigned int NUM_CONTENT_DIRECTION = sizeof(CONTENT_DIRECTION) / sizeof(std::string); + +const std::string JUSTIFY_CONTENT[] = { + "flexStart", + "center", + "flexEnd", + "spaceBetween", + "spaceAround" +}; + +const unsigned int NUM_JUSTIFY_CONTENT = sizeof(JUSTIFY_CONTENT) / sizeof(std::string); + +const std::string ALIGN_ITEMS[] = { + "flexStart", + "center", + "flexEnd", + "stretch" +}; + +const unsigned int NUM_ALIGN_ITEMS = sizeof(ALIGN_ITEMS) / sizeof(std::string); + +const std::string ALIGN_CONTENT[] = { + "flexStart", + "center", + "flexEnd", + "stretch" +}; + +const unsigned int NUM_ALIGN_CONTENT = sizeof(ALIGN_CONTENT) / sizeof(std::string); + +} // unnamed namespace + +/** + * This example demonstrates a proof of concept for FlexContainer UI control. + * The flexbox properties can be changed by pressing different buttons in the + * toolbar. + */ +class FlexContainerExample : public ConnectionTracker +{ +public: + + /** + * Constructor + * @param application class, stored as reference + */ + FlexContainerExample( Application& application ) + : mApplication( application ), + mCurrentFlexDirection( FlexContainer::ROW ), + mCurrentFlexWrap( FlexContainer::WRAP ), + mCurrentContentDirection( FlexContainer::INHERIT), + mCurrentJustifyContent( FlexContainer::JUSTIFY_FLEX_START ), + mCurrentAlignItems( FlexContainer::ALIGN_FLEX_START ), + mCurrentAlignContent( FlexContainer::ALIGN_FLEX_START ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect(this, &FlexContainerExample::OnInit); + } + + /** + * This method gets called once the main loop of application is up and running + */ + void OnInit(Application& app) + { + Stage stage = Dali::Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &FlexContainerExample::OnKeyEvent); + stage.GetRootLayer().SetBehavior(Layer::LAYER_3D); + + Vector2 stageSize = Stage::GetCurrent().GetSize(); + + // Creates a default view with a default tool bar. + // The view is added to the stage. + Layer contents = DemoHelper::CreateView( mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + "" ); + + // Create a flex direction toggle button. (left of toolbar) + mFlexDirectionButton = Toolkit::PushButton::New(); + mFlexDirectionButton.SetName("mFlexDirectionButton"); + mFlexDirectionButton.SetUnselectedImage( DEMO_IMAGE_DIR "icon-change.png" ); + mFlexDirectionButton.SetSelectedImage( DEMO_IMAGE_DIR "icon-change-selected.png" ); + mFlexDirectionButton.ClickedSignal().Connect( this, &FlexContainerExample::OnFlexDirectionButtonClicked); + mFlexDirectionButton.SetLeaveRequired( true ); + mToolBar.AddControl( mFlexDirectionButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Create a flex wrap toggle button. (left of toolbar) + mFlexWrapButton = Toolkit::PushButton::New(); + mFlexWrapButton.SetName("mFlexWrapButton"); + mFlexWrapButton.SetUnselectedImage( DEMO_IMAGE_DIR "icon-edit.png" ); + mFlexWrapButton.SetSelectedImage( DEMO_IMAGE_DIR "icon-edit-selected.png" ); + mFlexWrapButton.ClickedSignal().Connect( this, &FlexContainerExample::OnFlexWrapButtonClicked); + mFlexWrapButton.SetLeaveRequired( true ); + mToolBar.AddControl( mFlexWrapButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Create a content direction toggle button. (left of toolbar) + mContentDirectionButton = Toolkit::PushButton::New(); + mContentDirectionButton.SetName("mContentDirectionButton"); + mContentDirectionButton.SetUnselectedImage( DEMO_IMAGE_DIR "icon-replace.png" ); + mContentDirectionButton.SetSelectedImage( DEMO_IMAGE_DIR "icon-replace-selected.png" ); + mContentDirectionButton.ClickedSignal().Connect( this, &FlexContainerExample::OnContentDirectionButtonClicked); + mContentDirectionButton.SetLeaveRequired( true ); + mToolBar.AddControl( mContentDirectionButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Create a justify content toggle button. (right of toolbar) + mJustifyContentButton = Toolkit::PushButton::New(); + mJustifyContentButton.SetName("mJustifyContentButton"); + mJustifyContentButton.SetUnselectedImage( DEMO_IMAGE_DIR "icon-reset.png" ); + mJustifyContentButton.SetSelectedImage( DEMO_IMAGE_DIR "icon-reset-selected.png" ); + mJustifyContentButton.ClickedSignal().Connect( this, &FlexContainerExample::OnJustifyContentButtonClicked); + mJustifyContentButton.SetLeaveRequired( true ); + mToolBar.AddControl( mJustifyContentButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Create a align items toggle button. (right of toolbar) + mAlignItemsButton = Toolkit::PushButton::New(); + mAlignItemsButton.SetName("mAlignItemsButton"); + mAlignItemsButton.SetUnselectedImage( DEMO_IMAGE_DIR "icon-highp.png" ); + mAlignItemsButton.SetSelectedImage( DEMO_IMAGE_DIR "icon-highp-selected.png" ); + mAlignItemsButton.ClickedSignal().Connect( this, &FlexContainerExample::OnAlignItemsButtonClicked); + mAlignItemsButton.SetLeaveRequired( true ); + mToolBar.AddControl( mAlignItemsButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Create a align content toggle button. (right of toolbar) + mAlignContentButton = Toolkit::PushButton::New(); + mAlignContentButton.SetName("mAlignContentButton"); + mAlignContentButton.SetUnselectedImage( DEMO_IMAGE_DIR "icon-effect-cross.png" ); + mAlignContentButton.SetSelectedImage( DEMO_IMAGE_DIR "icon-effect-cross-selected.png" ); + mAlignContentButton.ClickedSignal().Connect( this, &FlexContainerExample::OnAlignContentButtonClicked); + mAlignContentButton.SetLeaveRequired( true ); + mToolBar.AddControl( mAlignContentButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Create the base flex container + mFlexContainer = FlexContainer::New(); + mFlexContainer.SetParentOrigin(ParentOrigin::TOP_LEFT); + mFlexContainer.SetAnchorPoint(AnchorPoint::TOP_LEFT); + mFlexContainer.SetSize( stageSize.width, stageSize.height - VIEW_STYLE.mToolBarHeight ); + mFlexContainer.SetY(VIEW_STYLE.mToolBarHeight); + mFlexContainer.SetProperty(FlexContainer::Property::FLEX_DIRECTION, FlexContainer::COLUMN); // column as main axis + contents.Add(mFlexContainer); + + // Add a text label to the container for showing the recently updated flexbox property value + mFlexPropertyLabel = TextLabel::New( FLEX_DIRECTION[mCurrentFlexDirection] ); + mFlexPropertyLabel.RegisterProperty("flexMargin", Vector4(10.0f, 10.0f, 10.0f, 10.0f), Property::READ_WRITE); + mFlexPropertyLabel.RegisterProperty("flex", 0.05f, Property::READ_WRITE); // 5 pecent of the container size in the main axis + mFlexPropertyLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mFlexPropertyLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mFlexContainer.Add( mFlexPropertyLabel ); + + // Create the flex container for the flex items and add it to the base flex container + mFlexItemContainer = FlexContainer::New(); + mFlexItemContainer.SetParentOrigin(ParentOrigin::TOP_LEFT); + mFlexItemContainer.SetAnchorPoint(AnchorPoint::TOP_LEFT); + mFlexItemContainer.SetBackgroundColor( Color::YELLOW ); + mFlexItemContainer.RegisterProperty("flex", 0.95f, Property::READ_WRITE); // 95 pecent of the container size in the main axis + mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_DIRECTION, mCurrentFlexDirection); + mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_WRAP, mCurrentFlexWrap); + mFlexContainer.Add(mFlexItemContainer); + + // Create flex items and add them to the container + for (int i = 0; i < NUM_FLEX_ITEMS; i++) + { + PushButton flexItem = PushButton::New(); + flexItem.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + flexItem.SetParentOrigin( ParentOrigin::TOP_LEFT ); + + // Set different background colour to help to identify different items + flexItem.SetBackgroundColor(Vector4(static_cast(i) / NUM_FLEX_ITEMS, static_cast(NUM_FLEX_ITEMS - i) / NUM_FLEX_ITEMS, 1.0f, 1.0f)); + flexItem.SetUnselectedImage(""); + flexItem.SetSelectedImage(""); + + // Add a label to the button so that we can identify each item more easily + std::ostringstream index; + index << i + 1; + flexItem.SetLabelText(index.str()); + flexItem.SetName("FlexItem " + index.str()); + + // Set a fixed size to the items so that we can wrap the line and test these + // flex properties that only work when there are multiple lines in the layout + flexItem.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + // Make sure there are still extra space in the line after wrapping + flexItem.SetSize(stageSize.width / NUM_FLEX_ITEMS * 1.25f, (stageSize.height - VIEW_STYLE.mToolBarHeight) * 0.95f / NUM_FLEX_ITEMS * 1.25f); + + mFlexItemContainer.Add( flexItem ); + } + + // Update the title + SetTitle( "Flex direction", FLEX_DIRECTION[mCurrentFlexDirection] ); + } + + bool OnFlexDirectionButtonClicked( Toolkit::Button button ) + { + mCurrentFlexDirection = static_cast( ( mCurrentFlexDirection + 1 ) % NUM_FLEX_DIRECTION ); + mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_DIRECTION, mCurrentFlexDirection); + SetTitle( "Flex direction", FLEX_DIRECTION[mCurrentFlexDirection] ); + + return true; + } + + bool OnFlexWrapButtonClicked( Toolkit::Button button ) + { + mCurrentFlexWrap = static_cast( ( mCurrentFlexWrap + 1 ) % NUM_FLEX_WRAP ); + mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_WRAP, mCurrentFlexWrap); + SetTitle( "Flex wrap", FLEX_WRAP[mCurrentFlexWrap] ); + + return true; + } + + bool OnContentDirectionButtonClicked( Toolkit::Button button ) + { + mCurrentContentDirection = static_cast( ( mCurrentContentDirection + 1 ) % NUM_CONTENT_DIRECTION ); + mFlexItemContainer.SetProperty(FlexContainer::Property::CONTENT_DIRECTION, mCurrentContentDirection); + SetTitle( "Content direction", CONTENT_DIRECTION[mCurrentContentDirection] ); + + return true; + } + + bool OnJustifyContentButtonClicked( Toolkit::Button button ) + { + mCurrentJustifyContent = static_cast( ( mCurrentJustifyContent + 1 ) % NUM_JUSTIFY_CONTENT ); + mFlexItemContainer.SetProperty(FlexContainer::Property::JUSTIFY_CONTENT, mCurrentJustifyContent); + SetTitle( "Justify content", JUSTIFY_CONTENT[mCurrentJustifyContent] ); + + return true; + } + + bool OnAlignItemsButtonClicked( Toolkit::Button button ) + { + mCurrentAlignItems = static_cast( ( mCurrentAlignItems + 1 ) % ( NUM_ALIGN_ITEMS + 1 ) ); + mCurrentAlignItems = mCurrentAlignItems < FlexContainer::ALIGN_FLEX_START ? FlexContainer::ALIGN_FLEX_START : mCurrentAlignItems; // skip auto as it is invalid for alignItems property + mFlexItemContainer.SetProperty(FlexContainer::Property::ALIGN_ITEMS, mCurrentAlignItems ); + SetTitle( "Align Items", ALIGN_ITEMS[mCurrentAlignItems - 1] ); + + return true; + } + + bool OnAlignContentButtonClicked( Toolkit::Button button ) + { + mCurrentAlignContent = static_cast( ( mCurrentAlignContent + 1 ) % (NUM_ALIGN_CONTENT + 1 ) ); + mCurrentAlignContent = mCurrentAlignContent < FlexContainer::ALIGN_FLEX_START ? FlexContainer::ALIGN_FLEX_START : mCurrentAlignContent; // skip auto as it is invalid for alignContent property + mFlexItemContainer.SetProperty(FlexContainer::Property::ALIGN_CONTENT, mCurrentAlignContent); + SetTitle( "Align content", ALIGN_CONTENT[mCurrentAlignContent - 1] ); + + return true; + } + +private: + + /** + * Sets/Updates the title of the View and the value of the recently updated + * flexbox property. + * + * @param[in] title The new title for the view. + * @param[in] propertyValue The value of the flexbox property. + */ + void SetTitle(const std::string& title, const std::string& propertyValue) + { + if(!mTitleActor) + { + mTitleActor = DemoHelper::CreateToolBarLabel( "" ); + // Add title to the tool bar. + mToolBar.AddControl( mTitleActor, VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); + } + + // Update the title and property value + mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); + mFlexPropertyLabel.SetProperty( TextLabel::Property::TEXT, propertyValue ); + } + + /** + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + +private: + + Application& mApplication; + + Toolkit::Control mView; + Toolkit::ToolBar mToolBar; + TextLabel mTitleActor; ///< The Toolbar's Title. + + FlexContainer mFlexContainer; + FlexContainer mFlexItemContainer; + TextLabel mFlexPropertyLabel; + + FlexContainer::FlexDirection mCurrentFlexDirection; + FlexContainer::WrapType mCurrentFlexWrap; + FlexContainer::ContentDirection mCurrentContentDirection; + FlexContainer::Justification mCurrentJustifyContent; + FlexContainer::Alignment mCurrentAlignItems; + FlexContainer::Alignment mCurrentAlignContent; + + Toolkit::PushButton mFlexDirectionButton; + Toolkit::PushButton mFlexWrapButton; + Toolkit::PushButton mContentDirectionButton; + Toolkit::PushButton mJustifyContentButton; + Toolkit::PushButton mAlignItemsButton; + Toolkit::PushButton mAlignContentButton; +}; + +void RunTest(Application& app) +{ + FlexContainerExample test(app); + + app.MainLoop(); +} + +int DALI_EXPORT_API main(int argc, char **argv) +{ + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + + RunTest(app); + + return 0; +} diff --git a/examples/gradients/gradients-example.cpp b/examples/gradients/gradients-example.cpp index 88d64e1..2e59ab8 100644 --- a/examples/gradients/gradients-example.cpp +++ b/examples/gradients/gradients-example.cpp @@ -178,7 +178,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/hello-world/hello-world-example.cpp b/examples/hello-world/hello-world-example.cpp index f316b2c..2c5763a 100644 --- a/examples/hello-world/hello-world-example.cpp +++ b/examples/hello-world/hello-world-example.cpp @@ -74,7 +74,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/homescreen-benchmark/homescreen-benchmark.cpp b/examples/homescreen-benchmark/homescreen-benchmark.cpp index 31ff790..a35919a 100644 --- a/examples/homescreen-benchmark/homescreen-benchmark.cpp +++ b/examples/homescreen-benchmark/homescreen-benchmark.cpp @@ -677,7 +677,7 @@ void RunTest( Application& application, const HomescreenBenchmark::Config& confi // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { // default settings HomescreenBenchmark::Config config; diff --git a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp index b5d2407..99fe02e 100644 --- a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp +++ b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp @@ -759,7 +759,7 @@ void RunTest( Application& application ) } // Entry point for Linux & Tizen applications -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp index 39fe97c..dc982f8 100644 --- a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp +++ b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp @@ -614,7 +614,7 @@ void RunTest( Application& application ) } /** Entry point for Linux & Tizen applications */ -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp b/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp index d47cb7c..db6adfa 100644 --- a/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp +++ b/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp @@ -122,7 +122,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/image-view-pixel-area/image-view-pixel-area-example.cpp b/examples/image-view-pixel-area/image-view-pixel-area-example.cpp index 2805025..69a8c54 100644 --- a/examples/image-view-pixel-area/image-view-pixel-area-example.cpp +++ b/examples/image-view-pixel-area/image-view-pixel-area-example.cpp @@ -118,7 +118,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/image-view-svg/image-view-svg-example.cpp b/examples/image-view-svg/image-view-svg-example.cpp index da06f87..7c34a92 100644 --- a/examples/image-view-svg/image-view-svg-example.cpp +++ b/examples/image-view-svg/image-view-svg-example.cpp @@ -234,7 +234,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/image-view/image-view-example.cpp b/examples/image-view/image-view-example.cpp index db0704f..af3f16c 100644 --- a/examples/image-view/image-view-example.cpp +++ b/examples/image-view/image-view-example.cpp @@ -263,7 +263,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/item-view/item-view-example.cpp b/examples/item-view/item-view-example.cpp index 6d90387..2c4060b 100644 --- a/examples/item-view/item-view-example.cpp +++ b/examples/item-view/item-view-example.cpp @@ -983,7 +983,7 @@ void RunTest(Application& app) app.MainLoop(); } -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); diff --git a/examples/line-mesh/line-mesh-example.cpp b/examples/line-mesh/line-mesh-example.cpp index 8916928..5c8779b 100644 --- a/examples/line-mesh/line-mesh-example.cpp +++ b/examples/line-mesh/line-mesh-example.cpp @@ -32,14 +32,18 @@ namespace const char* VERTEX_SHADER = MAKE_SHADER( attribute mediump vec2 aPosition1; attribute mediump vec2 aPosition2; +attribute lowp vec3 aColor; uniform mediump mat4 uMvpMatrix; uniform mediump vec3 uSize; uniform mediump float uMorphAmount; +varying lowp vec3 vColor; + void main() { mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); + vColor = aColor; vertexPosition.xyz *= uSize; vertexPosition = uMvpMatrix * vertexPosition; gl_Position = vertexPosition; @@ -50,59 +54,87 @@ const char* FRAGMENT_SHADER = MAKE_SHADER( uniform lowp vec4 uColor; uniform sampler2D sTexture; +varying lowp vec3 vColor; + void main() { - gl_FragColor = uColor; + gl_FragColor = uColor * vec4( vColor, 1.0 ); } ); +PropertyBuffer CreateIndexBuffer( Geometry::GeometryType geometryType ) +{ + // Create indices + const unsigned int indexDataLines[] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 }; + const unsigned int indexDataLoops[] = { 0, 1, 2, 3, 4 }; + const unsigned int indexDataStrips[] = { 0, 1, 2, 3, 4, 0 }; + + // Create index buffer if doesn't exist + Property::Map indexFormat; + indexFormat["indices"] = Property::INTEGER; + PropertyBuffer indices = PropertyBuffer::New( indexFormat ); + + // Update buffer + switch( geometryType ) + { + case Geometry::LINES: + { + indices.SetData( indexDataLines, sizeof(indexDataLines)/sizeof(indexDataLines[0]) ); + break; + } + case Geometry::LINE_LOOP: + { + indices.SetData( indexDataLoops, sizeof(indexDataLoops)/sizeof(indexDataLoops[0]) ); + break; + } + case Geometry::LINE_STRIP: + { + indices.SetData( indexDataStrips, sizeof(indexDataStrips)/sizeof(indexDataStrips[0]) ); + break; + } + default: // this will never happen, but compilers yells + { + } + } + + return indices; +} + Geometry CreateGeometry() { // Create vertices - struct Vertex { Vector2 position; }; - Vertex pentagonVertexData[5] = - { - { Vector2( 0.0f, 1.00f) }, // 0 - { Vector2( -0.95f, 0.31f) }, // 1 - { Vector2( -0.59f, -0.81f) }, // 2 - { Vector2( 0.59f, -0.81f) }, // 3 - { Vector2( 0.95f, 0.31f) }, // 4 - }; + struct Vertex + { + Vector2 position1; + Vector2 position2; + Vector3 color; + }; - Vertex pentacleVertexData[5] = + // Create new geometry object + Vertex pentagonVertexData[5] = { - { Vector2( 0.0f, -1.00f) }, // - { Vector2( 0.59f, 0.81f) }, // - { Vector2( -0.95f, -0.31f) }, // - { Vector2( 0.95f, -0.31f) }, // - { Vector2( -0.59f, 0.81f) }, // + { Vector2( 0.0f, 1.00f), Vector2( 0.0f, -1.00f), Vector3( 1.0f, 1.0f, 1.0f ) }, // 0 + { Vector2( -0.95f, 0.31f), Vector2( 0.59f, 0.81f), Vector3( 1.0f, 0.0f, 0.0f ) }, // 1 + { Vector2( -0.59f, -0.81f), Vector2( -0.95f, -0.31f), Vector3( 0.0f, 1.0f, 0.0f ) }, // 2 + { Vector2( 0.59f, -0.81f), Vector2( 0.95f, -0.31f), Vector3( 0.0f, 0.0f, 1.0f ) }, // 3 + { Vector2( 0.95f, 0.31f), Vector2( -0.59f, 0.81f), Vector3( 1.0f, 1.0f, 0.0f ) }, // 4 }; Property::Map pentagonVertexFormat; pentagonVertexFormat["aPosition1"] = Property::VECTOR2; + pentagonVertexFormat["aPosition2"] = Property::VECTOR2; + pentagonVertexFormat["aColor"] = Property::VECTOR3; PropertyBuffer pentagonVertices = PropertyBuffer::New( pentagonVertexFormat ); pentagonVertices.SetData(pentagonVertexData, 5); - Property::Map pentacleVertexFormat; - pentacleVertexFormat["aPosition2"] = Property::VECTOR2; - PropertyBuffer pentacleVertices = PropertyBuffer::New( pentacleVertexFormat ); - pentacleVertices.SetData( pentacleVertexData, 5 ); - // Create indices - unsigned int indexData[10] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 }; - Property::Map indexFormat; - indexFormat["indices"] = Property::INTEGER; - PropertyBuffer indices = PropertyBuffer::New( indexFormat ); - indices.SetData( indexData, sizeof(indexData)/sizeof(indexData[0]) ); + PropertyBuffer indices = CreateIndexBuffer( Geometry::LINES ); // Create the geometry object Geometry pentagonGeometry = Geometry::New(); pentagonGeometry.AddVertexBuffer( pentagonVertices ); - pentagonGeometry.AddVertexBuffer( pentacleVertices ); pentagonGeometry.SetIndexBuffer( indices ); - pentagonGeometry.SetGeometryType( Geometry::LINES ); - return pentagonGeometry; } @@ -140,22 +172,40 @@ public: void Create( Application& application ) { Stage stage = Stage::GetCurrent(); + + CreateRadioButtons(); + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); mStageSize = stage.GetSize(); // The Init signal is received once (only) during the Application lifetime + ReInitialise( Geometry::LINES ); // Hide the indicator bar application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f)); + } - mMaterial = Material::New( mShader ); + /** + * Invoked whenever application changes the type of geometry drawn + * @param[in] type of geometry + */ + void ReInitialise( Geometry::GeometryType geometryType ) + { + Stage stage = Stage::GetCurrent(); - mGeometry = CreateGeometry(); + // destroy mesh actor and its resources if already exists + if( mMeshActor ) + { + stage.Remove( mMeshActor ); + mMeshActor.Reset(); + } - mRenderer = Renderer::New( mGeometry, mMaterial ); + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mGeometry = CreateGeometry(); + mRenderer = Renderer::New( mGeometry, mShader ); mMeshActor = Actor::New(); mMeshActor.AddRenderer( mRenderer ); @@ -177,8 +227,48 @@ public: animation.AnimateBetween( Property( mMeshActor, morphAmountIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); animation.SetLooping(true); animation.Play(); + } - stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f)); + /** + * Invoked on create + */ + void CreateRadioButtons() + { + Stage stage = Stage::GetCurrent(); + + Toolkit::TableView modeSelectTableView = Toolkit::TableView::New( 3, 1 ); + modeSelectTableView.SetParentOrigin( ParentOrigin::TOP_LEFT ); + modeSelectTableView.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + modeSelectTableView.SetFitHeight( 0 ); + modeSelectTableView.SetFitHeight( 1 ); + modeSelectTableView.SetFitHeight( 2 ); + modeSelectTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + modeSelectTableView.SetScale( Vector3( 0.5f, 0.5f, 0.5f )); + + const char* labels[] = + { + "LINES", + "LINE_LOOP", + "LINE_STRIP" + }; + + for( int i = 0; i < 3; ++i ) + { + Property::Map labelMap; + labelMap[ "text" ] = labels[i]; + labelMap[ "textColor" ] = Vector4( 0.8f, 0.8f, 0.8f, 1.0f ); + + Dali::Toolkit::RadioButton radio = Dali::Toolkit::RadioButton::New(); + + radio.SetProperty( Dali::Toolkit::RadioButton::Property::LABEL, labelMap ); + radio.SetParentOrigin( ParentOrigin::TOP_LEFT ); + radio.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + radio.SetSelected( i == 0 ); + radio.PressedSignal().Connect( this, &ExampleController::OnButtonPressed ); + mButtons[i] = radio; + modeSelectTableView.AddChild( radio, Toolkit::TableView::CellPosition( i, 0 ) ); + } + stage.Add(modeSelectTableView); } /** @@ -203,16 +293,48 @@ public: } } + bool OnButtonPressed( Toolkit::Button button ) + { + const Geometry::GeometryType geomTypes[] = + { + Geometry::LINES, + Geometry::LINE_LOOP, + Geometry::LINE_STRIP + }; + + size_t index; + if( button == mButtons[0] ) + { + index = 0; + } + else if( button == mButtons[1] ) + { + index = 1; + } + else + { + index = 2; + } + + PropertyBuffer indices = CreateIndexBuffer( geomTypes[ index ] ); + mGeometry.SetIndexBuffer( indices ); + mGeometry.SetGeometryType( geomTypes[ index ] ); + + return true; + } + + + private: Application& mApplication; ///< Application instance Vector3 mStageSize; ///< The size of the stage Shader mShader; - Material mMaterial; Geometry mGeometry; Renderer mRenderer; Actor mMeshActor; + Toolkit::RadioButton mButtons[3]; }; void RunTest( Application& application ) @@ -224,7 +346,7 @@ void RunTest( Application& application ) // Entry point for Linux & SLP applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/logging/logging-example.cpp b/examples/logging/logging-example.cpp index 46969e0..9abef21 100644 --- a/examples/logging/logging-example.cpp +++ b/examples/logging/logging-example.cpp @@ -710,7 +710,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/magnifier/magnifier-example.cpp b/examples/magnifier/magnifier-example.cpp index 4433e59..279713d 100644 --- a/examples/magnifier/magnifier-example.cpp +++ b/examples/magnifier/magnifier-example.cpp @@ -411,7 +411,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/mesh-morph/mesh-morph-example.cpp b/examples/mesh-morph/mesh-morph-example.cpp index 10b7f2e..9ab3b4b 100644 --- a/examples/mesh-morph/mesh-morph-example.cpp +++ b/examples/mesh-morph/mesh-morph-example.cpp @@ -292,11 +292,8 @@ public: application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); - - mMaterial = Material::New( mShader ); mGeometry = CreateGeometry(); - - mRenderer = Renderer::New( mGeometry, mMaterial ); + mRenderer = Renderer::New( mGeometry, mShader ); mMeshActor = Actor::New(); mMeshActor.AddRenderer( mRenderer ); @@ -346,7 +343,6 @@ private: Vector3 mStageSize; ///< The size of the stage Shader mShader; - Material mMaterial; Geometry mGeometry; Renderer mRenderer; Actor mMeshActor; @@ -362,7 +358,7 @@ void RunTest( Application& application ) // Entry point for Linux & SLP applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/mesh-sorting/mesh-sorting-example.cpp b/examples/mesh-sorting/mesh-sorting-example.cpp index 4b51c37..95c091d 100644 --- a/examples/mesh-sorting/mesh-sorting-example.cpp +++ b/examples/mesh-sorting/mesh-sorting-example.cpp @@ -30,7 +30,7 @@ using namespace Dali; namespace { -const char* MATERIAL_SAMPLES[] = +const char* IMAGES[] = { DEMO_IMAGE_DIR "people-medium-1.jpg", DEMO_IMAGE_DIR "people-medium-4.jpg", @@ -39,7 +39,7 @@ const char* MATERIAL_SAMPLES[] = DEMO_IMAGE_DIR "people-medium-15.jpg", DEMO_IMAGE_DIR "people-medium-6.jpg", }; -const unsigned int NUMBER_OF_SAMPLES(sizeof(MATERIAL_SAMPLES)/sizeof(const char*)); +const unsigned int NUMBER_OF_SAMPLES(sizeof(IMAGES)/sizeof(const char*)); #define MAKE_SHADER(A)#A @@ -164,16 +164,17 @@ public: mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); mGeometry = CreateGeometry(); - Material firstMat; + TextureSet firstTextureSet; for( unsigned i=0; i +#include +#include +#include +#include +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; + + +namespace +{ +const char* IMAGE_PATH[] = { + DEMO_IMAGE_DIR "gallery-medium-1.jpg", + DEMO_IMAGE_DIR "gallery-medium-2.jpg", + DEMO_IMAGE_DIR "gallery-medium-3.jpg", + DEMO_IMAGE_DIR "gallery-medium-4.jpg", + DEMO_IMAGE_DIR "gallery-medium-5.jpg", + DEMO_IMAGE_DIR "gallery-medium-6.jpg", + DEMO_IMAGE_DIR "gallery-medium-7.jpg", + DEMO_IMAGE_DIR "gallery-medium-8.jpg", + DEMO_IMAGE_DIR "gallery-medium-9.jpg", + DEMO_IMAGE_DIR "gallery-medium-10.jpg", + DEMO_IMAGE_DIR "gallery-medium-11.jpg", + DEMO_IMAGE_DIR "gallery-medium-12.jpg", + DEMO_IMAGE_DIR "gallery-medium-13.jpg", + DEMO_IMAGE_DIR "gallery-medium-14.jpg", + DEMO_IMAGE_DIR "gallery-medium-15.jpg", + DEMO_IMAGE_DIR "gallery-medium-16.jpg", + DEMO_IMAGE_DIR "gallery-medium-17.jpg", + DEMO_IMAGE_DIR "gallery-medium-18.jpg", + DEMO_IMAGE_DIR "gallery-medium-19.jpg", + DEMO_IMAGE_DIR "gallery-medium-20.jpg", + DEMO_IMAGE_DIR "gallery-medium-21.jpg", + DEMO_IMAGE_DIR "gallery-medium-22.jpg", + DEMO_IMAGE_DIR "gallery-medium-23.jpg", + DEMO_IMAGE_DIR "gallery-medium-24.jpg", + DEMO_IMAGE_DIR "gallery-medium-25.jpg", + DEMO_IMAGE_DIR "gallery-medium-26.jpg", + DEMO_IMAGE_DIR "gallery-medium-27.jpg", + DEMO_IMAGE_DIR "gallery-medium-28.jpg", + DEMO_IMAGE_DIR "gallery-medium-29.jpg", + DEMO_IMAGE_DIR "gallery-medium-30.jpg", + DEMO_IMAGE_DIR "gallery-medium-31.jpg", + DEMO_IMAGE_DIR "gallery-medium-32.jpg", + DEMO_IMAGE_DIR "gallery-medium-33.jpg", + DEMO_IMAGE_DIR "gallery-medium-34.jpg", + DEMO_IMAGE_DIR "gallery-medium-35.jpg", + DEMO_IMAGE_DIR "gallery-medium-36.jpg", + DEMO_IMAGE_DIR "gallery-medium-37.jpg", + DEMO_IMAGE_DIR "gallery-medium-38.jpg", + DEMO_IMAGE_DIR "gallery-medium-39.jpg", + DEMO_IMAGE_DIR "gallery-medium-40.jpg", + DEMO_IMAGE_DIR "gallery-medium-41.jpg", + DEMO_IMAGE_DIR "gallery-medium-42.jpg", + DEMO_IMAGE_DIR "gallery-medium-43.jpg", + DEMO_IMAGE_DIR "gallery-medium-44.jpg", + DEMO_IMAGE_DIR "gallery-medium-45.jpg", + DEMO_IMAGE_DIR "gallery-medium-46.jpg", + DEMO_IMAGE_DIR "gallery-medium-47.jpg", + DEMO_IMAGE_DIR "gallery-medium-48.jpg", + DEMO_IMAGE_DIR "gallery-medium-49.jpg", + DEMO_IMAGE_DIR "gallery-medium-50.jpg", + DEMO_IMAGE_DIR "gallery-medium-51.jpg", + DEMO_IMAGE_DIR "gallery-medium-52.jpg", + DEMO_IMAGE_DIR "gallery-medium-53.jpg", +}; + +const char* NINEPATCH_IMAGE_PATH[] = { + DEMO_IMAGE_DIR "selection-popup-bg.1.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.2.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.3.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.4.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.5.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.6.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.7.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.8.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.9.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.10.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.11.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.12.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.13.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.14.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.15.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.16.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.17.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.18.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.19.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.20.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.21.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.22.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.23.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.24.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.25.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.26.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.27.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.28.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.29.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.30.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.31.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.32.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.33.9.png", + DEMO_IMAGE_DIR "button-disabled.9.png", + DEMO_IMAGE_DIR "button-down.9.png", + DEMO_IMAGE_DIR "button-down-disabled.9.png", + DEMO_IMAGE_DIR "button-up-1.9.png", + DEMO_IMAGE_DIR "button-up-2.9.png", + DEMO_IMAGE_DIR "button-up-3.9.png", + DEMO_IMAGE_DIR "button-up-4.9.png", + DEMO_IMAGE_DIR "button-up-5.9.png", + DEMO_IMAGE_DIR "button-up-6.9.png", + DEMO_IMAGE_DIR "button-up-7.9.png", + DEMO_IMAGE_DIR "button-up-8.9.png", + DEMO_IMAGE_DIR "button-up-9.9.png", + DEMO_IMAGE_DIR "button-up-10.9.png", + DEMO_IMAGE_DIR "button-up-11.9.png", + DEMO_IMAGE_DIR "button-up-12.9.png", + DEMO_IMAGE_DIR "button-up-13.9.png", + DEMO_IMAGE_DIR "button-up-14.9.png", + DEMO_IMAGE_DIR "button-up-15.9.png", + DEMO_IMAGE_DIR "button-up-16.9.png", + DEMO_IMAGE_DIR "button-up-17.9.png", +}; + +const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); +const unsigned int NUM_NINEPATCH_IMAGES = sizeof(NINEPATCH_IMAGE_PATH) / sizeof(char*); + +const float ANIMATION_TIME ( 5.0f ); // animation length in seconds + +struct VertexWithTexture +{ + Vector2 position; + Vector2 texCoord; +}; + +VertexWithTexture gQuadWithTexture[] = { + { Vector2( -0.5f, -0.5f ), Vector2( 0.0f, 0.0f ) }, + { Vector2( 0.5f, -0.5f ), Vector2( 1.0f, 0.0f ) }, + { Vector2( -0.5f, 0.5f ), Vector2( 0.0f, 1.0f ) }, + { Vector2( 0.5f, 0.5f ), Vector2( 1.0f, 1.0f ) } +}; + +const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( + attribute mediump vec2 aPosition;\n + attribute mediump vec2 aTexCoord;\n + uniform mediump mat4 uMvpMatrix;\n + uniform mediump vec3 uSize;\n + varying mediump vec2 vTexCoord;\n + void main()\n + {\n + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n + gl_Position = uMvpMatrix * position;\n + vTexCoord = aTexCoord;\n + }\n +); + +const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( + uniform lowp vec4 uColor;\n + uniform sampler2D sTexture;\n + varying mediump vec2 vTexCoord;\n + + void main()\n + {\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n + }\n +); + + +Geometry& QuadMesh() +{ + static Geometry mesh; + if( !mesh ) + { + PropertyBuffer vertexBuffer; + Property::Map vertexFormat; + vertexFormat["aPosition"] = Property::VECTOR2; + vertexFormat["aTexCoord"] = Property::VECTOR2; + + //Create a vertex buffer for vertex positions and texture coordinates + vertexBuffer = PropertyBuffer::New( vertexFormat ); + vertexBuffer.SetData( gQuadWithTexture, 4u ); + + //Create the geometry + mesh = Geometry::New(); + mesh.AddVertexBuffer( vertexBuffer ); + mesh.SetGeometryType( Geometry::TRIANGLE_STRIP ); + } + return mesh; +} + +bool gUseMesh(false); +bool gNinePatch(false); +unsigned int gRowsPerPage(15); +unsigned int gColumnsPerPage(15); +unsigned int gPageCount(10); +float gDuration(10.0f); + +Renderer CreateRenderer( unsigned int index ) +{ + + int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; + static Renderer* renderers = new Renderer[numImages]; + if( !renderers[index] ) + { + //Create the renderer + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); + + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; + Image image = ResourceImage::New( imagePath ); + + TextureSet textureSet = TextureSet::New(); + textureSet.SetImage( 0u, image ); + renderers[index] = Renderer::New( QuadMesh(), shader ); + renderers[index].SetTextures( textureSet ); + renderers[index].SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::OFF ); + + } + return renderers[index]; +} + +Actor CreateMeshActor( unsigned int index) +{ + Renderer renderer = CreateRenderer( index ); + Actor meshActor = Actor::New(); + meshActor.AddRenderer( renderer ); + return meshActor; +} + +} +// Test application to compare performance between ImageActor and ImageView +// By default, the application consist of 10 pages of 25x25 ImageActors, this can be modified using the following command line arguments: +// -t duration (sec ) +// --use-imageview ( Use ImageView instead of ImageActor ) +// --use-mesh ( Use new renderer API (as ImageView) but shares renderers between actors when possible ) + +// +class PerfScroll : public ConnectionTracker +{ +public: + + PerfScroll( Application& application ) + : mApplication( application ), + mRowsPerPage( gRowsPerPage ), + mColumnsPerPage( gColumnsPerPage ), + mPageCount( gPageCount ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &PerfScroll::Create ); + } + + ~PerfScroll() + { + // Nothing to do here; + } + + // The Init signal is received once (only) during the Application lifetime + void Create( Application& application ) + { + // Get a handle to the stage + Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Color::WHITE ); + Vector2 stageSize = stage.GetSize(); + + stage.GetRootLayer().SetDepthTestDisabled(true); + + mSize = Vector3( stageSize.x / mColumnsPerPage, stageSize.y / mRowsPerPage, 0.0f ); + + // Respond to a click anywhere on the stage + stage.GetRootLayer().TouchedSignal().Connect( this, &PerfScroll::OnTouch ); + + mParent = Actor::New(); + mParent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + stage.Add(mParent); + + if( gUseMesh ) + { + CreateMeshActors(); + } + else + { + CreateImageViews(); + } + + ShowAnimation(); + } + + bool OnTouch( Actor actor, const TouchEvent& touch ) + { + // quit the application + mApplication.Quit(); + return true; + } + + const char* ImagePath( int i ) + { + return !gNinePatch ? IMAGE_PATH[i % NUM_IMAGES] : NINEPATCH_IMAGE_PATH[i % NUM_NINEPATCH_IMAGES]; + } + + void CreateImageViews() + { + Stage stage = Stage::GetCurrent(); + unsigned int actorCount( mRowsPerPage*mColumnsPerPage * mPageCount ); + mImageView.resize( actorCount ); + + for( size_t i(0); i mActor; + std::vector mImageView; + Actor mParent; + + Vector3 mSize; + unsigned int mRowsPerPage; + unsigned int mColumnsPerPage; + unsigned int mPageCount; + + Animation mShow; + Animation mScroll; + Animation mHide; +}; + +void RunTest( Application& application ) +{ + PerfScroll test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & Tizen applications +// +int DALI_EXPORT_API main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + for( int i(1) ; i < argc; ++i ) + { + std::string arg( argv[i] ); + if( arg.compare("--use-mesh") == 0) + { + gUseMesh = true; + } + else if( arg.compare("--nine-patch" ) == 0) + { + gNinePatch = true; + } + else if( arg.compare(0, 2, "-t" ) == 0) + { + gDuration = atof( arg.substr( 2, arg.size()).c_str()); + } + } + + RunTest( application ); + + return 0; +} diff --git a/examples/point-mesh/point-mesh-example.cpp b/examples/point-mesh/point-mesh-example.cpp index 6f7c032..22d557d 100644 --- a/examples/point-mesh/point-mesh-example.cpp +++ b/examples/point-mesh/point-mesh-example.cpp @@ -152,18 +152,19 @@ public: // Hide the indicator bar application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); - mImage = ResourceImage::New( MATERIAL_SAMPLE ); - Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); + Image image0 = ResourceImage::New( MATERIAL_SAMPLE ); + Image image1 = ResourceImage::New( MATERIAL_SAMPLE2 ); - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); - mMaterial = Material::New( mShader ); - mMaterial.AddTexture(mImage, "sTexture1"); - mMaterial.AddTexture(image, "sTexture2"); + TextureSet textureSet = TextureSet::New(); + textureSet.SetImage( 0u, image0 ); + textureSet.SetImage( 1u, image1 ); - mGeometry = CreateGeometry(); + Geometry geometry = CreateGeometry(); - mRenderer = Renderer::New( mGeometry, mMaterial ); + mRenderer = Renderer::New( geometry, shader ); + mRenderer.SetTextures( textureSet ); mMeshActor = Actor::New(); mMeshActor.AddRenderer( mRenderer ); @@ -219,10 +220,6 @@ private: Application& mApplication; ///< Application instance Vector3 mStageSize; ///< The size of the stage - Image mImage; - Shader mShader; - Material mMaterial; - Geometry mGeometry; Renderer mRenderer; Actor mMeshActor; Renderer mRenderer2; @@ -239,7 +236,7 @@ void RunTest( Application& application ) // Entry point for Linux & SLP applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); diff --git a/examples/popup/popup-example.cpp b/examples/popup/popup-example.cpp index 4582f81..b88982f 100644 --- a/examples/popup/popup-example.cpp +++ b/examples/popup/popup-example.cpp @@ -731,7 +731,7 @@ void RunTest( Application& application ) } // Entry point for Linux & SLP applications -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); diff --git a/examples/radial-menu/radial-menu-example.cpp b/examples/radial-menu/radial-menu-example.cpp index 3454125..4086fbc 100644 --- a/examples/radial-menu/radial-menu-example.cpp +++ b/examples/radial-menu/radial-menu-example.cpp @@ -299,7 +299,7 @@ void RunTest(Application app) } // Entry point for Linux & Tizen applications -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); diff --git a/examples/radial-menu/radial-sweep-view-impl.cpp b/examples/radial-menu/radial-sweep-view-impl.cpp index ea98aa6..c072f58 100644 --- a/examples/radial-menu/radial-sweep-view-impl.cpp +++ b/examples/radial-menu/radial-sweep-view-impl.cpp @@ -302,10 +302,6 @@ void RadialSweepViewImpl::Deactivate() { mAnim.Stop(); } - // mLayer.Remove( mStencilActor ); - // mStencilActor.Reset(); - // mMesh.Reset(); - // mMaterial.Reset(); } void RadialSweepViewImpl::CreateStencil( Radian initialSector ) @@ -344,14 +340,13 @@ void RadialSweepViewImpl::CreateStencil( Radian initialSector ) meshGeometry.AddVertexBuffer( vertices ); meshGeometry.SetIndexBuffer( indices ); - // Create material + // Create shader std::ostringstream vertexShaderStringStream; vertexShaderStringStream<