2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file style-example.cpp
19 * @brief Example of styling Toolkit controls.
23 #include "styling-application.h"
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"
36 using namespace Dali::Toolkit;
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" );
49 const char* DEFAULT_CONTROL_AREA_IMAGE_PATH( DEMO_IMAGE_DIR "popup_button_background.9.png" );
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" );
56 const int NUMBER_OF_THEMES(3); // The default theme is considered.
58 const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f );
59 const int BORDER_WIDTH( 4 );
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";
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";
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";
71 const int MARGIN_SIZE = 10;
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;
78 Property::Index GetChannelProperty( int index )
80 Property::Index channelIndex = Property::INVALID_INDEX;
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; }
90 } // anonymous namespace
94 StylingApplication::StylingApplication( Application& application )
95 : mApplication( application ),
98 application.InitSignal().Connect( this, &StylingApplication::Create );
101 StylingApplication::~StylingApplication()
105 void StylingApplication::Create( Application& application )
107 Stage stage = Stage::GetCurrent();
108 stage.KeyEventSignal().Connect(this, &StylingApplication::OnKeyEvent);
109 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
111 // Hide the indicator bar
112 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
114 mContentPane = CreateContentPane();
115 stage.Add( mContentPane );
116 mContentPane.SetSize( stage.GetSize() );
119 TableView contentLayout = TableView::New( 5, 1 );
120 contentLayout.SetName("ContentLayout");
121 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
122 contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
123 contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
124 contentLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
126 // Assign all rows the size negotiation property of fitting to children
127 for( unsigned int i = 0; i < contentLayout.GetRows(); ++i )
131 contentLayout.SetFitHeight(i); // Row 1 should fill
135 mContentPane.Add( contentLayout );
137 mTitle = TextLabel::New( "Styling Example" );
138 mTitle.SetName( "Title" );
139 mTitle.SetStyleName("Title");
140 mTitle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
141 mTitle.SetParentOrigin( ParentOrigin::TOP_CENTER );
142 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
143 mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
144 mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
145 contentLayout.Add( mTitle );
149 TableView imageSelectLayout = TableView::New( 1, 2 );
150 imageSelectLayout.SetName("ImageSelectLayout");
152 imageSelectLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
153 imageSelectLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
154 imageSelectLayout.SetAnchorPoint( AnchorPoint::CENTER );
155 imageSelectLayout.SetParentOrigin( ParentOrigin::CENTER );
156 imageSelectLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
158 // Fit radio button column to child width, leave image to fill remainder
159 imageSelectLayout.SetFitWidth( 0 );
161 contentLayout.Add( imageSelectLayout );
163 TableView radioButtonsLayout = TableView::New( 3, 2 );
164 radioButtonsLayout.SetName("RadioButtonsLayout");
165 radioButtonsLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
166 // Leave each row to fill to parent height
167 // Set each column to fit to child width
168 radioButtonsLayout.SetFitWidth(0);
169 radioButtonsLayout.SetFitWidth(1);
170 radioButtonsLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) );
172 imageSelectLayout.AddChild( radioButtonsLayout, TableView::CellPosition(0, 0) );
173 imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
175 const char* images[] = { SMALL_IMAGE_1, SMALL_IMAGE_2, SMALL_IMAGE_3 };
177 for( int i=0; i<3; ++i )
179 std::ostringstream thumbnailName; thumbnailName << "thumbnail" << i+1;
180 ImageView image = ImageView::New( ResourceImage::New( images[i] ) );
181 image.SetName( thumbnailName.str() );
182 image.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) );
184 std::ostringstream label; label << (i+1);
185 std::ostringstream radioButtonStyleName;
186 radioButtonStyleName << "imageSelectButton" << i+1;
187 mRadioButtons[i] = RadioButton::New( label.str() );
188 mRadioButtons[i].SetName( radioButtonStyleName.str() );
189 mRadioButtons[i].SetParentOrigin( ParentOrigin::TOP_LEFT );
190 mRadioButtons[i].SetAnchorPoint( AnchorPoint::TOP_LEFT );
191 mRadioButtons[i].SetSelected( false );
192 mRadioButtons[i].StateChangedSignal().Connect( this, &StylingApplication::OnButtonStateChange );
194 radioButtonsLayout.AddChild( mRadioButtons[i], TableView::CellPosition( i, 0 ) );
195 radioButtonsLayout.AddChild( image, TableView::CellPosition( i, 1 ) );
196 radioButtonsLayout.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
197 radioButtonsLayout.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
200 mRadioButtons[0].SetSelected( true );
202 mImagePlacement = Actor::New();
203 mImagePlacement.SetParentOrigin( ParentOrigin::CENTER );
204 mImagePlacement.SetAnchorPoint( AnchorPoint::CENTER );
205 mImagePlacement.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
206 imageSelectLayout.AddChild( mImagePlacement, TableView::CellPosition( 0, 1 ) );
207 imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER );
209 mIcc1 = ImageChannelControl::New( BIG_IMAGE_1 );
210 mIcc1.SetName("ICC1");
211 mIcc1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT , Dimension::ALL_DIMENSIONS );
212 mIcc1.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
213 mIcc1.SetParentOrigin( ParentOrigin::CENTER );
214 mIcc1.SetVisibility( true );
216 mImagePlacement.Add( mIcc1 );
218 mIcc2 = ImageChannelControl::New( BIG_IMAGE_2 );
219 mIcc2.SetName("ICC2");
220 mIcc2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT , Dimension::ALL_DIMENSIONS );
221 mIcc2.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
222 mIcc2.SetParentOrigin( ParentOrigin::CENTER );
223 mIcc2.SetVisibility( false );
225 mImagePlacement.Add( mIcc2 );
227 mIcc3 = ImageChannelControl::New( BIG_IMAGE_3 );
228 mIcc3.SetName("ICC3");
229 mIcc3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT , Dimension::ALL_DIMENSIONS );
230 mIcc3.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
231 mIcc3.SetParentOrigin( ParentOrigin::CENTER );
232 mIcc3.SetVisibility( false );
234 mImagePlacement.Add( mIcc3 );
236 mImageChannelControl = mIcc1;
238 TableView channelSliderLayout = TableView::New( 3, 3 );
239 channelSliderLayout.SetName("ChannelSliderLayout");
241 // Contains a column of check buttons and a column of sliders for R/G/B
242 channelSliderLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
243 channelSliderLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
244 channelSliderLayout.SetAnchorPoint( AnchorPoint::CENTER );
245 channelSliderLayout.SetParentOrigin( ParentOrigin::CENTER );
246 channelSliderLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
248 // Set each row to fit to child height
249 channelSliderLayout.SetFitHeight( 0 );
250 channelSliderLayout.SetFitHeight( 1 );
251 channelSliderLayout.SetFitHeight( 2 );
253 // Set each column to fit to child width
254 channelSliderLayout.SetFitWidth( 0 );
255 channelSliderLayout.SetFitWidth( 1 );
257 contentLayout.Add( channelSliderLayout );
258 const char *checkboxLabels[3] = {"R", "G", "B"};
260 for( int i=0; i<3; ++i )
262 std::ostringstream checkBoxStyleName;
263 checkBoxStyleName << "channelActiveCheckBox" << i+1;
264 mCheckButtons[i] = CheckBoxButton::New();
265 mCheckButtons[i].SetName( checkBoxStyleName.str() );
266 mCheckButtons[i].SetParentOrigin( ParentOrigin::CENTER );
267 mCheckButtons[i].SetAnchorPoint( AnchorPoint::CENTER );
268 mCheckButtons[i].SetSelected( true );
270 mCheckButtons[i].StateChangedSignal().Connect( this, &StylingApplication::OnCheckButtonChange );
271 mCheckButtons[i].RegisterProperty( "channel", i, Property::READ_WRITE );
273 channelSliderLayout.AddChild( mCheckButtons[i], TableView::CellPosition( i, 0 ) );
274 channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
276 TextLabel label = TextLabel::New( checkboxLabels[i] );
277 std::ostringstream labelStyleName; labelStyleName << "ColorLabel" << i+1;
278 label.SetName( labelStyleName.str() );
279 label.SetStyleName( labelStyleName.str() );
280 label.SetParentOrigin( ParentOrigin::CENTER );
281 label.SetAnchorPoint ( AnchorPoint::CENTER );
282 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
283 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
285 channelSliderLayout.AddChild( label, TableView::CellPosition( i, 1 ) );
286 channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
288 mChannelSliders[i] = Slider::New();
289 std::ostringstream sliderStyleName; sliderStyleName << "ColorSlider" << i+1;
290 mChannelSliders[i].SetName( sliderStyleName.str() );
291 mChannelSliders[i].SetStyleName( sliderStyleName.str() );
292 mChannelSliders[i].SetParentOrigin( ParentOrigin::CENTER );
293 mChannelSliders[i].SetAnchorPoint ( AnchorPoint::CENTER );
294 mChannelSliders[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
295 mChannelSliders[i].SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN , Dimension::HEIGHT );
296 mChannelSliders[i].SetProperty( Slider::Property::LOWER_BOUND, 0.0f );
297 mChannelSliders[i].SetProperty( Slider::Property::UPPER_BOUND, 100.0f );
298 mChannelSliders[i].SetProperty( Slider::Property::VALUE_PRECISION, 0 );
299 mChannelSliders[i].SetProperty( Slider::Property::VALUE, 100.0f );
300 mChannelSliders[i].SetProperty( Slider::Property::SHOW_POPUP, true );
301 mChannelSliders[i].SetProperty( Slider::Property::SHOW_VALUE, true );
303 mChannelSliders[i].RegisterProperty( "channel", i, Property::READ_WRITE );
305 channelSliderLayout.AddChild( mChannelSliders[i], TableView::CellPosition( i, 2 ) );
306 channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 2 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER );
308 mChannelSliders[i].ValueChangedSignal().Connect( this, &StylingApplication::OnSliderChanged );
311 mResetButton = PushButton::New();
312 mResetButton.SetLabelText( "Reset" );
313 mResetButton.SetName("ResetButton");
314 mResetButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
315 mResetButton.ClickedSignal().Connect( this, &StylingApplication::OnResetClicked );
317 contentLayout.Add( mResetButton );
318 contentLayout.SetCellAlignment( TableView::CellPosition( 3, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
320 TableView themeButtonLayout = TableView::New( 1, 4 );
321 themeButtonLayout.SetName("ThemeButtonsLayout");
322 themeButtonLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) );
324 themeButtonLayout.SetAnchorPoint( AnchorPoint::CENTER );
325 themeButtonLayout.SetParentOrigin( ParentOrigin::CENTER );
326 themeButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
327 themeButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
328 themeButtonLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
329 themeButtonLayout.SetFitHeight( 0 );
331 TextLabel label = TextLabel::New( "Theme: ");
332 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
333 label.SetStyleName("ThemeLabel");
334 label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
335 label.SetParentOrigin( ParentOrigin::TOP_CENTER );
336 themeButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
337 themeButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
339 for( int i=0; i<3; ++i )
341 mThemeButtons[i] = PushButton::New();
342 mThemeButtons[i].SetName("ThemeButton");
343 mThemeButtons[i].SetStyleName("ThemeButton");
344 mThemeButtons[i].SetParentOrigin( ParentOrigin::CENTER );
345 mThemeButtons[i].SetAnchorPoint( ParentOrigin::CENTER );
346 mThemeButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
347 mThemeButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
348 mThemeButtons[i].RegisterProperty( "theme", i, Property::READ_WRITE );
349 mThemeButtons[i].ClickedSignal().Connect( this, &StylingApplication::OnThemeButtonClicked );
350 themeButtonLayout.AddChild( mThemeButtons[i], TableView::CellPosition( 0, 1+i ) );
352 mThemeButtons[0].SetLabelText( "Lite" ); // Lightweight changes on top of Dali
353 mThemeButtons[1].SetLabelText( "App1" ); // Different application style
354 mThemeButtons[2].SetLabelText( "App2" );
356 contentLayout.Add( themeButtonLayout );
359 Actor StylingApplication::CreateContentPane()
361 Toolkit::ImageView contentPane = Toolkit::ImageView::New( BORDER_IMAGE );
362 contentPane.SetName("ContentPane");
363 contentPane.SetParentOrigin( ParentOrigin::CENTER );
364 contentPane.SetAnchorPoint( AnchorPoint::CENTER );
365 contentPane.SetPadding( Padding( BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH ) );
369 Actor StylingApplication::CreateResizableContentPane()
371 Toolkit::ImageView contentPane = Toolkit::ImageView::New( BORDER_IMAGE );
372 contentPane.SetName("ContentPane");
373 contentPane.SetParentOrigin( ParentOrigin::CENTER );
374 contentPane.SetAnchorPoint( AnchorPoint::CENTER );
375 contentPane.SetPadding( Padding( BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH ) );
377 Toolkit::ImageView grabHandle = Toolkit::ImageView::New( RESIZE_HANDLE_IMAGE );
378 grabHandle.SetName("GrabHandle");
379 grabHandle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
380 grabHandle.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
381 grabHandle.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
382 grabHandle.SetPosition( -BORDER_WIDTH, -BORDER_WIDTH );
383 grabHandle.SetOpacity( 0.6f );
385 Layer grabCornerLayer = Layer::New();
386 grabCornerLayer.SetName("GrabCornerLayer");
387 grabCornerLayer.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
388 grabCornerLayer.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
389 grabCornerLayer.Add( grabHandle );
390 contentPane.Add( grabCornerLayer );
392 mPanGestureDetector = PanGestureDetector::New();
393 mPanGestureDetector.Attach( grabHandle );
394 mPanGestureDetector.DetectedSignal().Connect( this, &StylingApplication::OnPan );
399 Popup StylingApplication::CreateResetPopup()
401 Stage stage = Stage::GetCurrent();
403 Popup popup= Popup::New();
404 popup.SetName("ResetPopup");
405 popup.SetStyleName("ResetPopup");
406 popup.SetParentOrigin( ParentOrigin::CENTER );
407 popup.SetAnchorPoint( AnchorPoint::CENTER );
408 popup.SetSize( stage.GetSize().width * 0.75f, 0.0f );
409 popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false );
410 popup.OutsideTouchedSignal().Connect( this, &StylingApplication::HidePopup );
411 popup.HiddenSignal().Connect( this, &StylingApplication::PopupHidden );
413 popup.SetTitle( CreateTitle( "Reset channels" ) );
415 TextLabel text = TextLabel::New( "This will reset the channel data to full value. Are you sure?" );
416 text.SetName( "PopupContentText" );
417 text.SetStyleName( "PopupBody" );
418 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
419 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
420 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
421 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
422 popup.SetContent( text );
424 ImageView footer = ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
425 footer.SetName( "PopupFooter" );
426 footer.SetStyleName( "PopupFooter" );
427 footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
428 footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
429 footer.SetSize( 0.0f, 80.0f );
430 footer.SetAnchorPoint( AnchorPoint::CENTER );
431 footer.SetParentOrigin( ParentOrigin::CENTER );
433 TableView footerLayout = TableView::New( 1, 2 );
434 footerLayout.SetParentOrigin( ParentOrigin::CENTER );
435 footerLayout.SetAnchorPoint ( AnchorPoint::CENTER );
436 footerLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
438 PushButton okayButton = PushButton::New();
439 okayButton.SetName( POPUP_CONTROL_OK_NAME );
440 okayButton.SetStyleName( POPUP_CONTROL_OK_NAME );
441 okayButton.SetLabelText( "Ok!" );
442 okayButton.ClickedSignal().Connect( this, &StylingApplication::OnReset );
443 okayButton.SetParentOrigin( ParentOrigin::CENTER );
444 okayButton.SetAnchorPoint( AnchorPoint::CENTER );
445 okayButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
446 okayButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0f ) );
448 PushButton cancelButton = PushButton::New();
449 cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
450 cancelButton.SetStyleName( POPUP_CONTROL_CANCEL_NAME );
451 cancelButton.SetLabelText( "Cancel" );
452 cancelButton.ClickedSignal().Connect( this, &StylingApplication::OnResetCancelled );
453 cancelButton.SetParentOrigin( ParentOrigin::CENTER );
454 cancelButton.SetAnchorPoint( AnchorPoint::CENTER );
455 cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
456 cancelButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0f ) );
458 footerLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
459 footerLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
460 footerLayout.AddChild( okayButton, TableView::CellPosition( 0, 0 ) );
461 footerLayout.AddChild( cancelButton, TableView::CellPosition( 0, 1 ) );
462 footerLayout.SetCellPadding( Size( 10.f, 10.f ) );
463 footer.Add( footerLayout );
465 popup.SetFooter( footer );
469 TextLabel StylingApplication::CreateTitle( std::string title )
471 TextLabel titleActor = TextLabel::New( title );
472 titleActor.SetName( "titleActor" );
473 titleActor.SetStyleName( "PopupTitle" );
474 titleActor.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
475 titleActor.SetProperty( TextLabel::Property::MULTI_LINE, false );
480 bool StylingApplication::OnButtonStateChange( Button button )
482 // On button press, called twice, once to tell new button it's selected,
483 // once to tell old button it isn't selected?
485 // Todo: save / restore slider states per image
487 if( button.IsSelected() )
490 ImageChannelControl prevIcc = mImageChannelControl;
492 if( mRadioButtons[0].IsSelected() )
494 mImageChannelControl = mIcc1;
496 else if( mRadioButtons[1].IsSelected() )
498 mImageChannelControl = mIcc2;
500 else if( mRadioButtons[2].IsSelected() )
502 mImageChannelControl = mIcc3;
507 prevIcc.SetVisibility( false );
510 if( mImageChannelControl )
512 mImageChannelControl.SetVisibility( true );
519 bool StylingApplication::OnCheckButtonChange( Button button )
521 Property::Index index = button.GetPropertyIndex("channel");
522 if( index != Property::INVALID_INDEX )
524 int channel = button.GetProperty<int>( index );
525 float value = mChannelSliders[channel].GetProperty<float>( Slider::Property::VALUE );
526 if( !button.IsSelected() )
528 // "Turn off" the channel's contribution
531 Property::Index channelIndex = GetChannelProperty( channel );
532 mImageChannelControl.SetProperty(channelIndex, value/100.0f);
537 bool StylingApplication::OnThemeButtonClicked( Button button )
539 int theme = button.GetProperty<int>(button.GetPropertyIndex("theme"));
540 const char* themePath=NULL;
546 themePath = DEMO_THEME_ONE_PATH;
551 themePath = DEMO_THEME_TWO_PATH;
556 themePath = DEMO_THEME_THREE_PATH;
561 StyleManager::Get().ApplyTheme( themePath );
566 bool StylingApplication::OnResetClicked( Button button )
570 mResetPopup = CreateResetPopup ();
573 Stage::GetCurrent().Add( mResetPopup );
575 mResetPopup.SetDisplayState( Popup::SHOWN );
579 bool StylingApplication::OnReset( Button button )
581 // todo: Reset the sliders for this image
582 for( int i=0; i<3; ++i )
584 mChannelSliders[i].SetProperty( Slider::Property::VALUE, 100.0f );
590 bool StylingApplication::OnResetCancelled( Button button )
596 bool StylingApplication::OnSliderChanged( Slider slider, float value )
598 // todo - change color channel's saturation
599 Property::Index index = slider.GetPropertyIndex("channel");
600 if( index != Property::INVALID_INDEX )
602 int channel = slider.GetProperty<int>( index );
603 if( mCheckButtons[channel].IsSelected() )
605 Property::Index channelIndex = GetChannelProperty( channel );
606 mImageChannelControl.SetProperty(channelIndex, value/100.0f);
612 void StylingApplication::HidePopup()
616 mResetPopup.SetDisplayState( Popup::HIDDEN );
620 void StylingApplication::PopupHidden()
624 // Clear down resources
625 mResetPopup.Unparent();
630 void StylingApplication::OnPan( Actor actor, const PanGesture& gesture )
632 Vector3 size = mContentPane.GetTargetSize();
633 mContentPane.SetSize( size.GetVectorXY() + gesture.displacement * 2.0f );
636 void StylingApplication::OnKeyEvent( const KeyEvent& keyEvent )
638 static int keyPressed = 0;
640 if( keyEvent.state == KeyEvent::Down)
642 if( keyPressed == 0 ) // Is this the first down event?
644 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
646 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
650 else if( keyEvent.keyPressedName.compare("Return") == 0 )
653 mCurrentTheme %= NUMBER_OF_THEMES;
655 StyleManager styleManager = StyleManager::Get();
656 switch( mCurrentTheme )
660 styleManager.ApplyTheme( DEMO_THEME_ONE_PATH );
661 printf("Changing to theme One\n");
666 styleManager.ApplyTheme( DEMO_THEME_TWO_PATH );
667 printf("Changing to theme Two\n");
672 styleManager.ApplyDefaultTheme();
673 printf("Changing to Toolkit theme\n");
681 else if( keyEvent.state == KeyEvent::Up )