diff --git a/builder/dali-builder.cpp b/builder/dali-builder.cpp index 4481c3d..5445fd1 100644 --- a/builder/dali-builder.cpp +++ b/builder/dali-builder.cpp @@ -27,6 +27,7 @@ //------------------------------------------------------------------------------ #include +#include #include #include #include @@ -102,10 +103,16 @@ private: std::time_t mLastTime; std::string mstringPath; - std::string GetFileContents(const std::string &fn) + std::string GetFileContents(const std::string &filename) { - std::ifstream t(fn.c_str()); - return std::string((std::istreambuf_iterator(t)), std::istreambuf_iterator()); + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) + { + return std::string(); + } + + return std::string( &fileBuffer[0], bufferSize ); }; }; diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 85fcc28..5d2901b 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -296,6 +296,15 @@ + + + + + + + + + http://tizen.org/privilege/mediastorage diff --git a/examples-reel/dali-examples-reel.cpp b/examples-reel/dali-examples-reel.cpp index 445a45c..92d05e9 100644 --- a/examples-reel/dali-examples-reel.cpp +++ b/examples-reel/dali-examples-reel.cpp @@ -50,6 +50,7 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("flex-container.example", DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND)); demo.AddExample(Example("frame-callback.example", DALI_DEMO_STR_TITLE_FRAME_CALLBACK)); demo.AddExample(Example("focus-integration.example", DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION)); + demo.AddExample(Example("gaussian-blur-view.example", DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW)); demo.AddExample(Example("gestures.example", DALI_DEMO_STR_TITLE_GESTURES)); demo.AddExample(Example("gradients.example", DALI_DEMO_STR_TITLE_COLOR_GRADIENT)); demo.AddExample(Example("hello-world.example", DALI_DEMO_STR_TITLE_HELLO_WORLD)); @@ -80,6 +81,7 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("scroll-view.example", DALI_DEMO_STR_TITLE_SCROLL_VIEW)); demo.AddExample(Example("size-negotiation.example", DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE)); demo.AddExample(Example("styling.example", DALI_DEMO_STR_TITLE_STYLING)); + demo.AddExample(Example("super-blur-view.example", DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW)); demo.AddExample(Example("text-editor.example", DALI_DEMO_STR_TITLE_TEXT_EDITOR)); demo.AddExample(Example("text-field.example", DALI_DEMO_STR_TITLE_TEXT_FIELD)); demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); diff --git a/examples/builder/examples.cpp b/examples/builder/examples.cpp index ba47e28..e022227 100644 --- a/examples/builder/examples.cpp +++ b/examples/builder/examples.cpp @@ -43,6 +43,7 @@ #include #include +#include #include "shared/view.h" #define TOKEN_STRING(x) #x @@ -86,9 +87,14 @@ std::string ReplaceQuotes(const std::string &single_quoted) std::string GetFileContents(const std::string &fn) { - std::ifstream t(fn.c_str()); - return std::string((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( fn, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) + { + return std::string(); + } + + return std::string( &fileBuffer[0], bufferSize ); }; typedef std::vector FileList; diff --git a/examples/fpp-game/game-utils.cpp b/examples/fpp-game/game-utils.cpp index 8cb99f1..1f3f502 100644 --- a/examples/fpp-game/game-utils.cpp +++ b/examples/fpp-game/game-utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -17,6 +17,8 @@ #include #include +#include +#include #include "game-utils.h" @@ -24,25 +26,25 @@ namespace GameUtils { bool LoadFile( const char* filename, ByteArray& bytes ) { - FILE* fin = fopen( filename, "rb" ); + Dali::FileStream fileStream( filename, Dali::FileStream::READ | Dali::FileStream::BINARY ); + FILE* fin = fileStream.GetFile(); + if( fin ) { if( fseek( fin, 0, SEEK_END ) ) { - fclose(fin); return false; } bytes.resize( ftell( fin ) ); std::fill( bytes.begin(), bytes.end(), 0 ); if( fseek( fin, 0, SEEK_SET ) ) { - fclose( fin ); return false; } size_t result = fread( bytes.data(), 1, bytes.size(), fin ); - fclose( fin ); return ( result != 0 ); } + return false; } diff --git a/examples/gaussian-blur-view/gaussian-blur-view-example.cpp b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp new file mode 100644 index 0000000..6c68f69 --- /dev/null +++ b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2019 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; +using Dali::Toolkit::TextLabel; +using Dali::Toolkit::GaussianBlurView; + +namespace +{ + +const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" ); +const float BACKGROUND_IMAGE_WIDTH = 2048.0f; + +} + +/** + * This example shows a scrolling background image which can be blurred (on/off) by tapping the screen + */ +class GaussianBlurViewExample : public ConnectionTracker +{ +public: + + GaussianBlurViewExample( Application& application ) + : mApplication( application ), + mExcessWidth( 0.0f ), + mStrength( 1.0f ) + { + mApplication.InitSignal().Connect( this, &GaussianBlurViewExample::Create ); + } + + ~GaussianBlurViewExample() = default; + +private: + + void Create( Application& application ) + { + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + stage.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent); + + mImageView = Toolkit::ImageView::New( BACKGROUND_IMAGE ); + mImageView.SetParentOrigin( ParentOrigin::CENTER ); + mImageView.SetAnchorPoint( AnchorPoint::CENTER ); + + stage.Add( mImageView ); + + float excessWidth = std::max( 0.0f, (BACKGROUND_IMAGE_WIDTH - stageSize.width) * 0.5f ); + + if( excessWidth > 0.0f ) + { + // Move background image to show GaussianBlurView activity + + float pixelsPerSecond = 10.0f; + float duration = excessWidth / pixelsPerSecond; + float qDuration = duration * 0.25f; + + mAnimation = Animation::New( duration ); + mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), excessWidth, TimePeriod(0.0f , qDuration) ); + mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(qDuration , qDuration) ); + mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), -excessWidth, TimePeriod(2.0f*qDuration, qDuration) ); + mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(3.0f*qDuration, qDuration) ); + + mAnimation.SetLooping( true ); + mAnimation.Play(); + } + + Layer onTop = Layer::New(); + onTop.SetParentOrigin( ParentOrigin::CENTER ); + onTop.SetAnchorPoint( AnchorPoint::CENTER ); + onTop.SetSize( stageSize ); + stage.Add( onTop ); + onTop.RaiseToTop(); + + mOnLabel = TextLabel::New( "Blur ON" ); + mOnLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mOnLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::GREEN ); + mOnLabel.SetVisible( false ); + onTop.Add( mOnLabel ); + + mOffLabel = TextLabel::New( "Blur OFF" ); + mOffLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mOffLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); + mOffLabel.SetVisible( true ); + onTop.Add( mOffLabel ); + + stage.GetRootLayer().TouchSignal().Connect( this, &GaussianBlurViewExample::OnTouch ); + } + + bool OnTouch( Actor actor, const TouchData& touch ) + { + const PointState::Type state = touch.GetState( 0 ); + + if( PointState::DOWN == state ) + { + Stage stage = Stage::GetCurrent(); + + // Enable/disable blur effect + + if( !mGaussianBlurView ) + { + mGaussianBlurView = GaussianBlurView::New( 30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false ); + mGaussianBlurView.SetParentOrigin( ParentOrigin::CENTER ); + mGaussianBlurView.SetAnchorPoint( AnchorPoint::CENTER ); + mGaussianBlurView.SetSize( stage.GetSize() ); + stage.Add( mGaussianBlurView ); + + mGaussianBlurView.Add( mImageView ); + mGaussianBlurView.Activate(); + + mGaussianBlurView.SetProperty( mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength ); + + mOnLabel.SetVisible( true ); + mOffLabel.SetVisible( false ); + } + else + { + stage.Add( mImageView ); + + UnparentAndReset( mGaussianBlurView ); + + mOnLabel.SetVisible( false ); + mOffLabel.SetVisible( true ); + } + + } + + return true; + } + + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + +private: + + Application& mApplication; + + Toolkit::ImageView mImageView; + + Animation mAnimation; + + TextLabel mOnLabel; + TextLabel mOffLabel; + + GaussianBlurView mGaussianBlurView; + + float mExcessWidth; + float mStrength; +}; + +int DALI_EXPORT_API main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + GaussianBlurViewExample test( application ); + + application.MainLoop(); + + return 0; +} diff --git a/examples/ray-marching/ray-marching-example.cpp b/examples/ray-marching/ray-marching-example.cpp index d638217..2a7b959 100644 --- a/examples/ray-marching/ray-marching-example.cpp +++ b/examples/ray-marching/ray-marching-example.cpp @@ -20,6 +20,8 @@ #include "shared/view.h" #include "shared/utility.h" #include +#include +#include using namespace Dali; using Dali::Toolkit::TextLabel; @@ -41,14 +43,16 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& { std::string fullpath( path ); fullpath += filename; - FILE* file = fopen( fullpath.c_str(), "rb" ); - if( ! file ) + + Dali::FileStream fileStream( fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY ); + FILE* file = fileStream.GetFile(); + if( !file ) { return false; } bool retValue = false; - if( ! fseek( file, 0, SEEK_END ) ) + if( !fseek( file, 0, SEEK_END ) ) { long int size = ftell( file ); @@ -63,7 +67,6 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& } } - fclose( file ); return retValue; } diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index 14c4878..ffbc59a 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -19,8 +19,9 @@ #include #include #include +#include +#include -#include #include #include @@ -471,14 +472,22 @@ private: std::vector& vertexPositions, Vector& faceIndices) { - std::ifstream ifs( objFileName.c_str(), std::ios::in ); + std::streampos bufferSize = 0; + Dali::Vector fileBuffer; + if( !Dali::FileLoader::ReadFile( objFileName, bufferSize, fileBuffer, Dali::FileLoader::FileType::TEXT ) ) + { + DALI_LOG_WARNING( "file open failed for: \"%s\"", objFileName ); + return; + } + + std::stringstream iss( &fileBuffer[0], std::ios::in ); boundingBox.Resize( 6 ); boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits::max(); boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits::max(); std::string line; - while( std::getline( ifs, line ) ) + while( std::getline( iss, line ) ) { if( line[0] == 'v' && std::isspace(line[1])) // vertex { @@ -518,8 +527,6 @@ private: faceIndices.PushBack( indices[2*step]-1 ); } } - - ifs.close(); } void ShapeResizeAndTexureCoordinateCalculation( const Vector& boundingBox, diff --git a/examples/rendering-basic-pbr/ktx-loader.cpp b/examples/rendering-basic-pbr/ktx-loader.cpp index 175d6c3..579724e 100644 --- a/examples/rendering-basic-pbr/ktx-loader.cpp +++ b/examples/rendering-basic-pbr/ktx-loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -22,6 +22,8 @@ #include #include #include +#include +#include namespace PbrDemo { @@ -92,8 +94,8 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& form bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) { - FILE* fp = fopen(path.c_str(),"rb"); - + Dali::FileStream fileStream( path, Dali::FileStream::READ | Dali::FileStream::BINARY ); + FILE* fp = fileStream.GetFile(); if( NULL == fp ) { return false; @@ -104,7 +106,6 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) int result = fread(&header,1,sizeof(KtxFileHeader),fp); if( 0 == result ) { - fclose( fp ); return false; } @@ -115,14 +116,12 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) if( fseek(fp, imageSizeOffset, SEEK_END) ) { - fclose( fp ); return false; } lSize = ftell(fp); if( lSize == -1L ) { - fclose( fp ); return false; } @@ -130,7 +129,6 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) if( fseek(fp, imageSizeOffset, SEEK_SET) ) { - fclose( fp ); return false; } diff --git a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp index 931f5fb..1239401 100644 --- a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp +++ b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -25,6 +25,8 @@ #include "ktx-loader.h" #include "model-skybox.h" #include "model-pbr.h" +#include +#include using namespace Dali; using namespace Toolkit; @@ -390,7 +392,8 @@ public: */ bool LoadShaderCode( const std::string& fullpath, std::vector& output ) { - FILE* file = fopen( fullpath.c_str(), "rb" ); + Dali::FileStream fileStream( fullpath, FileStream::READ | FileStream::BINARY ); + FILE* file = fileStream.GetFile(); if( NULL == file ) { return false; @@ -411,7 +414,7 @@ public: retValue = ( result >= 0 ); } } - fclose( file ); + return retValue; } diff --git a/examples/simple-text-renderer/simple-text-renderer-example.cpp b/examples/simple-text-renderer/simple-text-renderer-example.cpp index 3f8116f..c980170 100644 --- a/examples/simple-text-renderer/simple-text-renderer-example.cpp +++ b/examples/simple-text-renderer/simple-text-renderer-example.cpp @@ -26,9 +26,6 @@ #include #include -#include -#include - using namespace std; using namespace Dali; using namespace Dali::Toolkit; diff --git a/examples/super-blur-view/super-blur-view-example.cpp b/examples/super-blur-view/super-blur-view-example.cpp new file mode 100644 index 0000000..d90b248 --- /dev/null +++ b/examples/super-blur-view/super-blur-view-example.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2019 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; +using Dali::Toolkit::Button; +using Dali::Toolkit::PushButton; +using Dali::Toolkit::SuperBlurView; + +namespace +{ + +const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-4.jpg" ); + +const unsigned int DEFAULT_BLUR_LEVEL(5u); ///< The default blur level when creating SuperBlurView from the type registry + +} + +/** + * This example shows a background image which is "super blurred" while the push-button control is pressed. + */ +class SuperBlurViewExample : public ConnectionTracker +{ +public: + + SuperBlurViewExample( Application& application ) + : mApplication( application ) + { + mApplication.InitSignal().Connect( this, &SuperBlurViewExample::Create ); + } + + ~SuperBlurViewExample() = default; + +private: + + void Create( Application& application ) + { + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect( this, &SuperBlurViewExample::OnKeyEvent ); + + mSuperBlurView = SuperBlurView::New( DEFAULT_BLUR_LEVEL ); + mSuperBlurView.SetParentOrigin( ParentOrigin::CENTER ); + mSuperBlurView.SetAnchorPoint( AnchorPoint::CENTER ); + mSuperBlurView.SetSize( 800, 1280 ); + mSuperBlurView.SetProperty( SuperBlurView::Property::IMAGE_URL, BACKGROUND_IMAGE ); + stage.Add( mSuperBlurView ); + + mBlurAnimation = Animation::New(1.0f); + mBlurAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 1.0f ); + + mClearAnimation = Animation::New(1.0f); + mClearAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 0.0f ); + + mPushButton = PushButton::New(); + mPushButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + mPushButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + mPushButton.SetProperty( Button::Property::LABEL_TEXT, "Blur" ); + mPushButton.PressedSignal().Connect( this, &SuperBlurViewExample::OnButtonPressed ); + mPushButton.ReleasedSignal().Connect( this, &SuperBlurViewExample::OnButtonReleased ); + stage.Add( mPushButton ); + } + + bool OnButtonPressed( Button button ) + { + mBlurAnimation.Play(); + return true; + } + + bool OnButtonReleased( Button button ) + { + mClearAnimation.Play(); + return true; + } + + void OnKeyEvent( const KeyEvent& event ) + { + if ( event.state == KeyEvent::Down ) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + +private: + + Application& mApplication; + + SuperBlurView mSuperBlurView; + + PushButton mPushButton; + + Animation mBlurAnimation; + Animation mClearAnimation; +}; + +int DALI_EXPORT_API main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + SuperBlurViewExample test( application ); + + application.MainLoop(); + + return 0; +} diff --git a/examples/visual-fitting-mode/visual-fitting-mode-example.cpp b/examples/visual-fitting-mode/visual-fitting-mode-example.cpp new file mode 100644 index 0000000..7873d32 --- /dev/null +++ b/examples/visual-fitting-mode/visual-fitting-mode-example.cpp @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2019 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; +using namespace Dali::Toolkit; + +namespace +{ +const char * const IMAGE_NAME = DEMO_IMAGE_DIR "gallery-medium-1.jpg"; ///< The image to use. +const Vector3 IMAGE_SIZE = Vector3( 300, 200, 0 ); ///< The size of the image-views. + +const float BORDER_SIZE = 2.0f; ///< The size of the border. +const Property::Value BORDER ///< The border to use for each image-view. +{ + { Visual::Property::TYPE, Visual::BORDER }, + { BorderVisual::Property::COLOR, Color::RED }, + { BorderVisual::Property::SIZE, BORDER_SIZE } +}; +const Extents LARGE_PADDING( 100.0f, 100.0f, 2.0f, 2.0f ); ///< The large padding extents. +const Extents BORDER_ONLY_PADDING( BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE ); ///< The border only padding extents. + +const std::string INSTRUCTIONS_TEXT = "\n(Tap or Key Press To Change)"; ///< Instructions on how to change the padding mode. +const std::string LARGE_PADDING_TEXT( "Padding: Left/Right Large" + INSTRUCTIONS_TEXT ); ///< Label to shown when large padding enabled. +const std::string BORDER_ONLY_PADDING_TEXT( "Padding: Border Only" + INSTRUCTIONS_TEXT ); ///< Label to shown when border-only padding enabled. +const std::string FILL_LABEL( "FILL" ); +const std::string FIT_KEEP_ASPECT_LABEL( "FIT\nKEEP ASPECT" ); + +const Property::Map TEXT_LABEL_PROPERTIES ///< All the properties of the Large Text Label shown in the example. +{ + { Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER }, + { Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER }, + { Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT }, + { Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT }, + { Control::Property::BACKGROUND, + { + { Toolkit::Visual::Property::TYPE, Visual::GRADIENT }, + { GradientVisual::Property::STOP_COLOR, Property::Array{ Vector4( 167.0f, 207.0f, 223.0f, 255.0f ) / 255.0f, + Vector4( 0.0f, 64.0f, 137.0f, 255.0f ) / 255.0f } }, + { GradientVisual::Property::START_POSITION, Vector2( 0.0f, -0.5f ) }, + { GradientVisual::Property::END_POSITION, Vector2( 0.0f, 0.5f ) } + } + }, + { TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER }, + { TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER }, + { TextLabel::Property::MULTI_LINE, true } +}; + +const Property::Map FILL_IMAGE_PROPERTIES ///< The basic properties of the Fill image view. +{ + { Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER }, + { Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER }, + { Actor::Property::SIZE, IMAGE_SIZE }, + { Control::Property::BACKGROUND, BORDER } +}; + +const Property::Map FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES ///< The basic properties of the Fit Keep Aspect image view. +{ + { Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER }, + { Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER }, + { Actor::Property::SIZE, IMAGE_SIZE }, + { Control::Property::BACKGROUND, BORDER } +}; + +const Property::Map OVERLAY_LABEL_PROPERTIES ///< The image view overlay label properties +{ + { TextLabel::Property::TEXT_COLOR, Color::WHITE }, + { TextLabel::Property::OUTLINE, { { "color", Color::BLACK }, { "width", 1.0f } } }, + { TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER }, + { TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER }, + { TextLabel::Property::MULTI_LINE, true }, +}; +} // unnamed namespace + +/** + * @brief This example shows how to use the Dali::Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE property. + */ +class VisualFittingModeController : public ConnectionTracker +{ +public: + + /** + * @brief Constructor. + * @param[in] application A reference to the Application class. + */ + VisualFittingModeController( Application& application ) + : mApplication( application ), + mLargePadding( true ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &VisualFittingModeController::Create ); + } + +private: + + /** + * @brief Called to initialise the application content + * @param[in] application A reference to the Application class. + */ + void Create( Application& application ) + { + // Get a handle to the stage + Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Color::WHITE ); + + // Text Label filling the entire screen, with a background + mTextLabel = DevelHandle::New< TextLabel >( TEXT_LABEL_PROPERTIES ); + stage.Add( mTextLabel ); + + // We want to change the padding when tapping + mTapDetector = TapGestureDetector::New(); + mTapDetector.Attach( mTextLabel ); + mTapDetector.DetectedSignal().Connect( this, &VisualFittingModeController::OnTap ); + + // Create an ImageView with the default behaviour, i.e. image fills to control size + mFillImage = ImageView::New( IMAGE_NAME ); + DevelHandle::SetProperties( mFillImage, FILL_IMAGE_PROPERTIES ); + stage.Add( mFillImage ); + + // Create an ImageView that Keeps the aspect ratio while fitting within the given size + mFitKeepAspectRatioImage = DevelHandle::New< ImageView >( FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES ); + mFitKeepAspectRatioImage.SetProperty( ImageView::Property::IMAGE, + Property::Map + { + { Visual::Property::TYPE, Visual::IMAGE }, + { ImageVisual::Property::URL, IMAGE_NAME }, + { DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FIT_KEEP_ASPECT_RATIO } + } ); + stage.Add( mFitKeepAspectRatioImage ); + + // Create an overlay label for fill image + Actor fillLabel = TextLabel::New( FILL_LABEL ); + DevelHandle::SetProperties( fillLabel, FILL_IMAGE_PROPERTIES ); + DevelHandle::SetProperties( fillLabel, OVERLAY_LABEL_PROPERTIES ); + stage.Add( fillLabel ); + + // Create an overlay label for the Fit/Keep Aspect image + Actor fitLabel = TextLabel::New( FIT_KEEP_ASPECT_LABEL ); + DevelHandle::SetProperties( fitLabel, FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES ); + DevelHandle::SetProperties( fitLabel, OVERLAY_LABEL_PROPERTIES ); + stage.Add( fitLabel ); + + // Respond to key events, exit if ESC/Back, change the padding if anything else + stage.KeyEventSignal().Connect( this, &VisualFittingModeController::OnKeyEvent ); + + // Set the initial padding + ChangePadding(); + } + + /** + * @brief Changes the padding of both image-views to show how the VisualFittingMode is applied. + */ + void ChangePadding() + { + mLargePadding = !mLargePadding; + + const Extents padding( mLargePadding ? LARGE_PADDING : BORDER_ONLY_PADDING ); + mFitKeepAspectRatioImage.SetProperty( Control::Property::PADDING, padding ); + mFillImage.SetProperty( Control::Property::PADDING, padding ); + + mTextLabel.SetProperty( TextLabel::Property::TEXT, mLargePadding ? LARGE_PADDING_TEXT : BORDER_ONLY_PADDING_TEXT ); + } + + /** + * @brief Called when the main text-label is tapped. + * + * We just want to change the padding when this happens. + */ + void OnTap( Actor /* actor */, const TapGesture& /* tap */ ) + { + ChangePadding(); + } + + /** + * @brief Called when any key event is received + * + * Will use this to quit the application if we receive the Back or the Escape key & change + * the padding if any other key. + * @param[in] event The key event information + */ + void OnKeyEvent( const KeyEvent& event ) + { + if( event.state == KeyEvent::Down ) + { + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + else + { + ChangePadding(); + } + } + } + +private: + Application& mApplication; ///< Reference to the application class. + Actor mFillImage; ///< An image-view that fills to the control size. + Actor mFitKeepAspectRatioImage; ///< An image-view that fits within the given size & keeps the aspect ratio. + Actor mTextLabel; ///< A text label to show the current padding mode. + TapGestureDetector mTapDetector; ///< A tap detector to change the padding mode. + bool mLargePadding; ///< If true, the large padding values are used. When false, only the border padding is applied. +}; + +int DALI_EXPORT_API main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + VisualFittingModeController visualFittingModeController( application ); + application.MainLoop(); + return 0; +} diff --git a/packaging/com.samsung.dali-demo.spec b/packaging/com.samsung.dali-demo.spec index 2499398..bf1ceee 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: 1.4.27 +Version: 1.4.28 Release: 1 Group: System/Libraries License: Apache-2.0 diff --git a/resources/po/en_GB.po b/resources/po/en_GB.po index cf46d29..cff2764 100755 --- a/resources/po/en_GB.po +++ b/resources/po/en_GB.po @@ -40,6 +40,9 @@ msgstr "Clipping" msgid "DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER" msgstr "Clipping Draw Order" +msgid "DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW" +msgstr "Gaussian Blur" + msgid "DALI_DEMO_STR_TITLE_GESTURES" msgstr "Gestures" @@ -181,6 +184,9 @@ msgstr "Sparkle" msgid "DALI_DEMO_STR_TITLE_STYLING" msgstr "Styling" +msgid "DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW" +msgstr "Super Blur" + msgid "DALI_DEMO_STR_TITLE_TEXTURED_MESH" msgstr "Mesh Texture" @@ -217,6 +223,9 @@ msgstr "Tooltip" msgid "DALI_DEMO_STR_TITLE_FPP_GAME" msgstr "FPP Game" +msgid "DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE" +msgstr "Visual Fitting Mode" + msgid "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS" msgstr "Visual Transitions" diff --git a/resources/po/en_US.po b/resources/po/en_US.po index b40c673..4e8a9c8 100755 --- a/resources/po/en_US.po +++ b/resources/po/en_US.po @@ -40,6 +40,9 @@ msgstr "Clipping" msgid "DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER" msgstr "Clipping Draw Order" +msgid "DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW" +msgstr "Gaussian Blur" + msgid "DALI_DEMO_STR_TITLE_GESTURES" msgstr "Gestures" @@ -184,6 +187,9 @@ msgstr "Sparkle" msgid "DALI_DEMO_STR_TITLE_STYLING" msgstr "Styling" +msgid "DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW" +msgstr "Super Blur" + msgid "DALI_DEMO_STR_TITLE_TEXTURED_MESH" msgstr "Mesh Texture" @@ -220,6 +226,9 @@ msgstr "Tooltip" msgid "DALI_DEMO_STR_TITLE_FPP_GAME" msgstr "FPP Game" +msgid "DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE" +msgstr "Visual Fitting Mode" + msgid "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS" msgstr "Visual Transitions" diff --git a/resources/scripts/super-blur-view.json b/resources/scripts/super-blur-view.json index b380a40..0b0b3b1 100644 --- a/resources/scripts/super-blur-view.json +++ b/resources/scripts/super-blur-view.json @@ -52,9 +52,7 @@ "parentOrigin": "TOP_CENTER", "anchorPoint": "TOP_CENTER", "size": [800, 1280, 0], - "image": { - "filename": "{DEMO_IMAGE_DIR}background-4.jpg" - } + "imageUrl": "{DEMO_IMAGE_DIR}background-4.jpg" }, // Button to blur/clear diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index 9dac375..c680a15 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -46,6 +46,7 @@ extern "C" #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") #define DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER") +#define DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW") #define DALI_DEMO_STR_TITLE_GESTURES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_GESTURES") #define DALI_DEMO_STR_TITLE_COLOR_GRADIENT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COLOR_GRADIENT") #define DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS") @@ -105,6 +106,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_SKYBOX dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SKYBOX") #define DALI_DEMO_STR_TITLE_SPARKLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SPARKLE") #define DALI_DEMO_STR_TITLE_STYLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_STYLING") +#define DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW") #define DALI_DEMO_STR_TITLE_TEXTURED_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXTURED_MESH") #define DALI_DEMO_STR_TITLE_TEXT_EDITOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_EDITOR") #define DALI_DEMO_STR_TITLE_TEXT_FIELD dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_FIELD") @@ -116,6 +118,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_TEXT_SCROLLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_SCROLLING") #define DALI_DEMO_STR_TITLE_TILT_SENSOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TILT_SENSOR") #define DALI_DEMO_STR_TITLE_TOOLTIP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TOOLTIP") +#define DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE") #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS") #define DALI_DEMO_STR_TITLE_WEB_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_WEB_VIEW") #define DALI_DEMO_STR_TITLE_TEXT_RENDERER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_RENDERER") @@ -138,6 +141,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_CARD_ACTIVE "Card Active" #define DALI_DEMO_STR_TITLE_CLIPPING "Clipping" #define DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER "Clipping Draw Order" +#define DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW "Gaussian Blur" #define DALI_DEMO_STR_TITLE_GESTURES "Gestures" #define DALI_DEMO_STR_TITLE_COLOR_GRADIENT "Color Gradient" #define DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS "Compressed Texture Formats" @@ -197,6 +201,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_SKYBOX "Skybox" #define DALI_DEMO_STR_TITLE_SPARKLE "Sparkle" #define DALI_DEMO_STR_TITLE_STYLING "Styling" +#define DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW "Super Blur" #define DALI_DEMO_STR_TITLE_TEXTURED_MESH "Mesh Texture" #define DALI_DEMO_STR_TITLE_TEXT_EDITOR "Text Editor" #define DALI_DEMO_STR_TITLE_TEXT_FIELD "Text Field" @@ -208,6 +213,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_TEXT_SCROLLING "Text Scrolling" #define DALI_DEMO_STR_TITLE_TILT_SENSOR "Tilt Sensor" #define DALI_DEMO_STR_TITLE_TOOLTIP "Tooltip" +#define DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE "Visual Fitting Mode" #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS "Visual Transitions" #define DALI_DEMO_STR_TITLE_WEB_VIEW "Web View" #define DALI_DEMO_STR_TITLE_TEXT_RENDERER "Text Renderer" diff --git a/tests-reel/dali-tests-reel.cpp b/tests-reel/dali-tests-reel.cpp index b7f37a5..8300496 100644 --- a/tests-reel/dali-tests-reel.cpp +++ b/tests-reel/dali-tests-reel.cpp @@ -47,6 +47,7 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("text-fonts.example", DALI_DEMO_STR_TITLE_TEXT_FONTS)); demo.AddExample(Example("text-memory-profiling.example", DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING)); demo.AddExample(Example("text-overlap.example", DALI_DEMO_STR_TITLE_TEXT_OVERLAP)); + demo.AddExample(Example("visual-fitting-mode.example", DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE)); demo.AddExample(Example("visual-transitions.example", DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS)); demo.AddExample(Example("simple-text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); demo.AddExample(Example("simple-text-field.example", DALI_DEMO_STR_TITLE_TEXT_FIELD));