diff --git a/examples-reel/dali-examples-reel.cpp b/examples-reel/dali-examples-reel.cpp index cdd64a0..af4b9d0 100644 --- a/examples-reel/dali-examples-reel.cpp +++ b/examples-reel/dali-examples-reel.cpp @@ -38,6 +38,7 @@ 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("alpha-blending-cpu.example", DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU)); 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("clipping.example", DALI_DEMO_STR_TITLE_CLIPPING)); diff --git a/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp b/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp new file mode 100644 index 0000000..8b8cd98 --- /dev/null +++ b/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2015 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 + +using namespace Dali; + +namespace +{ +const char* const IMAGE_PATH_1 ( DEMO_IMAGE_DIR "people-small-7b.jpg" ); // 100x100 +const char* const IMAGE_PATH_2 ( DEMO_IMAGE_DIR "people-medium-7.jpg" ); +const char* const IMAGE_PATH_3 ( DEMO_IMAGE_DIR "people-medium-7-rgb565.png" ); // is compressed +const char* const IMAGE_PATH_4 ( DEMO_IMAGE_DIR "people-medium-7-masked.png" ); // has alpha channel +const char* const MASK_IMAGE_PATH_1 ( DEMO_IMAGE_DIR "mask.png" ); +const char* const MASK_IMAGE_PATH_2 ( DEMO_IMAGE_DIR "mask-large.png" ); // 300x300 +} + +class ImageViewAlphaBlendApp : public ConnectionTracker +{ +public: + ImageViewAlphaBlendApp( Application& application ) + : mApplication( application ), + mImageCombinationIndex( 0 ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create ); + } + + ~ImageViewAlphaBlendApp() + { + // Nothing to do here; + } + +private: + // The Init signal is received once (only) during the Application lifetime + void Create( Application& application ) + { + // This creates an image view with one of 3 images, and one of 2 masks. + // Clicking the screen will cycle through each combination of mask and image. + + // Get a handle to the stage + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent); + stage.SetBackgroundColor( Color::WHITE ); + + mImageView = Toolkit::ImageView::New(); + + mImageView.SetSize(200, 200); + mImageView.SetParentOrigin( ParentOrigin::CENTER ); + stage.Add(mImageView); + + mImageLabel = Toolkit::TextLabel::New(); + mImageLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + mImageLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER ); + mImageLabel.SetPosition( Vector3( 0.0f, -50.0f, 0.0f ) ); + mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::GREEN ); + stage.Add(mImageLabel); + + mMaskLabel = Toolkit::TextLabel::New(); + mMaskLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + mMaskLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER ); + mMaskLabel.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); + mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::GREEN ); + stage.Add(mMaskLabel); + + LoadImages(); + + stage.TouchSignal().Connect( this, &ImageViewAlphaBlendApp::OnTouched ); + } + + void OnTouched( const TouchData& touchData ) + { + static bool touched = false; + if( touchData.GetState( 0 ) == PointState::DOWN ) + { + touched = true; + } + + if( touchData.GetState( 0 ) == PointState::UP && touched) + { + mImageCombinationIndex++; + touched = false; + LoadImages(); + } + } + + void LoadImages() + { + const char* images[4] = { IMAGE_PATH_1, IMAGE_PATH_2, IMAGE_PATH_3, IMAGE_PATH_4 }; + const char* masks[2] = { MASK_IMAGE_PATH_1, MASK_IMAGE_PATH_2 }; + + const char* mask = masks[mImageCombinationIndex%2 ]; // Cycle through masks + const char* image = images[(mImageCombinationIndex/2)%4]; // then images + Property::Map map; + map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE ); + map.Add( Toolkit::ImageVisual::Property::URL, image ); + map.Add( Toolkit::DevelImageVisual::Property::ALPHA_MASK_URL, mask ); + mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); + + mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(image, '/') ); + mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(mask, '/') ); + } + + 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; + Toolkit::TextLabel mImageLabel; + Toolkit::TextLabel mMaskLabel; + + int mImageCombinationIndex; +}; + +void RunTest( Application& application ) +{ + ImageViewAlphaBlendApp 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 ); + + RunTest( application ); + + return 0; +} diff --git a/resources/images/application-icon-7-RGB565.png b/resources/images/application-icon-7-RGB565.png new file mode 100644 index 0000000..bdbc28b --- /dev/null +++ b/resources/images/application-icon-7-RGB565.png diff --git a/resources/images/mask-large.png b/resources/images/mask-large.png new file mode 100644 index 0000000..e280f35 --- /dev/null +++ b/resources/images/mask-large.png diff --git a/resources/images/mask.png b/resources/images/mask.png new file mode 100644 index 0000000..b3e423c --- /dev/null +++ b/resources/images/mask.png diff --git a/resources/images/mask.xcf b/resources/images/mask.xcf new file mode 100644 index 0000000..b9628d0 --- /dev/null +++ b/resources/images/mask.xcf diff --git a/resources/images/people-medium-7-masked.png b/resources/images/people-medium-7-masked.png new file mode 100644 index 0000000..d94b586 --- /dev/null +++ b/resources/images/people-medium-7-masked.png diff --git a/resources/images/people-medium-7-rgb565.png b/resources/images/people-medium-7-rgb565.png new file mode 100644 index 0000000..07fa790 --- /dev/null +++ b/resources/images/people-medium-7-rgb565.png diff --git a/resources/images/people-small-7b.jpg b/resources/images/people-small-7b.jpg new file mode 100644 index 0000000..dd62dab --- /dev/null +++ b/resources/images/people-small-7b.jpg diff --git a/resources/po/en_GB.po b/resources/po/en_GB.po index 4c9c8f1..7bd4065 100755 --- a/resources/po/en_GB.po +++ b/resources/po/en_GB.po @@ -4,6 +4,9 @@ msgstr "Animated Images" msgid "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES" msgstr "Animated Shapes" +msgid "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU" +msgstr "CPU Alpha Blending" + msgid "DALI_DEMO_STR_TITLE_BASIC_LIGHT" msgstr "Basic Light" diff --git a/resources/po/en_US.po b/resources/po/en_US.po index ee9e456..a1f44ea 100755 --- a/resources/po/en_US.po +++ b/resources/po/en_US.po @@ -4,6 +4,9 @@ msgstr "Animated Images" msgid "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES" msgstr "Animated Shapes" +msgid "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU" +msgstr "CPU Alpha Blending" + msgid "DALI_DEMO_STR_TITLE_BASIC_LIGHT" msgstr "Basic Light" diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index adc0bca..ab83d1f 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -34,6 +34,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_ALPHA_BLENDING_CPU dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU") #define DALI_DEMO_STR_TITLE_BASIC_LIGHT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BASIC_LIGHT") #define DALI_DEMO_STR_TITLE_BLOCKS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOCKS") #define DALI_DEMO_STR_TITLE_BUBBLES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUBBLES") @@ -98,6 +99,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_ALPHA_BLENDING_CPU "CPU Alpha Blending" #define DALI_DEMO_STR_TITLE_BASIC_LIGHT "Basic Light" #define DALI_DEMO_STR_TITLE_BLOCKS "Blocks" #define DALI_DEMO_STR_TITLE_BUBBLES "Bubbles"