Commit ba018272fc0769a60d56829dcc77201732889b28

Authored by Xiangyin Ma
1 parent 93ece7f6

Added SuperBlur & Bloom demo

Change-Id: I0de724d4efd822db22db18e2b411263a0f56f10c
com.samsung.dali-demo.xml
... ... @@ -34,22 +34,22 @@
34 34 <ui-application appid="item-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/item-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
35 35 <label>Item View</label>
36 36 </ui-application>
37   - <ui-application appid="magnifier.example" exec="/usr/apps/com.samsung.dali-demo/bin/magnifier.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
38   - <label>Magnifier</label>
39   - </ui-application>
40   - <ui-application appid="metaball-explosion.example" exec="/usr/apps/com.samsung.dali-demo/bin/metaball-explosion.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
41   - <label>Metaball Explosion</label>
42   - </ui-application>
43   - <ui-application appid="metaball-refrac.example" exec="/usr/apps/com.samsung.dali-demo/bin/metaball-refrac.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
44   - <label>Metaball Refractions</label>
45   - </ui-application>
46   - <ui-application appid="motion-blur.example" exec="/usr/apps/com.samsung.dali-demo/bin/motion-blur.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
47   - <label>Motion Blur</label>
48   - </ui-application>
49   - <ui-application appid="model3d-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/model3d-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
50   - <label>Model 3D Viewer</label>
51   - </ui-application>
52   - <ui-application appid="motion-stretch.example" exec="/usr/apps/com.samsung.dali-demo/bin/motion-stretch.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  37 + <ui-application appid="magnifier.example" exec="/usr/apps/com.samsung.dali-demo/bin/magnifier.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  38 + <label>Magnifier</label>
  39 + </ui-application>
  40 + <ui-application appid="metaball-explosion.example" exec="/usr/apps/com.samsung.dali-demo/bin/metaball-explosion.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  41 + <label>Metaball Explosion</label>
  42 + </ui-application>
  43 + <ui-application appid="metaball-refrac.example" exec="/usr/apps/com.samsung.dali-demo/bin/metaball-refrac.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  44 + <label>Metaball Refractions</label>
  45 + </ui-application>
  46 + <ui-application appid="motion-blur.example" exec="/usr/apps/com.samsung.dali-demo/bin/motion-blur.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  47 + <label>Motion Blur</label>
  48 + </ui-application>
  49 + <ui-application appid="model3d-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/model3d-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  50 + <label>Model 3D Viewer</label>
  51 + </ui-application>
  52 + <ui-application appid="motion-stretch.example" exec="/usr/apps/com.samsung.dali-demo/bin/motion-stretch.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
53 53 <label>Motion Stretch</label>
54 54 </ui-application>
55 55 <ui-application appid="radial-menu.example" exec="/usr/apps/com.samsung.dali-demo/bin/radial-menu.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
... ... @@ -94,9 +94,9 @@
94 94 <ui-application appid="text-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
95 95 <label>Text Field</label>
96 96 </ui-application>
97   - <ui-application appid="text-fonts.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-fonts.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
98   - <label>Text Fonts</label>
99   - </ui-application>
  97 + <ui-application appid="text-fonts.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-fonts.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  98 + <label>Text Fonts</label>
  99 + </ui-application>
100 100 <ui-application appid="text-message-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-message-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
101 101 <label>Text Label</label>
102 102 </ui-application>
... ... @@ -121,6 +121,9 @@
121 121 <ui-application appid="gradients.example" exec="/usr/apps/com.samsung.dali-demo/bin/gradients.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
122 122 <label>Color Gradient</label>
123 123 </ui-application>
  124 + <ui-application appid="super-blur-bloom.example" exec="/usr/apps/com.samsung.dali-demo/bin/super-blur-bloom.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  125 + <label>Super Blur and Bloom</label>
  126 + </ui-application>
