diff --git a/build/android/dali/build_toolkit.sh b/build/android/dali/build_toolkit.sh index eae8927..cd35bf5 100755 --- a/build/android/dali/build_toolkit.sh +++ b/build/android/dali/build_toolkit.sh @@ -15,6 +15,10 @@ else export ENABLE_TRACE=OFF fi + if [ -z "$CXX" ]; then + export CXX="g++" + fi + export PREFIX=${DALI_ENV_DIR} export PKG_CONFIG_LIBDIR=${ANDROID_NDK}/prebuilt/linux-x86_64/lib/pkgconfig export PKG_CONFIG_PATH=${PREFIX}/lib/${ANDROID_ABI}/pkgconfig @@ -23,7 +27,7 @@ else export DALI_DATA_RO_INSTALL_DIR=${PREFIX}/files export DALI_DATA_RW_INSTALL_DIR=${PREFIX}/files - ${ANDROID_SDK}/cmake/3.10.2.4988404/bin/cmake ${DALI_DIR}/dali-toolkit/build/tizen -DCMAKE_C_COMPILER=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -DCMAKE_CXX_COMPILER=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=${ANDROID_PLATFORM} -DANDROID_ABI=${ANDROID_ABI} -DANDROID_NDK=${ANDROID_NDK} -DANDROID_STL=c++_shared -DCMAKE_CXX_FLAGS='-fexceptions -frtti -w -Wall -std=c++17' -DINCLUDE_DIR=${PREFIX}/include -DLIB_DIR=${PREFIX}/lib/${ANDROID_ABI} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DENABLE_TRACE=${ENABLE_TRACE} -DWITH_STYLE='720x1280' + ${ANDROID_SDK}/cmake/3.10.2.4988404/bin/cmake ${DALI_DIR}/dali-toolkit/build/tizen -DCMAKE_C_COMPILER=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -DCMAKE_CXX_COMPILER=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=${ANDROID_PLATFORM} -DANDROID_ABI=${ANDROID_ABI} -DANDROID_NDK=${ANDROID_NDK} -DANDROID_STL=c++_shared -DCMAKE_CXX_FLAGS='-fexceptions -frtti -w -Wall -std=c++17' -DINCLUDE_DIR=${PREFIX}/include -DLIB_DIR=${PREFIX}/lib/${ANDROID_ABI} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DENABLE_TRACE=${ENABLE_TRACE} -DWITH_STYLE='720x1280' -DANDROID_HOST_COMPILER="$CXX" fi make -j8 || exit 1 diff --git a/build/tizen/CMakeLists.txt b/build/tizen/CMakeLists.txt index df31de6..820188d 100644 --- a/build/tizen/CMakeLists.txt +++ b/build/tizen/CMakeLists.txt @@ -154,6 +154,7 @@ INSTALL_TREE_FILES(${LOCAL_IMAGES_DIR} "${LOCAL_IMAGES_TREE}" "*.ktx" ${IMAGES_D INSTALL_TREE_FILES(${LOCAL_IMAGES_DIR} "${LOCAL_IMAGES_TREE}" "*.astc" ${IMAGES_DIR}) INSTALL_TREE_FILES(${LOCAL_IMAGES_DIR} "${LOCAL_IMAGES_TREE}" "*.svg" ${IMAGES_DIR}) INSTALL_TREE_FILES(${LOCAL_IMAGES_DIR} "${LOCAL_IMAGES_TREE}" "*.json" ${IMAGES_DIR}) +INSTALL_TREE_FILES(${LOCAL_IMAGES_DIR} "${LOCAL_IMAGES_TREE}" "*.riv" ${IMAGES_DIR}) FILE(GLOB LOCAL_VIDEOS_LIST RELATIVE "${LOCAL_VIDEOS_DIR}" "${LOCAL_VIDEOS_DIR}/*") FOREACH(flag ${LOCAL_VIDEOS_LIST}) diff --git a/build/tizen/examples/CMakeLists.txt b/build/tizen/examples/CMakeLists.txt index 6476710..1692226 100644 --- a/build/tizen/examples/CMakeLists.txt +++ b/build/tizen/examples/CMakeLists.txt @@ -20,16 +20,13 @@ IF (NOT "${ENABLE_SCENE_LOADER}" ) ENDIF() ENDIF() +FIND_PROGRAM( SHADER_GENERATOR "dali-shader-generator" ) +IF( NOT SHADER_GENERATOR ) + MESSAGE( FATAL_ERROR "dali-shader-generator not found!" ) +ENDIF() + FOREACH(EXAMPLE ${SUBDIRS}) - # Generate source files for shaders - SET(SHADER_SOURCE_DIR "${EXAMPLES_SRC_DIR}/${EXAMPLE}/shaders/") - SET(SHADER_GENERATED_DIR "${EXAMPLES_SRC_DIR}/${EXAMPLE}/generated/") SET(PARENT_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../") - IF (EXISTS ${SHADER_SOURCE_DIR}) - EXECUTE_PROCESS( COMMAND bash -c "${PARENT_CMAKE_SOURCE_DIR}/shader-generator.sh ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR} --skip") - SET_PROPERTY( DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES - "${SHADER_GENERATED_DIR}" ) - ENDIF() FILE(GLOB SRCS "${EXAMPLES_SRC_DIR}/${EXAMPLE}/*.cpp") SET(SRCS ${SRCS} "${ROOT_SRC_DIR}/shared/resources-location.cpp") IF(SHARED) @@ -37,6 +34,18 @@ FOREACH(EXAMPLE ${SUBDIRS}) ELSE() ADD_EXECUTABLE(${EXAMPLE}.example ${SRCS}) ENDIF() + + # Generate source files for shaders + SET(SHADER_SOURCE_DIR "${EXAMPLES_SRC_DIR}/${EXAMPLE}/shaders/") + IF (EXISTS ${SHADER_SOURCE_DIR}) + SET(SHADER_GENERATED_DIR "${EXAMPLES_SRC_DIR}/${EXAMPLE}/generated/") + ADD_CUSTOM_TARGET(${EXAMPLE}-generate-shaders + COMMAND ${SHADER_GENERATOR} --skip ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR}) + SET_PROPERTY(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + "${SHADER_GENERATED_DIR}") + ADD_DEPENDENCIES(${EXAMPLE}.example ${EXAMPLE}-generate-shaders) + ENDIF() + TARGET_LINK_LIBRARIES(${EXAMPLE}.example ${REQUIRED_LIBS}) INSTALL(TARGETS ${EXAMPLE}.example DESTINATION ${BINDIR}) ENDFOREACH(EXAMPLE) diff --git a/build/tizen/shader-generator.sh b/build/tizen/shader-generator.sh deleted file mode 100755 index 5426fd2..0000000 --- a/build/tizen/shader-generator.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -# Set Colors -Red='\033[0;31m' # Red -Yellow='\033[0;33m' # Yellow -Blue='\033[0;34m' # Blue -Clear='\033[0m' # Text Reset - -######################################################################################### - -Usage() -{ - echo -e "${Yellow}Usage: $(basename ${BASH_SOURCE[0]}) [indir] [outdir] [OPTIONS]" - echo - echo -e " ${Blue}Mandatory parameters:${Clear}" - echo -e " indir The input directory where the original shader files are located" - echo -e " outdir The output directory where the header files for the shaders should be generated" - echo -e " ${Red}NOTE: All the above parameters must be provided${Clear}" - echo - echo -e " ${Blue}Options:${Clear}" - echo -e " -s|--skip Skip the generation of header and cpp files that include all the generated shader header files" - echo -e " -h|--help Help" -} - -if [ "$1" = "-h" ] || [ "$1" = "--help" ] -then - Usage - exit 0 -elif [ "$#" -lt 2 ] -then - echo -e "${Red}ERROR:${Clear} Mandatory parameters are not provided" - echo - Usage - exit 1 -fi - -######################################################################################### - -indir=$1 -outdir=$2 -skip="" - -for option in $* -do - if [ "$option" = "-s" ] || [ "$option" = "--skip" ] - then - skip="--skip" - continue - elif [[ $option == -* ]] - then - echo -e "${Red}Invalid Option: ${Blue}$option${Clear}" - echo - Usage - exit 1 - fi -done - -######################################################################################### - -mkdir -p $outdir - -if [ ! -e $indir ] ; then - echo "Error: The folder \""$indir"\" does not exist!" - exit 1 -fi - -cd $indir -all_shaders=$(ls -1 *.{vert,frag,def} 2>/dev/null) -cd $OLDPWD - -# Generate one header file per shader which is defined as a const std::string_view -for name in $all_shaders ; do - echo "Generating header files for $name..." - varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;') - - newname=$(echo ${name} | sed -e 's/\./-/;')".h" - echo Writing $newname - - shader_fullpath=$(echo ${indir})$name - - header_name="${varname}_GEN_H" - echo "const std::string_view" "$varname""{" > $outdir/$newname - cat $shader_fullpath | sed -e 's/^..*$/"&\\n"/' >> $outdir/$newname - echo "};" >> $outdir/$newname -done - -if [ "$skip" != "--skip" ]; then - # Generate one cpp file that includes all the previously generated string_views for shaders - echo "Generating cpp file..." - echo -e "#include \"../builtin-shader-extern-gen.h\"\n" > $outdir/builtin-shader-gen.cpp - - varnames= - for name in $all_shaders ; do - varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;') - newname=$(echo ${name} | sed -e 's/\./-/;')".h" - varnames="${varnames} $varname" - echo "#include \"$newname\"" >> $outdir/builtin-shader-gen.cpp - done - - # Generate one header file that defines all the shader string_views as extern variables - echo "Generating extern header file ( for external use )..." - echo "#ifndef GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H" > $outdir/../builtin-shader-extern-gen.h - echo -e "#define GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H\n" >> $outdir/../builtin-shader-extern-gen.h - - echo "#include " >> $outdir/../builtin-shader-extern-gen.h - echo "" >> $outdir/../builtin-shader-extern-gen.h - - for name in $all_shaders ; do - varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;') - newname=$(echo ${name} | sed -e 's/\./-/;')".h" - echo "extern const std::string_view $varname;" >> $outdir/../builtin-shader-extern-gen.h - done - cat >> $outdir/../builtin-shader-extern-gen.h << EOF - -#endif // GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H -EOF -fi - diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 8cf0fc8..622c301 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -55,6 +55,9 @@ + + + diff --git a/examples-reel/dali-examples-reel.cpp b/examples-reel/dali-examples-reel.cpp index 1f43d21..41de8e9 100644 --- a/examples-reel/dali-examples-reel.cpp +++ b/examples-reel/dali-examples-reel.cpp @@ -41,10 +41,12 @@ int DALI_EXPORT_API main(int argc, char** argv) demo.AddExample(Example("animated-images.example", DALI_DEMO_STR_TITLE_ANIMATED_IMAGES)); demo.AddExample(Example("animated-shapes.example", DALI_DEMO_STR_TITLE_ANIMATED_SHAPES)); demo.AddExample(Example("animated-vector-images.example", DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES)); + demo.AddExample(Example("animated-vector-images-rive.example", DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES_RIVE)); demo.AddExample(Example("arc-visual.example", DALI_DEMO_STR_TITLE_ARC_VISUAL)); demo.AddExample(Example("bloom-view.example", DALI_DEMO_STR_TITLE_BLOOM_VIEW)); demo.AddExample(Example("builder.example", DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI)); demo.AddExample(Example("buttons.example", DALI_DEMO_STR_TITLE_BUTTONS)); + demo.AddExample(Example("canvas-view.example", DALI_DEMO_STR_TITLE_CANVAS_VIEW)); demo.AddExample(Example("clipping.example", DALI_DEMO_STR_TITLE_CLIPPING)); demo.AddExample(Example("clipping-draw-order.example", DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER)); demo.AddExample(Example("color-transition.example", DALI_DEMO_STR_TITLE_COLOR_TRANSITION)); diff --git a/examples/animated-vector-images-rive/animated-vector-images-rive-example.cpp b/examples/animated-vector-images-rive/animated-vector-images-rive-example.cpp new file mode 100644 index 0000000..9f16ecd --- /dev/null +++ b/examples/animated-vector-images-rive/animated-vector-images-rive-example.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2021 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 +#include "shared/view.h" + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace +{ +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-gradient.jpg"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("Animated Vector Images Rive"); + +const char* IMAGE_PATH[] = { + DEMO_IMAGE_DIR "shape.riv", + }; + +const unsigned int NUMBER_OF_IMAGES = 1; + +enum CellPlacement +{ + TOP_BUTTON, + LOWER_BUTTON, + IMAGE, + NUMBER_OF_ROWS +}; + +unsigned int GetControlIndex(Control control) +{ + std::string controlName = control.GetProperty(Dali::Actor::Property::NAME); + unsigned int index = 0; + + if(controlName != "") + { + index = std::stoul(controlName); + } + + return index; +} + +} // namespace + +// This example shows the usage of AnimatedVectorImageVisual(Rive). +// It doesn't work on Ubuntu because the visual uses the external library to render frames. +class AnimatedVectorImageViewController : public ConnectionTracker +{ +public: + AnimatedVectorImageViewController(Application& application) + : mApplication(application) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect(this, &AnimatedVectorImageViewController::Create); + } + + void Create(Application& application) + { + // The Init signal is received once (only) during the Application lifetime + + // Creates a default view with a default tool bar. + // The view is added to the window. + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + APPLICATION_TITLE); + + // Create a table view to show a pair of buttons above each image. + mTable = TableView::New(CellPlacement::NUMBER_OF_ROWS, NUMBER_OF_IMAGES); + mTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mTable.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + Vector3 offset(0.9f, 0.70f, 0.0f); + mTable.SetProperty(Actor::Property::SIZE_MODE_FACTOR, offset); + mTable.SetFitHeight(CellPlacement::TOP_BUTTON); + mTable.SetFitHeight(CellPlacement::LOWER_BUTTON); + mContentLayer.Add(mTable); + + for(unsigned int x = 0; x < NUMBER_OF_IMAGES; x++) + { + mPlayButtons[x] = PushButton::New(); + mPlayButtons[x].SetProperty(Button::Property::LABEL, "Play"); + mPlayButtons[x].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mPlayButtons[x].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mPlayButtons[x].ClickedSignal().Connect(this, &AnimatedVectorImageViewController::OnPlayButtonClicked); + mPlayButtons[x].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mPlayButtons[x].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + std::string s = std::to_string(x); + mPlayButtons[x].SetProperty(Dali::Actor::Property::NAME, s); + mTable.AddChild(mPlayButtons[x], TableView::CellPosition(CellPlacement::TOP_BUTTON, x)); + + mStopButtons[x] = PushButton::New(); + mStopButtons[x].SetProperty(Button::Property::LABEL, "Stop"); + mStopButtons[x].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mStopButtons[x].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mStopButtons[x].ClickedSignal().Connect(this, &AnimatedVectorImageViewController::OnStopButtonClicked); + mStopButtons[x].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mStopButtons[x].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mStopButtons[x].SetProperty(Dali::Actor::Property::NAME, s); + mTable.AddChild(mStopButtons[x], TableView::CellPosition(CellPlacement::LOWER_BUTTON, x)); + + mImageViews[x] = ImageView::New(); + Property::Map imagePropertyMap; + imagePropertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); + imagePropertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATH[x]); + imagePropertyMap.Insert(DevelImageVisual::Property::LOOP_COUNT, 3); + mImageViews[x].SetProperty(ImageView::Property::IMAGE, imagePropertyMap); + + mImageViews[x].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageViews[x].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mImageViews[x].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mImageViews[x].SetProperty(Dali::Actor::Property::NAME, s); + + DevelControl::VisualEventSignal(mImageViews[x]).Connect(this, &AnimatedVectorImageViewController::OnVisualEvent); + + mTable.AddChild(mImageViews[x], TableView::CellPosition(CellPlacement::IMAGE, x)); + } + + application.GetWindow().KeyEventSignal().Connect(this, &AnimatedVectorImageViewController::OnKeyEvent); + } + +private: + bool OnPlayButtonClicked(Button button) + { + unsigned int controlIndex = GetControlIndex(button); + + ImageView imageView = mImageViews[controlIndex]; + + Property::Map map = imageView.GetProperty(ImageView::Property::IMAGE); + Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE); + + if(value) + { + if(value->Get() != static_cast(DevelImageVisual::PlayState::PLAYING)) + { + mPlayButtons[controlIndex].SetProperty(Button::Property::LABEL, "Pause"); + + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PLAY, Property::Value()); + } + else + { + mPlayButtons[controlIndex].SetProperty(Button::Property::LABEL, "Play"); + + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Value()); + } + } + + return true; + } + + bool OnStopButtonClicked(Button button) + { + unsigned int controlIndex = GetControlIndex(button); + ImageView imageView = mImageViews[controlIndex]; + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::STOP, Property::Value()); + + return true; + } + + void OnVisualEvent(Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId) + { + unsigned int controlIndex = GetControlIndex(control); + + if(visualIndex == ImageView::Property::IMAGE && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED) + { + mPlayButtons[controlIndex].SetProperty(Button::Property::LABEL, "Play"); + } + } + + /** + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event) + { + if(event.GetState() == KeyEvent::DOWN) + { + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) + { + mApplication.Quit(); + } + } + } + +private: + Application& mApplication; + + Control mView; ///< The View instance. + ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer + TableView mTable; + ImageView mImageViews[NUMBER_OF_IMAGES]; + PushButton mPlayButtons[NUMBER_OF_IMAGES]; + PushButton mStopButtons[NUMBER_OF_IMAGES]; +}; + +int DALI_EXPORT_API main(int argc, char** argv) +{ + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + AnimatedVectorImageViewController test(application); + application.MainLoop(); + return 0; +} diff --git a/examples/canvas-view/canvas-view-example.cpp b/examples/canvas-view/canvas-view-example.cpp new file mode 100644 index 0000000..16e95e3 --- /dev/null +++ b/examples/canvas-view/canvas-view-example.cpp @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2021 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 + +using namespace Dali; + +/** + * @brief This demonstrates how to display and control vector primitives using CanvasView. + * + * - It displays various types of shapes. Rectangle, circle, path, etc. + * - Each shape can be set to fill color, stroke color, width, etc + * and can change the transfomation(rotate, scale, translate) + */ +class CanvasViewController : public ConnectionTracker +{ +public: + /** + * @brief Constructor. + * @param[in] application A reference to the Application class + */ + CanvasViewController(Application& application) + : mApplication(application), + mRoundedRect(), + mArc(), + mStar(), + mTimer(), + mCount(0) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect(this, &CanvasViewController::Create); + } + + ~CanvasViewController() = default; + + void Create(Application& application) + { + // The Init signal is received once (only) during the Application lifetime + Window window = application.GetWindow(); + Vector2 windowSize = window.GetSize(); + window.KeyEventSignal().Connect(this, &CanvasViewController::OnKeyEvent); + + Toolkit::CanvasView mCanvasView = Toolkit::CanvasView::New(windowSize); + mCanvasView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCanvasView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCanvasView.SetProperty(Actor::Property::SIZE, windowSize); + + Dali::CanvasRenderer::Shape canvasBackground = Dali::CanvasRenderer::Shape::New(); + canvasBackground.AddRect(Rect(0.0f, 0.0f, windowSize.width, windowSize.height), Vector2::ZERO); + canvasBackground.SetFillColor(Vector4(1.0f, 1.0f, 1.0f, 1.0f)); + mCanvasView.AddDrawable(canvasBackground); + + Dali::CanvasRenderer::Shape shape1 = Dali::CanvasRenderer::Shape::New(); + shape1.AddRect(Rect(-50.0f, -50.0f, 100.0f, 100.0f), Vector2::ZERO); + shape1.SetFillColor(Vector4(0.0f, 0.5f, 0.0f, 0.5f)); + shape1.SetStrokeColor(Vector4(0.5f, 0.0f, 0.0f, 0.5f)); + shape1.SetStrokeWidth(10.0f); + shape1.Scale(1.2f); + shape1.Rotate(Degree(45.0f)); + shape1.Translate(Vector2(100.0f, 100.0f)); + + mCanvasView.AddDrawable(shape1); + + mRoundedRect = Dali::CanvasRenderer::Shape::New(); + mRoundedRect.AddRect(Rect(10.0f, 350.0f, 200.0f, 140.0f), Vector2(40.0f, 40.0f)); + mRoundedRect.SetFillColor(Vector4(0.0f, 0.0f, 1.0f, 1.0f)); + mRoundedRect.SetOpacity(0.5f); + mRoundedRect.SetStrokeColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + mRoundedRect.SetStrokeWidth(10.0f); + mRoundedRect.SetStrokeJoin(Dali::CanvasRenderer::Shape::StrokeJoin::MITER); + Dali::Vector dashPattern; + dashPattern.PushBack(15.0f); + dashPattern.PushBack(30.0f); + mRoundedRect.SetStrokeDash(dashPattern); + mCanvasView.AddDrawable(mRoundedRect); + + Dali::CanvasRenderer::Shape shape2 = Dali::CanvasRenderer::Shape::New(); + shape2.AddMoveTo(Vector2(535.0f, 135.0f)); + shape2.AddLineTo(Vector2(660.0f, 455.0f)); + shape2.AddLineTo(Vector2(355.0f, 250.0f)); + shape2.AddLineTo(Vector2(715.0f, 250.0f)); + shape2.AddLineTo(Vector2(410.0f, 455.0f)); + shape2.Close(); + shape2.SetFillRule(Dali::CanvasRenderer::Shape::FillRule::EVEN_ODD); + shape2.SetFillColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + shape2.SetOpacity(0.5f); + shape2.SetStrokeColor(Vector4(1.0f, 0.0f, 1.0f, 1.0f)); + shape2.SetStrokeWidth(20.0f); + shape2.SetStrokeJoin(Dali::CanvasRenderer::Shape::StrokeJoin::ROUND); + shape2.Transform(Matrix3(0.6f, 0.0f, 20.0f, 0.0f, 0.6f, -50.0f, 0.0f, 0.0f, 1.0f)); + mCanvasView.AddDrawable(shape2); + + mArc = Dali::CanvasRenderer::Shape::New(); + mArc.AddArc(Vector2(100.0f, 650.0f), 80.0f, 10.0f, 0.0f, true); + mArc.AddArc(Vector2(100.0f, 650.0f), 80.0f, 10.0f, 0.0f, true); + mArc.SetOpacity(0.5f); + mArc.SetStrokeColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + mArc.SetStrokeWidth(10.0f); + mArc.SetStrokeCap(Dali::CanvasRenderer::Shape::StrokeCap::ROUND); + mCanvasView.AddDrawable(mArc); + + mStar = Dali::CanvasRenderer::Shape::New(); + mStar.AddMoveTo(Vector2(-1.0f, -165.0f)); + mStar.AddLineTo(Vector2(53.0f, -56.0f)); + mStar.AddLineTo(Vector2(174.0f, -39.0f)); + mStar.AddLineTo(Vector2(87.0f, 45.0f)); + mStar.AddLineTo(Vector2(107.0f, 166.0f)); + mStar.AddLineTo(Vector2(-1.0f, 110.0f)); + mStar.AddLineTo(Vector2(-103.0f, 166.0f)); + mStar.AddLineTo(Vector2(-88.0f, 46.0f)); + mStar.AddLineTo(Vector2(-174.0f, -38.0f)); + mStar.AddLineTo(Vector2(-54.0f, -56.0f)); + + mStar.Close(); + + mStar.SetFillColor(Vector4(0.0f, 1.0f, 1.0f, 1.0f)); + mStar.SetStrokeColor(Vector4(0.5f, 1.0f, 0.5f, 1.0f)); + mStar.SetStrokeWidth(30.0f); + mStar.SetStrokeCap(Dali::CanvasRenderer::Shape::StrokeCap::ROUND); + mStar.Scale(0.6f); + mStar.Translate(Vector2(350.0f, 450.0f)); + mStar.SetOpacity(0.5f); + + mCanvasView.AddDrawable(mStar); + + mTimer = Timer::New(1000.0f / 32.0f); + mTimer.TickSignal().Connect(this, &CanvasViewController::tick); + mTimer.Start(); + + window.Add(mCanvasView); + } + + /** + * @brief Called when set time. + * + * Change transformation every call to make it look like vector animation. + */ + bool tick() + { + mRoundedRect.ResetPath(); + mRoundedRect.AddRect(Rect(10.0f, 350.0f, 200.0f, 140.0f), Vector2(float(mCount % 80), float(mCount % 80))); + + mArc.ResetPath(); + mArc.AddArc(Vector2(100.0f, 650.0f), 80.0f, 10.0f, float(mCount % 180), true); + mArc.AddArc(Vector2(100.0f, 650.0f), 80.0f, 10.0f + float(mCount % 180), float(mCount % 180) / 2.0f, true); + + mStar.Rotate(Degree(mCount * 2.0f)); + mStar.Scale(float(mCount % 100) * 0.01f + 0.6f); + mCount++; + return true; + } + + /** + * @brief Called when any key event is received. + * + * Will use this to quit the application if Back or the Escape key is received + * @param[in] event The key event information + */ + void OnKeyEvent(const KeyEvent& event) + { + if(event.GetState() == KeyEvent::DOWN) + { + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) + { + mApplication.Quit(); + } + } + } + +private: + Application& mApplication; + Dali::CanvasRenderer::Shape mRoundedRect; + Dali::CanvasRenderer::Shape mArc; + Dali::CanvasRenderer::Shape mStar; + Timer mTimer; + int mCount; +}; + +int DALI_EXPORT_API main(int argc, char** argv) +{ + Application application = Application::New(&argc, &argv); + CanvasViewController test(application); + application.MainLoop(); + return 0; +} diff --git a/examples/color-visual/color-visual-example.cpp b/examples/color-visual/color-visual-example.cpp index abca5fd..ca2f9d7 100644 --- a/examples/color-visual/color-visual-example.cpp +++ b/examples/color-visual/color-visual-example.cpp @@ -27,14 +27,15 @@ namespace { const char* IMAGE_FILE(DEMO_IMAGE_DIR "gallery-medium-1.jpg"); -const float CORNER_RADIUS_VALUE(30.0f); - const float BLUR_RADIUS_VALUE(15.0f); const Vector2 BLUR_OFFSET_VALUE(0.05f, 0.05f); const Vector2 BLUR_SIZE_VALUE(1.1f, 1.1f); const Vector2 NO_BLUR_SIZE_VALUE(1.05f, 1.05f); const float ANIMATION_DURATION(2.0f); +constexpr Vector4 CORNER_RADIUS_VALUE(30.0f, 30.0f, 30.0f, 30.0f); +constexpr Vector4 SHADOW_CORNER_RADIUS_VALUE(33.0f, 33.0f, 33.0f, 33.0f); + const Property::Value SHADOW{ {Visual::Property::TYPE, Visual::COLOR}, {Visual::Property::MIX_COLOR, Vector4(0.0f, 0.0f, 0.0f, 0.5f)}, @@ -96,7 +97,7 @@ public: animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, ImageView::Property::IMAGE, Visual::Property::OPACITY), 0.5f); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, ImageView::Property::IMAGE, DevelVisual::Property::CORNER_RADIUS), CORNER_RADIUS_VALUE); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, ColorVisual::Property::MIX_COLOR), Vector3(0.0f, 0.0f, 1.0f)); - animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, DevelVisual::Property::CORNER_RADIUS), CORNER_RADIUS_VALUE * BLUR_SIZE_VALUE.x / NO_BLUR_SIZE_VALUE.x); + animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, DevelVisual::Property::CORNER_RADIUS), SHADOW_CORNER_RADIUS_VALUE); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, DevelColorVisual::Property::BLUR_RADIUS), BLUR_RADIUS_VALUE); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, Visual::Transform::Property::OFFSET), BLUR_OFFSET_VALUE); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, Visual::Transform::Property::SIZE), BLUR_SIZE_VALUE); @@ -105,9 +106,9 @@ public: { animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, ImageView::Property::IMAGE, Visual::Property::MIX_COLOR), Vector3(1.0f, 1.0f, 1.0f)); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, ImageView::Property::IMAGE, Visual::Property::OPACITY), 1.0f); - animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, ImageView::Property::IMAGE, DevelVisual::Property::CORNER_RADIUS), 0.0f); + animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, ImageView::Property::IMAGE, DevelVisual::Property::CORNER_RADIUS), Vector4::ZERO); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, ColorVisual::Property::MIX_COLOR), Vector3(0.0f, 0.0f, 0.0f)); - animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, DevelVisual::Property::CORNER_RADIUS), 0.0f); + animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, DevelVisual::Property::CORNER_RADIUS), Vector4::ZERO); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, DevelColorVisual::Property::BLUR_RADIUS), 0.0f); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, Visual::Transform::Property::OFFSET), Vector2::ZERO); animation.AnimateTo(DevelControl::GetVisualProperty(mImageView, DevelControl::Property::SHADOW, Visual::Transform::Property::SIZE), NO_BLUR_SIZE_VALUE); diff --git a/examples/gradients/gradients-example.cpp b/examples/gradients/gradients-example.cpp index 77abb2c..5d57114 100644 --- a/examples/gradients/gradients-example.cpp +++ b/examples/gradients/gradients-example.cpp @@ -33,7 +33,7 @@ const char* const CHANGE_ICON_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png" const char* const ROUNDED_CORNER_ICON(DEMO_IMAGE_DIR "icon-replace.png"); const char* const ROUNDED_CORNER_ICON_SELECTED(DEMO_IMAGE_DIR "icon-replace-selected.png"); -const float CORNER_RADIUS_VALUE(20.0f); +constexpr Vector4 CORNER_RADIUS_VALUE(20.0f, 20.0f, 20.0f, 20.0f); } // namespace @@ -119,7 +119,7 @@ public: stopColors.PushBack(Color::YELLOW); mGradientMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors); - mGradientMap.Insert(DevelVisual::Property::CORNER_RADIUS, mRoundedCorner ? CORNER_RADIUS_VALUE : 0.0f); + mGradientMap.Insert(DevelVisual::Property::CORNER_RADIUS, mRoundedCorner ? CORNER_RADIUS_VALUE : Vector4::ZERO); UpdateGradientMap(); } @@ -142,7 +142,7 @@ public: } else { - animation.AnimateTo(DevelControl::GetVisualProperty(mGradientControl, Control::Property::BACKGROUND, DevelVisual::Property::CORNER_RADIUS), 0.0f); + animation.AnimateTo(DevelControl::GetVisualProperty(mGradientControl, Control::Property::BACKGROUND, DevelVisual::Property::CORNER_RADIUS), Vector4::ZERO); } animation.Play(); diff --git a/examples/reflection-demo/gltf-scene.cpp b/examples/reflection-demo/gltf-scene.cpp index d752149..9b5a67f 100644 --- a/examples/reflection-demo/gltf-scene.cpp +++ b/examples/reflection-demo/gltf-scene.cpp @@ -163,6 +163,8 @@ void glTF::LoadFromFile(const std::string& filename) mBuffer = LoadFile(binFile); jsonBuffer = LoadFile(jsonFile); + jsonBuffer.push_back('\0'); // It should be null terminated. + // Log errors if(mBuffer.empty()) { diff --git a/packaging/com.samsung.dali-demo.spec b/packaging/com.samsung.dali-demo.spec index 7d66c48..45cb127 100755 --- a/packaging/com.samsung.dali-demo.spec +++ b/packaging/com.samsung.dali-demo.spec @@ -2,7 +2,7 @@ Name: com.samsung.dali-demo Summary: The OpenGLES Canvas Core Demo -Version: 2.0.21 +Version: 2.0.25 Release: 1 Group: System/Libraries License: Apache-2.0 diff --git a/resources/images/shape.riv b/resources/images/shape.riv new file mode 100644 index 0000000..2450a94 --- /dev/null +++ b/resources/images/shape.riv diff --git a/resources/po/en_GB.po b/resources/po/en_GB.po index 8fd4410..3cca600 100755 --- a/resources/po/en_GB.po +++ b/resources/po/en_GB.po @@ -28,6 +28,9 @@ msgstr "Bubbles" msgid "DALI_DEMO_STR_TITLE_BUTTONS" msgstr "Buttons" +msgid "DALI_DEMO_STR_TITLE_CANVAS_VIEW" +msgstr "Canvas view" + msgid "DALI_DEMO_STR_TITLE_CALL_ACTIVE" msgstr "Call Active" @@ -294,3 +297,6 @@ msgstr "Web View" msgid "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES" msgstr "Animated Vector Images" + +msgid "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES_RIVE" +msgstr "Animated Vector Images Rive" diff --git a/resources/po/en_US.po b/resources/po/en_US.po index ea7c328..5fe6a68 100755 --- a/resources/po/en_US.po +++ b/resources/po/en_US.po @@ -28,6 +28,9 @@ msgstr "Bubbles" msgid "DALI_DEMO_STR_TITLE_BUTTONS" msgstr "Buttons" +msgid "DALI_DEMO_STR_TITLE_CANVAS_VIEW" +msgstr "Canvas view" + msgid "DALI_DEMO_STR_TITLE_CALL_ACTIVE" msgstr "Call Active" @@ -295,6 +298,9 @@ msgstr "Web View" msgid "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES" msgstr "Animated Vector Images" +msgid "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES_RIVE" +msgstr "Animated Vector Images Rive" + msgid "DALI_DEMO_STR_TITLE_TEXT_RENDERER" msgstr "Text Renderer" diff --git a/resources/po/ko.po b/resources/po/ko.po index d96a77d..c56be6f 100755 --- a/resources/po/ko.po +++ b/resources/po/ko.po @@ -192,3 +192,6 @@ msgstr "PBR" msgid "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES" msgstr "애니메이션 벡터 이미지" + +msgid "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES_RIVE" +msgstr "애니메이션 벡터 이미지 라이브" diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index 1f411e3..323b5e0 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -37,6 +37,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES") #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES") #define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES") +#define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES_RIVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES_RIVE") #define DALI_DEMO_STR_TITLE_ARC_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ARC_VISUAL") #define DALI_DEMO_STR_TITLE_BASIC_LIGHT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BASIC_LIGHT") #define DALI_DEMO_STR_TITLE_BENCHMARK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BENCHMARK") @@ -45,6 +46,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_BLOOM_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOOM_VIEW") #define DALI_DEMO_STR_TITLE_BUBBLES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUBBLES") #define DALI_DEMO_STR_TITLE_BUTTONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUTTONS") +#define DALI_DEMO_STR_TITLE_CANVAS_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CANVAS_VIEW") #define DALI_DEMO_STR_TITLE_CALL_ACTIVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CALL_ACTIVE") #define DALI_DEMO_STR_TITLE_CARD_ACTIVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CARD_ACTIVE") #define DALI_DEMO_STR_TITLE_CLIPPING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CLIPPING") @@ -142,6 +144,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES "Animated Images" #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES "Animated Shapes" #define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES "Animated Vector Images" +#define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES_RIVE "Animated Vector Images Rive" #define DALI_DEMO_STR_TITLE_ARC_VISUAL "Arc Visual" #define DALI_DEMO_STR_TITLE_BASIC_LIGHT "Basic Light" #define DALI_DEMO_STR_TITLE_BENCHMARK "ImageView Benchmark" @@ -150,6 +153,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_BLOOM_VIEW "Bloom" #define DALI_DEMO_STR_TITLE_BUBBLES "Bubbles" #define DALI_DEMO_STR_TITLE_BUTTONS "Buttons" +#define DALI_DEMO_STR_TITLE_CANVAS_VIEW "Canvas View" #define DALI_DEMO_STR_TITLE_CALL_ACTIVE "Call Active" #define DALI_DEMO_STR_TITLE_CARD_ACTIVE "Card Active" #define DALI_DEMO_STR_TITLE_CLIPPING "Clipping"