Fixed up styling following toolkit string comparison
[platform/core/uifw/dali-demo.git] / examples / styling / styling-application.cpp
1 /*
2  * Copyright (c) 2016 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  * @file style-example.cpp
19  * @brief Example of styling Toolkit controls.
20  */
21
22 // Class include
23 #include "styling-application.h"
24
25 // External includes
26 #include <dali-toolkit/dali-toolkit.h>
27 //#include <dali-toolkit/devel-api/controls/slider/slider.h>
28 #include <dali-toolkit/devel-api/controls/popup/popup.h>
29 #include "image-channel-control.h"
30 #include <cstdio>
31 #include <sstream>
32
33 // Internal includes
34
35 using namespace Dali;
36 using namespace Dali::Toolkit;
37
38 namespace Demo
39 {
40
41 const char* StylingApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" );
42 const char* StylingApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" );
43 const char* StylingApplication::DEMO_THEME_THREE_PATH( DEMO_STYLE_DIR "style-example-theme-three.json" );
44
45 namespace
46 {
47 #define DP(x) x
48
49 const char* DEFAULT_CONTROL_AREA_IMAGE_PATH( DEMO_IMAGE_DIR "popup_button_background.9.png" );
50
51 const char* POPUP_CONTROL_OK_NAME( "PopupControlOk" );
52 const char* POPUP_CONTROL_CANCEL_NAME( "PopupControlCancel" );
53 const char* BORDER_IMAGE( DEMO_IMAGE_DIR "border-4px.9.png" );
54 const char* RESIZE_HANDLE_IMAGE( DEMO_IMAGE_DIR "resize-handle.png" );
55
56 const int NUMBER_OF_THEMES(3); // The default theme is considered.
57
58 const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f );
59 const int BORDER_WIDTH( 4 );
60
61 const char* const SMALL_IMAGE_1 = DEMO_IMAGE_DIR "gallery-small-14.jpg";
62 const char* const BIG_IMAGE_1   = DEMO_IMAGE_DIR "gallery-large-4.jpg";
63
64 const char* const SMALL_IMAGE_2 = DEMO_IMAGE_DIR "gallery-small-39.jpg";
65 const char* const BIG_IMAGE_2   = DEMO_IMAGE_DIR "gallery-large-7.jpg";
66
67 const char* const SMALL_IMAGE_3 = DEMO_IMAGE_DIR "gallery-small-20.jpg";
68 const char* const BIG_IMAGE_3   = DEMO_IMAGE_DIR "gallery-large-11.jpg";
69
70 // Layout
71 const int MARGIN_SIZE = 10;
72
73 const int RADIO_LABEL_THUMBNAIL_SIZE = 60;
74 const int RADIO_LABEL_THUMBNAIL_SIZE_SMALL = 40;
75 const int RADIO_IMAGE_SPACING = 8;
76 const int BUTTON_HEIGHT = 48;
77
78 Property::Index GetChannelProperty( int index )
79 {
80   Property::Index channelIndex = Property::INVALID_INDEX;
81   switch(index)
82   {
83     case 0: { channelIndex = ImageChannelControl::Property::RED_CHANNEL; break; }
84     case 1: { channelIndex = ImageChannelControl::Property::GREEN_CHANNEL; break; }
85     case 2: { channelIndex = ImageChannelControl::Property::BLUE_CHANNEL; break; }
86   }
87   return channelIndex;
88 }
89
90 } // anonymous namespace
91
92
93
94 StylingApplication::StylingApplication( Application& application )
95 : mApplication( application )
96 {
97   application.InitSignal().Connect( this, &StylingApplication::Create );
98 }
99
100 StylingApplication::~StylingApplication()
101 {
102 }
103
104 void StylingApplication::Create( Application& application )
105 {
106   Stage stage = Stage::GetCurrent();
107   stage.KeyEventSignal().Connect(this, &StylingApplication::OnKeyEvent);
108   stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
109
110   // Hide the indicator bar
111   application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
112
113   mContentPane = CreateContentPane();
114   stage.Add( mContentPane );
115   mContentPane.SetSize( stage.GetSize() );
116
117   // Content panes:
118   TableView contentLayout = TableView::New( 5, 1 );
119   contentLayout.SetName("ContentLayout");
120   contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
121   contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
122   contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
123   contentLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
124
125   // Assign all rows the size negotiation property of fitting to children
126   for( unsigned int i = 0; i < contentLayout.GetRows(); ++i )
127   {
128     if( i != 1 )
129     {
130       contentLayout.SetFitHeight(i); // Row 1 should fill
131     }
132   }
133
134   mContentPane.Add( contentLayout );
135
136   mTitle = TextLabel::New( "Styling Example" );
137   mTitle.SetName( "Title" );
138   mTitle.SetStyleName("Title");
139   mTitle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
140   mTitle.SetParentOrigin( ParentOrigin::TOP_CENTER );
141   mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
142   mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
143   mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
144   contentLayout.Add( mTitle );
145
146   // Buttons:
147
148   TableView imageSelectLayout = TableView::New( 1, 2 );
149   imageSelectLayout.SetName("ImageSelectLayout");
150
151   imageSelectLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
152   imageSelectLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
153   imageSelectLayout.SetAnchorPoint( AnchorPoint::CENTER );
154   imageSelectLayout.SetParentOrigin( ParentOrigin::CENTER );
155   imageSelectLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
156
157   // Fit radio button column to child width, leave image to fill remainder
158   imageSelectLayout.SetFitWidth( 0 );
159
160   contentLayout.Add( imageSelectLayout );
161
162   TableView radioButtonsLayout = TableView::New( 3, 2 );
163   radioButtonsLayout.SetName("RadioButtonsLayout");
164   radioButtonsLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
165   // Leave each row to fill to parent height
166   // Set each column to fit to child width
167   radioButtonsLayout.SetFitWidth(0);
168   radioButtonsLayout.SetFitWidth(1);
169   radioButtonsLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) );
170
171   imageSelectLayout.AddChild( radioButtonsLayout, TableView::CellPosition(0, 0) );
172   imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
173
174   const char* images[] = { SMALL_IMAGE_1, SMALL_IMAGE_2, SMALL_IMAGE_3 };
175
176   for( int i=0; i<3; ++i )
177   {
178     std::ostringstream thumbnailName; thumbnailName << "thumbnail" << i+1;
179     ImageView image = ImageView::New( ResourceImage::New( images[i] ) );
180     image.SetName( thumbnailName.str() );
181     image.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) );
182
183     std::ostringstream label; label << (i+1);
184     std::ostringstream radioButtonStyleName;
185     radioButtonStyleName << "imageSelectButton" << i+1;
186     mRadioButtons[i] = RadioButton::New( label.str() );
187     mRadioButtons[i].SetName( radioButtonStyleName.str() );
188     mRadioButtons[i].SetParentOrigin( ParentOrigin::TOP_LEFT );
189     mRadioButtons[i].SetAnchorPoint( AnchorPoint::TOP_LEFT );
190     mRadioButtons[i].SetSelected( false );
191     mRadioButtons[i].StateChangedSignal().Connect( this, &StylingApplication::OnButtonStateChange );
192
193     radioButtonsLayout.AddChild( mRadioButtons[i], TableView::CellPosition( i, 0 ) );
194     radioButtonsLayout.AddChild( image, TableView::CellPosition( i, 1 ) );
195     radioButtonsLayout.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
196     radioButtonsLayout.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
197   }
198
199   mRadioButtons[0].SetSelected( true );
200
201   mImageChannelControl = ImageChannelControl::New( BIG_IMAGE_1 );
202   mImageChannelControl.SetName("ImageChannelControl");
203   mImageChannelControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT , Dimension::ALL_DIMENSIONS );
204   mImageChannelControl.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
205   imageSelectLayout.AddChild( mImageChannelControl, TableView::CellPosition( 0, 1 ) );
206
207   imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER );
208
209
210   TableView channelSliderLayout = TableView::New( 3, 3 );
211   channelSliderLayout.SetName("ChannelSliderLayout");
212
213   // Contains a column of check buttons and a column of sliders for R/G/B
214   channelSliderLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
215   channelSliderLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
216   channelSliderLayout.SetAnchorPoint( AnchorPoint::CENTER );
217   channelSliderLayout.SetParentOrigin( ParentOrigin::CENTER );
218   channelSliderLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
219
220   // Set each row to fit to child height
221   channelSliderLayout.SetFitHeight( 0 );
222   channelSliderLayout.SetFitHeight( 1 );
223   channelSliderLayout.SetFitHeight( 2 );
224
225   // Set each column to fit to child width
226   channelSliderLayout.SetFitWidth( 0 );
227   channelSliderLayout.SetFitWidth( 1 );
228
229   contentLayout.Add( channelSliderLayout );
230   const char *checkboxLabels[3] = {"R", "G", "B"};
231
232   for( int i=0; i<3; ++i )
233   {
234     std::ostringstream checkBoxStyleName;
235     checkBoxStyleName << "channelActiveCheckBox" << i+1;
236     mCheckButtons[i] = CheckBoxButton::New();
237     mCheckButtons[i].SetName( checkBoxStyleName.str() );
238     mCheckButtons[i].SetParentOrigin( ParentOrigin::CENTER );
239     mCheckButtons[i].SetAnchorPoint( AnchorPoint::CENTER );
240     mCheckButtons[i].SetSelected( true );
241
242     mCheckButtons[i].StateChangedSignal().Connect( this, &StylingApplication::OnCheckButtonChange );
243     mCheckButtons[i].RegisterProperty( "channel", i, Property::READ_WRITE );
244
245     channelSliderLayout.AddChild( mCheckButtons[i], TableView::CellPosition( i, 0 ) );
246     channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
247
248     TextLabel label = TextLabel::New( checkboxLabels[i] );
249     std::ostringstream labelStyleName; labelStyleName << "ColorLabel" << i+1;
250     label.SetName( labelStyleName.str() );
251     label.SetStyleName( labelStyleName.str() );
252     label.SetParentOrigin( ParentOrigin::CENTER );
253     label.SetAnchorPoint ( AnchorPoint::CENTER );
254     label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
255     label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
256
257     channelSliderLayout.AddChild( label, TableView::CellPosition( i, 1 ) );
258     channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
259
260     mChannelSliders[i] = Slider::New();
261     std::ostringstream sliderStyleName; sliderStyleName << "ColorSlider" << i+1;
262     mChannelSliders[i].SetName( sliderStyleName.str() );
263     mChannelSliders[i].SetStyleName( sliderStyleName.str() );
264     mChannelSliders[i].SetParentOrigin( ParentOrigin::CENTER );
265     mChannelSliders[i].SetAnchorPoint ( AnchorPoint::CENTER );
266     mChannelSliders[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
267     mChannelSliders[i].SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN , Dimension::HEIGHT );
268     mChannelSliders[i].SetProperty( Slider::Property::LOWER_BOUND, 0.0f );
269     mChannelSliders[i].SetProperty( Slider::Property::UPPER_BOUND, 100.0f );
270     mChannelSliders[i].SetProperty( Slider::Property::VALUE_PRECISION, 0 );
271     mChannelSliders[i].SetProperty( Slider::Property::VALUE, 100.0f );
272     mChannelSliders[i].SetProperty( Slider::Property::SHOW_POPUP, true );
273     mChannelSliders[i].SetProperty( Slider::Property::SHOW_VALUE, true );
274
275     mChannelSliders[i].RegisterProperty( "channel", i, Property::READ_WRITE );
276
277     channelSliderLayout.AddChild( mChannelSliders[i], TableView::CellPosition( i, 2 ) );
278     channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 2 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER );
279
280     mChannelSliders[i].ValueChangedSignal().Connect( this, &StylingApplication::OnSliderChanged );
281   }
282
283   mResetButton = PushButton::New();
284   mResetButton.SetLabelText( "Reset" );
285   mResetButton.SetName("ResetButton");
286   mResetButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
287   mResetButton.ClickedSignal().Connect( this, &StylingApplication::OnResetClicked );
288
289   contentLayout.Add( mResetButton );
290   contentLayout.SetCellAlignment( TableView::CellPosition( 3, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
291
292   TableView themeButtonLayout = TableView::New( 1, 4 );
293   themeButtonLayout.SetName("ThemeButtonsLayout");
294   themeButtonLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) );
295
296   themeButtonLayout.SetAnchorPoint( AnchorPoint::CENTER );
297   themeButtonLayout.SetParentOrigin( ParentOrigin::CENTER );
298   themeButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
299   themeButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
300   themeButtonLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
301   themeButtonLayout.SetFitHeight( 0 );
302
303   TextLabel label = TextLabel::New( "Theme: ");
304   label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
305   label.SetStyleName("ThemeLabel");
306   label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
307   label.SetParentOrigin( ParentOrigin::TOP_CENTER );
308   themeButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
309   themeButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
310
311   for( int i=0; i<3; ++i )
312   {
313     mThemeButtons[i] = PushButton::New();
314     mThemeButtons[i].SetName("ThemeButton");
315     mThemeButtons[i].SetStyleName("ThemeButton");
316     mThemeButtons[i].SetParentOrigin( ParentOrigin::CENTER );
317     mThemeButtons[i].SetAnchorPoint( ParentOrigin::CENTER );
318     mThemeButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
319     mThemeButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
320     mThemeButtons[i].RegisterProperty( "theme", i, Property::READ_WRITE );
321     mThemeButtons[i].ClickedSignal().Connect( this, &StylingApplication::OnThemeButtonClicked );
322     themeButtonLayout.AddChild( mThemeButtons[i], TableView::CellPosition( 0, 1+i ) );
323   }
324   mThemeButtons[0].SetLabelText( "Lite" ); // Lightweight changes on top of Dali
325   mThemeButtons[1].SetLabelText( "App1" ); // Different application style
326   mThemeButtons[2].SetLabelText( "App2" );
327
328   contentLayout.Add( themeButtonLayout );
329 }
330
331 Actor StylingApplication::CreateContentPane()
332 {
333   Toolkit::ImageView contentPane = Toolkit::ImageView::New( BORDER_IMAGE );
334   contentPane.SetName("ContentPane");
335   contentPane.SetParentOrigin( ParentOrigin::CENTER );
336   contentPane.SetAnchorPoint( AnchorPoint::CENTER );
337   contentPane.SetPadding( Padding( BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH ) );
338   return contentPane;
339 }
340
341 Actor StylingApplication::CreateResizableContentPane()
342 {
343   Toolkit::ImageView contentPane = Toolkit::ImageView::New( BORDER_IMAGE );
344   contentPane.SetName("ContentPane");
345   contentPane.SetParentOrigin( ParentOrigin::CENTER );
346   contentPane.SetAnchorPoint( AnchorPoint::CENTER );
347   contentPane.SetPadding( Padding( BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH ) );
348
349   Toolkit::ImageView grabHandle = Toolkit::ImageView::New( RESIZE_HANDLE_IMAGE );
350   grabHandle.SetName("GrabHandle");
351   grabHandle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
352   grabHandle.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
353   grabHandle.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
354   grabHandle.SetPosition( -BORDER_WIDTH, -BORDER_WIDTH );
355   grabHandle.SetOpacity( 0.6f );
356
357   Layer grabCornerLayer = Layer::New();
358   grabCornerLayer.SetName("GrabCornerLayer");
359   grabCornerLayer.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
360   grabCornerLayer.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
361   grabCornerLayer.Add( grabHandle );
362   contentPane.Add( grabCornerLayer );
363
364   mPanGestureDetector = PanGestureDetector::New();
365   mPanGestureDetector.Attach( grabHandle );
366   mPanGestureDetector.DetectedSignal().Connect( this, &StylingApplication::OnPan );
367
368   return contentPane;
369 }
370
371 Popup StylingApplication::CreateResetPopup()
372 {
373   Stage stage = Stage::GetCurrent();
374
375   Popup popup= Popup::New();
376   popup.SetName("ResetPopup");
377   popup.SetStyleName("ResetPopup");
378   popup.SetParentOrigin( ParentOrigin::CENTER );
379   popup.SetAnchorPoint( AnchorPoint::CENTER );
380   popup.SetSize( stage.GetSize().width * 0.75f, 0.0f );
381   popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false );
382   popup.OutsideTouchedSignal().Connect( this, &StylingApplication::HidePopup );
383   popup.HiddenSignal().Connect( this, &StylingApplication::PopupHidden );
384
385   popup.SetTitle( CreateTitle( "Reset channels" ) );
386
387   TextLabel text = TextLabel::New( "This will reset the channel data to full value. Are you sure?" );
388   text.SetName( "PopupContentText" );
389   text.SetStyleName( "PopupBody" );
390   text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
391   text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
392   text.SetProperty( TextLabel::Property::MULTI_LINE, true );
393   text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
394   popup.SetContent( text );
395
396   ImageView footer = ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
397   footer.SetName( "PopupFooter" );
398   footer.SetStyleName( "PopupFooter" );
399   footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
400   footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
401   footer.SetSize( 0.0f, 80.0f );
402   footer.SetAnchorPoint( AnchorPoint::CENTER );
403   footer.SetParentOrigin( ParentOrigin::CENTER );
404
405   TableView footerLayout = TableView::New( 1, 2 );
406   footerLayout.SetParentOrigin( ParentOrigin::CENTER );
407   footerLayout.SetAnchorPoint ( AnchorPoint::CENTER );
408   footerLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
409
410   PushButton okayButton = PushButton::New();
411   okayButton.SetName( POPUP_CONTROL_OK_NAME );
412   okayButton.SetStyleName( POPUP_CONTROL_OK_NAME );
413   okayButton.SetLabelText( "Ok!" );
414   okayButton.ClickedSignal().Connect( this, &StylingApplication::OnReset );
415   okayButton.SetParentOrigin( ParentOrigin::CENTER );
416   okayButton.SetAnchorPoint( AnchorPoint::CENTER );
417   okayButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
418   okayButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0f ) );
419
420   PushButton cancelButton = PushButton::New();
421   cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
422   cancelButton.SetStyleName( POPUP_CONTROL_CANCEL_NAME );
423   cancelButton.SetLabelText( "Cancel" );
424   cancelButton.ClickedSignal().Connect( this, &StylingApplication::OnResetCancelled );
425   cancelButton.SetParentOrigin( ParentOrigin::CENTER );
426   cancelButton.SetAnchorPoint( AnchorPoint::CENTER );
427   cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
428   cancelButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0f ) );
429
430   footerLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
431   footerLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
432   footerLayout.AddChild( okayButton, TableView::CellPosition( 0, 0 ) );
433   footerLayout.AddChild( cancelButton, TableView::CellPosition( 0, 1 ) );
434   footerLayout.SetCellPadding( Size( 10.f, 10.f ) );
435   footer.Add( footerLayout );
436
437   popup.SetFooter( footer );
438   return popup;
439 }
440
441 TextLabel StylingApplication::CreateTitle( std::string title )
442 {
443   TextLabel titleActor = TextLabel::New( title );
444   titleActor.SetName( "titleActor" );
445   titleActor.SetStyleName( "PopupTitle" );
446   titleActor.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
447   titleActor.SetProperty( TextLabel::Property::MULTI_LINE, false );
448
449   return titleActor;
450 }
451
452 bool StylingApplication::OnButtonStateChange( Button button )
453 {
454   // Todo: save / restore slider states per image
455
456   if( mImageChannelControl )
457   {
458     if( mRadioButtons[0].IsSelected() )
459     {
460       mImageChannelControl.SetImage( BIG_IMAGE_1 );
461     }
462     else if( mRadioButtons[1].IsSelected() )
463     {
464       mImageChannelControl.SetImage( BIG_IMAGE_2 );
465     }
466     else if( mRadioButtons[2].IsSelected() )
467     {
468       mImageChannelControl.SetImage( BIG_IMAGE_3 );
469     }
470   }
471   return true;
472 }
473
474 bool StylingApplication::OnCheckButtonChange( Button button )
475 {
476   Property::Index index = button.GetPropertyIndex("channel");
477   if( index != Property::INVALID_INDEX )
478   {
479     int channel = button.GetProperty<int>( index );
480     float value = mChannelSliders[channel].GetProperty<float>( Slider::Property::VALUE );
481     if( !button.IsSelected() )
482     {
483       // "Turn off" the channel's contribution
484       value = 0.0f;
485     }
486     Property::Index channelIndex = GetChannelProperty( channel );
487     mImageChannelControl.SetProperty(channelIndex, value/100.0f);
488   }
489   return true;
490 }
491
492 bool StylingApplication::OnThemeButtonClicked( Button button )
493 {
494   int theme = button.GetProperty<int>(button.GetPropertyIndex("theme"));
495   const char* themePath=NULL;
496
497   switch( theme )
498   {
499     case 0:
500     {
501       themePath = DEMO_THEME_ONE_PATH;
502       break;
503     }
504     case 1:
505     {
506       themePath = DEMO_THEME_TWO_PATH;
507       break;
508     }
509     case 2:
510     {
511       themePath = DEMO_THEME_THREE_PATH;
512       break;
513     }
514   }
515   StyleManager::Get().ApplyTheme( themePath );
516
517   return true;
518 }
519
520 bool StylingApplication::OnResetClicked( Button button )
521 {
522   if( ! mResetPopup )
523   {
524     mResetPopup = CreateResetPopup ();
525   }
526
527   Stage::GetCurrent().Add( mResetPopup );
528
529   mResetPopup.SetDisplayState( Popup::SHOWN );
530   return true;
531 }
532
533 bool StylingApplication::OnReset( Button button )
534 {
535   // todo: Reset the sliders for this image
536   for( int i=0; i<3; ++i )
537   {
538     mChannelSliders[i].SetProperty( Slider::Property::VALUE, 100.0f );
539   }
540   HidePopup();
541   return true;
542 }
543
544 bool StylingApplication::OnResetCancelled( Button button )
545 {
546   HidePopup();
547   return true;
548 }
549
550 bool StylingApplication::OnSliderChanged( Slider slider, float value )
551 {
552   // todo - change color channel's saturation
553   Property::Index index = slider.GetPropertyIndex("channel");
554   if( index != Property::INVALID_INDEX )
555   {
556     int channel = slider.GetProperty<int>( index );
557     if( mCheckButtons[channel].IsSelected() )
558     {
559       Property::Index channelIndex = GetChannelProperty( channel );
560       mImageChannelControl.SetProperty(channelIndex, value/100.0f);
561     }
562   }
563   return true;
564 }
565
566 void StylingApplication::HidePopup()
567 {
568   if( mResetPopup )
569   {
570     mResetPopup.SetDisplayState( Popup::HIDDEN );
571   }
572 }
573
574 void StylingApplication::PopupHidden()
575 {
576   if( mResetPopup )
577   {
578     // Clear down resources
579     mResetPopup.Unparent();
580     mResetPopup.Reset();
581   }
582 }
583
584 void StylingApplication::OnPan( Actor actor, const PanGesture& gesture )
585 {
586   Vector3 size = mContentPane.GetTargetSize();
587   mContentPane.SetSize( size.GetVectorXY() + gesture.displacement * 2.0f );
588 }
589
590 void StylingApplication::OnKeyEvent( const KeyEvent& keyEvent )
591 {
592   static int keyPressed = 0;
593
594   if( keyEvent.state == KeyEvent::Down)
595   {
596     if( keyPressed == 0 ) // Is this the first down event?
597     {
598       printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
599
600       if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
601       {
602         mApplication.Quit();
603       }
604       else if( keyEvent.keyPressedName.compare("Return") == 0 )
605       {
606         mCurrentTheme++;
607         mCurrentTheme %= NUMBER_OF_THEMES;
608
609         StyleManager styleManager = StyleManager::Get();
610         switch( mCurrentTheme )
611         {
612           case 0:
613           {
614             styleManager.ApplyTheme( DEMO_THEME_ONE_PATH );
615             printf("Changing to theme One\n");
616             break;
617           }
618           case 1:
619           {
620             styleManager.ApplyTheme( DEMO_THEME_TWO_PATH );
621             printf("Changing to theme Two\n");
622             break;
623           }
624           case 2:
625           {
626             styleManager.ApplyDefaultTheme();
627             printf("Changing to Toolkit theme\n");
628             break;
629           }
630         }
631       }
632     }
633     keyPressed = 1;
634   }
635   else if( keyEvent.state == KeyEvent::Up )
636   {
637     keyPressed = 0;
638   }
639 }
640
641 } // namespace Demo