+ // Depending on button pressed, apply the style to the text label
+ bool OnStyleSelected( Toolkit::Button button )
+ {
+ if( button == mStyleButtons[ StyleType::TEXT_COLOR ] )
+ {
+ Animation animation = Animation::New( 2.f );
+ animation.AnimateTo( Property( mLabel, TextLabel::Property::TEXT_COLOR ), mSelectedColor, AlphaFunction::LINEAR );
+ animation.Play();
+ }
+ else if( button == mStyleButtons[ StyleType::OUTLINE ] )
+ {
+ Property::Map outlineMap;
+ float outlineWidth = OUTLINE_WIDTH;
+
+ if( mOutlineActive )
+ {
+ outlineWidth = ( mOutlineColor == mSelectedColor ) ? 0.0f : OUTLINE_WIDTH ; // toggles outline on/off
+ }
+ mOutlineActive = ( outlineWidth > 0.0f ) ? true : false;
+
+ mOutlineColor = mSelectedColor;
+ outlineMap["color"] = mOutlineColor;
+ outlineMap["width"] = outlineWidth;
+ mLabel.SetProperty( TextLabel::Property::OUTLINE, outlineMap );
+ }
+ else if( button == mStyleButtons[ StyleType::SHADOW ] )
+ {
+ Vector2 shadowOffset( SHADOW_OFFSET ); // Will be set to zeros if color already set
+ Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW_COLOR );
+ Vector4 currentShadowColor;
+ value.Get( currentShadowColor );
+
+ if ( mShadowActive )
+ {
+ // toggle shadow off ( zero offset ) if color is already set
+ shadowOffset = ( currentShadowColor == mSelectedColor ) ? Vector2::ZERO : Vector2( SHADOW_OFFSET );
+ }
+
+ mShadowActive = ( shadowOffset == Vector2::ZERO ) ? false : true;
+
+ Property::Map shadowMap;
+ shadowMap.Insert( "offset", shadowOffset );
+ shadowMap.Insert( "color", mSelectedColor );
+ shadowMap.Insert( "blurRadius", 2.0f );
+ mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap );
+ }
+ return true;
+ }
+
+ bool OnColorSelected( Toolkit::Button button )
+ {
+ for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
+ {
+ if ( mColorButtons[index] == button )
+ {
+ mSelectedColor = AVAILABLE_COLORS[ index ];
+ return true;
+ }
+ }
+ return true;
+ }
+
+ void ShowColorButtons()
+ {
+ for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
+ {
+ mColorButtons[index] = RadioButton::New();
+ mColorButtons[index].SetPosition( mButtonSize.width, mStageSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE - ( mButtonSize.width * (index+1) ) );
+ mColorButtons[index].SetSize( mButtonSize );
+ mColorButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnColorSelected );
+ mColorButtons[index].SetProperty( Button::Property::TOGGLABLE, true );
+ Property::Map propertyMap;
+ propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
+ propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
+ mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
+ mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap );
+
+ propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
+ propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
+ mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, propertyMap );
+
+ mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_VISUAL,
+ Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::BORDER )
+ .Add( BorderVisual::Property::COLOR, Color::WHITE )
+ .Add( BorderVisual::Property::SIZE, 2.0f )
+ .Add( BorderVisual::Property::ANTI_ALIASING, true ) );
+
+ Stage::GetCurrent().Add( mColorButtons[index] );
+ }
+ }
+
+
+ void HideColorButtons()
+ {
+ for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
+ {
+ UnparentAndReset( mColorButtons[index] );
+ }
+ }
+
+ void HideStyleButtons()
+ {
+ for( unsigned int index = 0; index < NUMBER_OF_STYLES; index++)
+ {
+ UnparentAndReset( mStyleButtons[index] );
+ }
+ }
+
+ bool OnStyleButtonClicked( Toolkit::Button button )
+ {
+ if ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() )
+ {
+ for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ )
+ {
+ mStyleButtons[index] = PushButton::New();
+ mStyleButtons[index].SetPosition( mButtonSize.width + ( mButtonSize.width * (index+1) ), mStageSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE );
+ mStyleButtons[index].SetSize( mButtonSize );
+ mStyleButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[ index ] );
+ mStyleButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE );
+ mStyleButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnStyleSelected );
+ Stage::GetCurrent().Add( mStyleButtons[index] );
+ }
+ ShowColorButtons();
+ }
+ else
+ {
+ // hide menu and colors
+ HideColorButtons();
+ HideStyleButtons();
+ }
+ return true;
+ }
+