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 )
97 application.InitSignal().Connect( this, &StylingApplication::Create );
100 StylingApplication::~StylingApplication()
104 void StylingApplication::Create( Application& application )
106 Stage stage = Stage::GetCurrent();
107 stage.KeyEventSignal().Connect(this, &StylingApplication::OnKeyEvent);
108 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
110 // Hide the indicator bar
111 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
113 mContentPane = CreateContentPane();
114 stage.Add( mContentPane );
115 mContentPane.SetSize( stage.GetSize() );
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 ) );
125 // Assign all rows the size negotiation property of fitting to children
126 for( unsigned int i = 0; i < contentLayout.GetRows(); ++i )
130 contentLayout.SetFitHeight(i); // Row 1 should fill
134 mContentPane.Add( contentLayout );
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 );
148 TableView imageSelectLayout = TableView::New( 1, 2 );
149 imageSelectLayout.SetName("ImageSelectLayout");
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 ) );
157 // Fit radio button column to child width, leave image to fill remainder
158 imageSelectLayout.SetFitWidth( 0 );
160 contentLayout.Add( imageSelectLayout );
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 ) );
171 imageSelectLayout.AddChild( radioButtonsLayout, TableView::CellPosition(0, 0) );
172 imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
174 const char* images[] = { SMALL_IMAGE_1, SMALL_IMAGE_2, SMALL_IMAGE_3 };
176 for( int i=0; i<3; ++i )
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) );
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 );
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 );
199 mRadioButtons[0].SetSelected( true );
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 ) );
207 imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER );
210 TableView channelSliderLayout = TableView::New( 3, 3 );
211 channelSliderLayout.SetName("ChannelSliderLayout");
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 ) );
220 // Set each row to fit to child height
221 channelSliderLayout.SetFitHeight( 0 );
222 channelSliderLayout.SetFitHeight( 1 );
223 channelSliderLayout.SetFitHeight( 2 );
225 // Set each column to fit to child width
226 channelSliderLayout.SetFitWidth( 0 );
227 channelSliderLayout.SetFitWidth( 1 );
229 contentLayout.Add( channelSliderLayout );
230 const char *checkboxLabels[3] = {"R", "G", "B"};
232 for( int i=0; i<3; ++i )
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 );
242 mCheckButtons[i].StateChangedSignal().Connect( this, &StylingApplication::OnCheckButtonChange );
243 mCheckButtons[i].RegisterProperty( "channel", i, Property::READ_WRITE );
245 channelSliderLayout.AddChild( mCheckButtons[i], TableView::CellPosition( i, 0 ) );
246 channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
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 );
257 channelSliderLayout.AddChild( label, TableView::CellPosition( i, 1 ) );
258 channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
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 );
275 mChannelSliders[i].RegisterProperty( "channel", i, Property::READ_WRITE );
277 channelSliderLayout.AddChild( mChannelSliders[i], TableView::CellPosition( i, 2 ) );
278 channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 2 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER );
280 mChannelSliders[i].ValueChangedSignal().Connect( this, &StylingApplication::OnSliderChanged );
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 );
289 contentLayout.Add( mResetButton );
290 contentLayout.SetCellAlignment( TableView::CellPosition( 3, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
292 TableView themeButtonLayout = TableView::New( 1, 4 );
293 themeButtonLayout.SetName("ThemeButtonsLayout");
294 themeButtonLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) );
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 );
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 );
311 for( int i=0; i<3; ++i )
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 ) );
324 mThemeButtons[0].SetLabelText( "Lite" ); // Lightweight changes on top of Dali
325 mThemeButtons[1].SetLabelText( "App1" ); // Different application style
326 mThemeButtons[2].SetLabelText( "App2" );
328 contentLayout.Add( themeButtonLayout );
331 Actor StylingApplication::CreateContentPane()
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 ) );
341 Actor StylingApplication::CreateResizableContentPane()
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 ) );
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 );
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 );
364 mPanGestureDetector = PanGestureDetector::New();
365 mPanGestureDetector.Attach( grabHandle );
366 mPanGestureDetector.DetectedSignal().Connect( this, &StylingApplication::OnPan );
371 Popup StylingApplication::CreateResetPopup()
373 Stage stage = Stage::GetCurrent();
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 );
385 popup.SetTitle( CreateTitle( "Reset channels" ) );
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 );
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 );
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 );
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 ) );
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 ) );
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 );
437 popup.SetFooter( footer );
441 TextLabel StylingApplication::CreateTitle( std::string title )
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 );
452 bool StylingApplication::OnButtonStateChange( Button button )
454 // Todo: save / restore slider states per image
456 if( mImageChannelControl )
458 if( mRadioButtons[0].IsSelected() )
460 mImageChannelControl.SetImage( BIG_IMAGE_1 );
462 else if( mRadioButtons[1].IsSelected() )
464 mImageChannelControl.SetImage( BIG_IMAGE_2 );
466 else if( mRadioButtons[2].IsSelected() )
468 mImageChannelControl.SetImage( BIG_IMAGE_3 );
474 bool StylingApplication::OnCheckButtonChange( Button button )
476 Property::Index index = button.GetPropertyIndex("channel");
477 if( index != Property::INVALID_INDEX )
479 int channel = button.GetProperty<int>( index );
480 float value = mChannelSliders[channel].GetProperty<float>( Slider::Property::VALUE );
481 if( !button.IsSelected() )
483 // "Turn off" the channel's contribution
486 Property::Index channelIndex = GetChannelProperty( channel );
487 mImageChannelControl.SetProperty(channelIndex, value/100.0f);
492 bool StylingApplication::OnThemeButtonClicked( Button button )
494 int theme = button.GetProperty<int>(button.GetPropertyIndex("theme"));
495 const char* themePath=NULL;
501 themePath = DEMO_THEME_ONE_PATH;
506 themePath = DEMO_THEME_TWO_PATH;
511 themePath = DEMO_THEME_THREE_PATH;
515 StyleManager::Get().ApplyTheme( themePath );
520 bool StylingApplication::OnResetClicked( Button button )
524 mResetPopup = CreateResetPopup ();
527 Stage::GetCurrent().Add( mResetPopup );
529 mResetPopup.SetDisplayState( Popup::SHOWN );
533 bool StylingApplication::OnReset( Button button )
535 // todo: Reset the sliders for this image
536 for( int i=0; i<3; ++i )
538 mChannelSliders[i].SetProperty( Slider::Property::VALUE, 100.0f );
544 bool StylingApplication::OnResetCancelled( Button button )
550 bool StylingApplication::OnSliderChanged( Slider slider, float value )
552 // todo - change color channel's saturation
553 Property::Index index = slider.GetPropertyIndex("channel");
554 if( index != Property::INVALID_INDEX )
556 int channel = slider.GetProperty<int>( index );
557 if( mCheckButtons[channel].IsSelected() )
559 Property::Index channelIndex = GetChannelProperty( channel );
560 mImageChannelControl.SetProperty(channelIndex, value/100.0f);
566 void StylingApplication::HidePopup()
570 mResetPopup.SetDisplayState( Popup::HIDDEN );
574 void StylingApplication::PopupHidden()
578 // Clear down resources
579 mResetPopup.Unparent();
584 void StylingApplication::OnPan( Actor actor, const PanGesture& gesture )
586 Vector3 size = mContentPane.GetTargetSize();
587 mContentPane.SetSize( size.GetVectorXY() + gesture.displacement * 2.0f );
590 void StylingApplication::OnKeyEvent( const KeyEvent& keyEvent )
592 static int keyPressed = 0;
594 if( keyEvent.state == KeyEvent::Down)
596 if( keyPressed == 0 ) // Is this the first down event?
598 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
600 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
604 else if( keyEvent.keyPressedName.compare("Return") == 0 )
607 mCurrentTheme %= NUMBER_OF_THEMES;
609 StyleManager styleManager = StyleManager::Get();
610 switch( mCurrentTheme )
614 styleManager.ApplyTheme( DEMO_THEME_ONE_PATH );
615 printf("Changing to theme One\n");
620 styleManager.ApplyTheme( DEMO_THEME_TWO_PATH );
621 printf("Changing to theme Two\n");
626 styleManager.ApplyDefaultTheme();
627 printf("Changing to Toolkit theme\n");
635 else if( keyEvent.state == KeyEvent::Up )