Commit ca2757f0c75a4dcd0a8b28b0f5ce1056d83a193a
Committed by
Gerrit Code Review
Merge "Added example of CPU based image masking" into devel/master
Showing
12 changed files
with
167 additions
and
0 deletions
examples-reel/dali-examples-reel.cpp
| ... | ... | @@ -38,6 +38,7 @@ int DALI_EXPORT_API main(int argc, char **argv) |
| 38 | 38 | |
| 39 | 39 | demo.AddExample(Example("animated-images.example", DALI_DEMO_STR_TITLE_ANIMATED_IMAGES)); |
| 40 | 40 | demo.AddExample(Example("animated-shapes.example", DALI_DEMO_STR_TITLE_ANIMATED_SHAPES)); |
| 41 | + demo.AddExample(Example("alpha-blending-cpu.example", DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU)); | |
| 41 | 42 | demo.AddExample(Example("builder.example", DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI)); |
| 42 | 43 | demo.AddExample(Example("buttons.example", DALI_DEMO_STR_TITLE_BUTTONS)); |
| 43 | 44 | demo.AddExample(Example("clipping.example", DALI_DEMO_STR_TITLE_CLIPPING)); | ... | ... |
examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +#include <dali-toolkit/dali-toolkit.h> | |
| 19 | +#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> | |
| 20 | +#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h> | |
| 21 | +#include <cstring> | |
| 22 | + | |
| 23 | +using namespace Dali; | |
| 24 | + | |
| 25 | +namespace | |
| 26 | +{ | |
| 27 | +const char* const IMAGE_PATH_1 ( DEMO_IMAGE_DIR "people-small-7b.jpg" ); // 100x100 | |
| 28 | +const char* const IMAGE_PATH_2 ( DEMO_IMAGE_DIR "people-medium-7.jpg" ); | |
| 29 | +const char* const IMAGE_PATH_3 ( DEMO_IMAGE_DIR "people-medium-7-rgb565.png" ); // is compressed | |
| 30 | +const char* const IMAGE_PATH_4 ( DEMO_IMAGE_DIR "people-medium-7-masked.png" ); // has alpha channel | |
| 31 | +const char* const MASK_IMAGE_PATH_1 ( DEMO_IMAGE_DIR "mask.png" ); | |
| 32 | +const char* const MASK_IMAGE_PATH_2 ( DEMO_IMAGE_DIR "mask-large.png" ); // 300x300 | |
| 33 | +} | |
| 34 | + | |
| 35 | +class ImageViewAlphaBlendApp : public ConnectionTracker | |
| 36 | +{ | |
| 37 | +public: | |
| 38 | + ImageViewAlphaBlendApp( Application& application ) | |
| 39 | + : mApplication( application ), | |
| 40 | + mImageCombinationIndex( 0 ) | |
| 41 | + { | |
| 42 | + // Connect to the Application's Init signal | |
| 43 | + mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create ); | |
| 44 | + } | |
| 45 | + | |
| 46 | + ~ImageViewAlphaBlendApp() | |
| 47 | + { | |
| 48 | + // Nothing to do here; | |
| 49 | + } | |
| 50 | + | |
| 51 | +private: | |
| 52 | + // The Init signal is received once (only) during the Application lifetime | |
| 53 | + void Create( Application& application ) | |
| 54 | + { | |
| 55 | + // This creates an image view with one of 3 images, and one of 2 masks. | |
| 56 | + // Clicking the screen will cycle through each combination of mask and image. | |
| 57 | + | |
| 58 | + // Get a handle to the stage | |
| 59 | + Stage stage = Stage::GetCurrent(); | |
| 60 | + stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent); | |
| 61 | + stage.SetBackgroundColor( Color::WHITE ); | |
| 62 | + | |
| 63 | + mImageView = Toolkit::ImageView::New(); | |
| 64 | + | |
| 65 | + mImageView.SetSize(200, 200); | |
| 66 | + mImageView.SetParentOrigin( ParentOrigin::CENTER ); | |
| 67 | + stage.Add(mImageView); | |
| 68 | + | |
| 69 | + mImageLabel = Toolkit::TextLabel::New(); | |
| 70 | + mImageLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | |
| 71 | + mImageLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER ); | |
| 72 | + mImageLabel.SetPosition( Vector3( 0.0f, -50.0f, 0.0f ) ); | |
| 73 | + mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::GREEN ); | |
| 74 | + stage.Add(mImageLabel); | |
| 75 | + | |
| 76 | + mMaskLabel = Toolkit::TextLabel::New(); | |
| 77 | + mMaskLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | |
| 78 | + mMaskLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER ); | |
| 79 | + mMaskLabel.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); | |
| 80 | + mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::GREEN ); | |
| 81 | + stage.Add(mMaskLabel); | |
| 82 | + | |
| 83 | + LoadImages(); | |
| 84 | + | |
| 85 | + stage.TouchSignal().Connect( this, &ImageViewAlphaBlendApp::OnTouched ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + void OnTouched( const TouchData& touchData ) | |
| 89 | + { | |
| 90 | + static bool touched = false; | |
| 91 | + if( touchData.GetState( 0 ) == PointState::DOWN ) | |
| 92 | + { | |
| 93 | + touched = true; | |
| 94 | + } | |
| 95 | + | |
| 96 | + if( touchData.GetState( 0 ) == PointState::UP && touched) | |
| 97 | + { | |
| 98 | + mImageCombinationIndex++; | |
| 99 | + touched = false; | |
| 100 | + LoadImages(); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + void LoadImages() | |
| 105 | + { | |
| 106 | + const char* images[4] = { IMAGE_PATH_1, IMAGE_PATH_2, IMAGE_PATH_3, IMAGE_PATH_4 }; | |
| 107 | + const char* masks[2] = { MASK_IMAGE_PATH_1, MASK_IMAGE_PATH_2 }; | |
| 108 | + | |
| 109 | + const char* mask = masks[mImageCombinationIndex%2 ]; // Cycle through masks | |
| 110 | + const char* image = images[(mImageCombinationIndex/2)%4]; // then images | |
| 111 | + Property::Map map; | |
| 112 | + map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE ); | |
| 113 | + map.Add( Toolkit::ImageVisual::Property::URL, image ); | |
| 114 | + map.Add( Toolkit::DevelImageVisual::Property::ALPHA_MASK_URL, mask ); | |
| 115 | + mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); | |
| 116 | + | |
| 117 | + mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(image, '/') ); | |
| 118 | + mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(mask, '/') ); | |
| 119 | + } | |
| 120 | + | |
| 121 | + void OnKeyEvent(const KeyEvent& event) | |
| 122 | + { | |
| 123 | + if(event.state == KeyEvent::Down) | |
| 124 | + { | |
| 125 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | |
| 126 | + { | |
| 127 | + mApplication.Quit(); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + } | |
| 131 | + | |
| 132 | + | |
| 133 | +private: | |
| 134 | + Application& mApplication; | |
| 135 | + Toolkit::ImageView mImageView; | |
| 136 | + Toolkit::TextLabel mImageLabel; | |
| 137 | + Toolkit::TextLabel mMaskLabel; | |
| 138 | + | |
| 139 | + int mImageCombinationIndex; | |
| 140 | +}; | |
| 141 | + | |
| 142 | +void RunTest( Application& application ) | |
| 143 | +{ | |
| 144 | + ImageViewAlphaBlendApp test( application ); | |
| 145 | + | |
| 146 | + application.MainLoop(); | |
| 147 | +} | |
| 148 | + | |
| 149 | +// Entry point for Linux & Tizen applications | |
| 150 | +// | |
| 151 | +int DALI_EXPORT_API main( int argc, char **argv ) | |
| 152 | +{ | |
| 153 | + Application application = Application::New( &argc, &argv ); | |
| 154 | + | |
| 155 | + RunTest( application ); | |
| 156 | + | |
| 157 | + return 0; | |
| 158 | +} | ... | ... |
resources/images/application-icon-7-RGB565.png
0 → 100644
96.7 KB
resources/images/mask-large.png
0 → 100644
22.4 KB
resources/images/mask.png
0 → 100644
4.35 KB
resources/images/mask.xcf
0 → 100644
No preview for this file type
resources/images/people-medium-7-masked.png
0 → 100644
118 KB
resources/images/people-medium-7-rgb565.png
0 → 100644
68.5 KB
resources/images/people-small-7b.jpg
0 → 100644
11.9 KB
resources/po/en_GB.po
| ... | ... | @@ -4,6 +4,9 @@ msgstr "Animated Images" |
| 4 | 4 | msgid "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES" |
| 5 | 5 | msgstr "Animated Shapes" |
| 6 | 6 | |
| 7 | +msgid "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU" | |
| 8 | +msgstr "CPU Alpha Blending" | |
| 9 | + | |
| 7 | 10 | msgid "DALI_DEMO_STR_TITLE_BASIC_LIGHT" |
| 8 | 11 | msgstr "Basic Light" |
| 9 | 12 | ... | ... |
resources/po/en_US.po
| ... | ... | @@ -4,6 +4,9 @@ msgstr "Animated Images" |
| 4 | 4 | msgid "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES" |
| 5 | 5 | msgstr "Animated Shapes" |
| 6 | 6 | |
| 7 | +msgid "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU" | |
| 8 | +msgstr "CPU Alpha Blending" | |
| 9 | + | |
| 7 | 10 | msgid "DALI_DEMO_STR_TITLE_BASIC_LIGHT" |
| 8 | 11 | msgstr "Basic Light" |
| 9 | 12 | ... | ... |
shared/dali-demo-strings.h
| ... | ... | @@ -34,6 +34,7 @@ extern "C" |
| 34 | 34 | |
| 35 | 35 | #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES") |
| 36 | 36 | #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES") |
| 37 | +#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU") | |
| 37 | 38 | #define DALI_DEMO_STR_TITLE_BASIC_LIGHT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BASIC_LIGHT") |
| 38 | 39 | #define DALI_DEMO_STR_TITLE_BLOCKS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOCKS") |
| 39 | 40 | #define DALI_DEMO_STR_TITLE_BUBBLES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUBBLES") |
| ... | ... | @@ -98,6 +99,7 @@ extern "C" |
| 98 | 99 | |
| 99 | 100 | #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES "Animated Images" |
| 100 | 101 | #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES "Animated Shapes" |
| 102 | +#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU "CPU Alpha Blending" | |
| 101 | 103 | #define DALI_DEMO_STR_TITLE_BASIC_LIGHT "Basic Light" |
| 102 | 104 | #define DALI_DEMO_STR_TITLE_BLOCKS "Blocks" |
| 103 | 105 | #define DALI_DEMO_STR_TITLE_BUBBLES "Bubbles" | ... | ... |