124 127 <ui-application appid="image-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/image-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
125 128 <label>Image View</label>
126 129 </ui-application>
... ...
demo/dali-demo.cpp
... ... @@ -69,6 +69,7 @@ int main(int argc, char **argv)
69 69 demo.AddExample(Example("line-mesh.example", DALI_DEMO_STR_TITLE_LINE_MESH));
70 70 demo.AddExample(Example("gradients.example", DALI_DEMO_STR_TITLE_COLOR_GRADIENT));
71 71 demo.AddExample(Example("image-view.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW));
  72 + demo.AddExample(Example("super-blur-bloom.example", DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM));
72 73  
73 74 demo.SortAlphabetically( true );
74 75  
... ...
examples/super-blur-bloom/super-blur-bloom-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 +#include <dali/dali.h>
  18 +#include <dali-toolkit/dali-toolkit.h>
  19 +#include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
  20 +#include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
  21 +#include "shared/view.h"
  22 +
  23 +using namespace Dali;
  24 +
  25 +namespace
  26 +{
  27 +const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
  28 +const char * const TITLE_SUPER_BLUR( "Super Blur" );
  29 +const char * const TITLE_BLOOM( "Bloom" );
  30 +const char * const CHANGE_BACKGROUND_ICON( DALI_IMAGE_DIR "icon-change.png" );
  31 +const char * const CHANGE_BACKGROUND_ICON_SELECTED( DALI_IMAGE_DIR "icon-change-selected.png" );
  32 +const char * const CHANGE_BLUR_ICON( DALI_IMAGE_DIR "icon-replace.png" );
  33 +const char * const CHANGE_BLUR_ICON_SELECTED( DALI_IMAGE_DIR "icon-replace-selected.png" );
  34 +
  35 +const char* BACKGROUND_IMAGES[]=
  36 +{
  37 + DALI_IMAGE_DIR "background-1.jpg",
  38 + DALI_IMAGE_DIR "background-2.jpg",
  39 + DALI_IMAGE_DIR "background-3.jpg",
  40 + DALI_IMAGE_DIR "background-4.jpg",
  41 + DALI_IMAGE_DIR "background-5.jpg",
  42 + DALI_IMAGE_DIR "background-magnifier.jpg",
  43 +};
  44 +const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) );
  45 +}
  46 +
  47 +/**
  48 + * @brief Load an image, scaled-down to no more than the stage dimensions.
  49 + *
  50 + * Uses image scaling mode FittingMode::SCALE_TO_FILL to resize the image at
  51 + * load time to cover the entire stage with pixels with no borders,
  52 + * and filter mode BOX_THEN_LINEAR to sample the image with
  53 + * maximum quality.
  54 + */
  55 +ResourceImage LoadStageFillingImage( const char * const imagePath )
  56 +{
  57 + Size stageSize = Stage::GetCurrent().GetSize();
  58 + return ResourceImage::New( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
  59 +}
  60 +
  61 +class BlurExample : public ConnectionTracker
  62 +{
  63 +public:
  64 + BlurExample(Application &app)
  65 + : mApp(app),
  66 + mImageIndex( 0 ),
  67 + mIsBlurring( false )
  68 + {
  69 + // Connect to the Application's Init signal
  70 + app.InitSignal().Connect(this, &BlurExample::Create);
  71 + }
  72 +
  73 + ~BlurExample()
  74 + {
  75 + }
  76 +private:
  77 + // The Init signal is received once (only) during the Application lifetime
  78 + void Create(Application& app)
  79 + {
  80 + Stage stage = Stage::GetCurrent();
  81 + Vector2 stageSize = stage.GetSize();
  82 +
  83 + stage.KeyEventSignal().Connect(this, &BlurExample::OnKeyEvent);
  84 +
  85 + // Creates a default view with a default tool bar.
  86 + // The view is added to the stage.
  87 + Layer content = DemoHelper::CreateView( app,
  88 + mBackground,
  89 + mToolBar,
  90 + "",
  91 + TOOLBAR_IMAGE,
  92 + "" );
  93 +
  94 + // Add a button to change background. (right of toolbar)
  95 + Toolkit::PushButton changeBackgroundButton = Toolkit::PushButton::New();
  96 + changeBackgroundButton.SetUnselectedImage( CHANGE_BACKGROUND_ICON );
  97 + changeBackgroundButton.SetSelectedImage( CHANGE_BACKGROUND_ICON_SELECTED );
  98 + changeBackgroundButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBackgroundIconClicked );
  99 + mToolBar.AddControl( changeBackgroundButton,
  100 + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
  101 + Toolkit::Alignment::HorizontalRight,
  102 + DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
  103 +
  104 + // Add a button to change the blur view. (left of toolbar)
  105 + Toolkit::PushButton changeBlurButton = Toolkit::PushButton::New();
  106 + changeBlurButton.SetUnselectedImage( CHANGE_BLUR_ICON );
  107 + changeBlurButton.SetSelectedImage( CHANGE_BLUR_ICON_SELECTED );
  108 + changeBlurButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBlurIconClicked );
  109 + mToolBar.AddControl( changeBlurButton,
  110 + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
  111 + Toolkit::Alignment::HorizontalLeft,
  112 + DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
  113 +
  114 + mSuperBlurView = Toolkit::SuperBlurView::New( 5 );
  115 + mSuperBlurView.SetSize( stageSize );
  116 + mSuperBlurView.SetParentOrigin( ParentOrigin::CENTER );
  117 + mSuperBlurView.SetAnchorPoint( AnchorPoint::CENTER );
  118 + mSuperBlurView.BlurFinishedSignal().Connect(this, &BlurExample::OnBlurFinished);
  119 + mCurrentImage = LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
  120 + mSuperBlurView.SetImage( mCurrentImage );
  121 + mBackground.Add( mSuperBlurView );
  122 + mIsBlurring = true;
  123 + SetTitle( TITLE_SUPER_BLUR );
  124 +
  125 + mBloomView = Toolkit::BloomView::New();
  126 + mBloomView.SetParentOrigin(ParentOrigin::CENTER);
  127 + mBloomView.SetSize(stageSize);
  128 + mBloomActor = Toolkit::ImageView::New(mCurrentImage);
  129 + mBloomActor.SetParentOrigin( ParentOrigin::CENTER );
  130 + mBloomView.Add( mBloomActor );
  131 +
  132 + // Connect the callback to the touch signal on the background
  133 + mSuperBlurView.TouchedSignal().Connect( this, &BlurExample::OnTouch );
  134 + mBloomView.TouchedSignal().Connect( this, &BlurExample::OnTouch );
  135 + }
  136 +
  137 + // Callback function of the touch signal on the background
  138 + bool OnTouch(Dali::Actor actor, const Dali::TouchEvent& event)
  139 + {
  140 + const TouchPoint &point = event.GetPoint(0);
  141 + switch(point.state)
  142 + {
  143 + case TouchPoint::Down:
  144 + {
  145 + if( mAnimation )
  146 + {
  147 + mAnimation.Clear();
  148 + }
  149 +
  150 + mAnimation = Animation::New( 2.f );
  151 + if( mSuperBlurView.OnStage() )
  152 + {
  153 + mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 1.f );
  154 + }
  155 + else
  156 + {
  157 + mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 3.f );
  158 + }
  159 + mAnimation.Play();
  160 + break;
  161 + }
  162 + case TouchPoint::Up:
  163 + case TouchPoint::Leave:
  164 + case TouchPoint::Interrupted:
  165 + {
  166 + if( mAnimation )
  167 + {
  168 + mAnimation.Clear();
  169 + }
  170 +
  171 + mAnimation = Animation::New( 2.f );
  172 + if( mSuperBlurView.OnStage() )
  173 + {
  174 + mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 0.f );
  175 + }
  176 + else
  177 + {
  178 + mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 0.f );
  179 + }
  180 + mAnimation.Play();
  181 + break;
  182 + }
  183 + case TouchPoint::Motion:
  184 + case TouchPoint::Stationary:
  185 + case TouchPoint::Last:
  186 + default:
  187 + {
  188 + break;
  189 + }
  190 + }
  191 + return true;
  192 + }
  193 +
  194 + /**
  195 + * Main key event handler
  196 + */
  197 + void OnKeyEvent(const KeyEvent& event)
  198 + {
  199 + if(event.state == KeyEvent::Down)
  200 + {
  201 + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
  202 + {
  203 + mApp.Quit();
  204 + }
  205 + }
  206 + }
  207 +
  208 + bool OnChangeBackgroundIconClicked( Toolkit::Button button )
  209 + {
  210 + if( mIsBlurring )
  211 + {
  212 + return true;
  213 + }
  214 +
  215 + if( mAnimation )
  216 + {
  217 + mAnimation.Clear();
  218 + }
  219 +
  220 + mImageIndex = (mImageIndex+1u)%NUM_BACKGROUND_IMAGES;
  221 + mCurrentImage = LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
  222 +
  223 + if( mSuperBlurView.OnStage() )
  224 + {
  225 + mIsBlurring = true;
  226 +
  227 + mSuperBlurView.SetBlurStrength( 0.f );
  228 + mSuperBlurView.SetImage( mCurrentImage );
  229 + }
  230 + else
  231 + {
  232 + mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
  233 + mBloomActor.SetImage( mCurrentImage );
  234 + }
  235 +
  236 + return true;
  237 + }
  238 +
  239 + bool OnChangeBlurIconClicked( Toolkit::Button button )
  240 + {
  241 + if( mSuperBlurView.OnStage() )
  242 + {
  243 + SetTitle( TITLE_BLOOM );
  244 + mBackground.Remove( mSuperBlurView );
  245 +
  246 + mBloomActor.SetImage( mCurrentImage );
  247 + mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
  248 + mBackground.Add( mBloomView );
  249 + mBloomView.Activate();
  250 +
  251 + }
  252 + else
  253 + {
  254 + SetTitle( TITLE_SUPER_BLUR );
  255 + mBackground.Remove( mBloomView );
  256 + mBloomView.Deactivate();
  257 +
  258 + mBackground.Add( mSuperBlurView );
  259 + mSuperBlurView.SetBlurStrength( 0.f );
  260 + mSuperBlurView.SetImage( mCurrentImage );
  261 + mIsBlurring = true;
  262 + }
  263 +
  264 + return true;
  265 + }
  266 +
  267 + void OnBlurFinished( Toolkit::SuperBlurView blurView )
  268 + {
  269 + mIsBlurring = false;
  270 + }
  271 +
  272 + /**
  273 + * Sets/Updates the title of the View
  274 + * @param[in] title The new title for the view.
  275 + */
  276 + void SetTitle(const std::string& title)
  277 + {
  278 + if(!mTitleActor)
  279 + {
  280 + mTitleActor = DemoHelper::CreateToolBarLabel( title );
  281 + // Add title to the tool bar.
  282 + mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
  283 + }
  284 +
  285 + mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, title );
  286 + }
  287 +
  288 +private:
  289 +
  290 + Application& mApp;
  291 + Toolkit::ToolBar mToolBar;
  292 + Toolkit::TextLabel mTitleActor; ///< The Toolbar's Title.
  293 + Toolkit::Control mBackground;
  294 + Toolkit::SuperBlurView mSuperBlurView;
  295 + Toolkit::BloomView mBloomView;
  296 + Animation mAnimation;
  297 + Toolkit::ImageView mBloomActor;
  298 + Image mCurrentImage;
  299 + unsigned int mImageIndex;
  300 + bool mIsBlurring;
  301 +};
  302 +
  303 +/*****************************************************************************/
  304 +
  305 +static void
  306 +RunTest(Application& app)
  307 +{
  308 + BlurExample theApp(app);
  309 + app.MainLoop();
  310 +}
  311 +
  312 +/*****************************************************************************/
  313 +
  314 +int
  315 +main(int argc, char **argv)
  316 +{
  317 + Application app = Application::New(&argc, &argv, DALI_DEMO_THEME_PATH);
  318 +
  319 + RunTest(app);
  320 +
  321 + return 0;
  322 +}
... ...
shared/dali-demo-strings.h
... ... @@ -61,6 +61,7 @@ extern &quot;C&quot;
61 61 #define DALI_DEMO_STR_TITLE_TEXTURED_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TEXTURED_MESH")
62 62 #define DALI_DEMO_STR_TITLE_LINE_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_LINE_MESH")
63 63 #define DALI_DEMO_STR_TITLE_COLOR_GRADIENT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_COLOR_GRADIENT")
  64 +#define DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_SUPER_BLUR_BLOOM")
64 65  
65 66 #else // !INTERNATIONALIZATION_ENABLED
66 67  
... ... @@ -97,6 +98,7 @@ extern &quot;C&quot;
97 98 #define DALI_DEMO_STR_TITLE_LINE_MESH "Mesh Line"
98 99 #define DALI_DEMO_STR_TITLE_COLOR_GRADIENT "Color Gradient"
99 100 #define DALI_DEMO_STR_TITLE_IMAGE_VIEW "Image View"
  101 +#define DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM "Super Blur and Bloom"
100 102  
101 103 #endif
102 104  
... ...