X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.cpp;h=9bf32effb04b5d306950964a1de41612992bf3c9;hp=dc00a3cd1beccd00507f27dbdb3bda9fe21b97bd;hb=c3f9162ab11786380e2ec9c55f217c2daf7722e8;hpb=764cd70c98c4f9393c8b50abb7b5a16484c28977 diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index dc00a3c..9bf32ef 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,9 @@ // INTERNAL INCLUDES #include #include +#include +#include + /** * Button states and contents @@ -527,46 +530,56 @@ void Button::SetupContent( Actor& actorToModify, Actor newActor ) } } -void Button::SetUnselectedColor( const Vector4& color ) -{ - mUnselectedColor = color; - - if( mUnselectedContent && !GetUnselectedImageFilename().empty() ) - { - // If there is existing unselected content, change the color on it directly. - mUnselectedContent.SetColor( mUnselectedColor ); - } - else - { - // If there is no existing content, create a new actor to use for flat color. - Toolkit::Control unselectedContentActor = Toolkit::Control::New(); - unselectedContentActor.SetBackgroundColor( mUnselectedColor ); - SetupContent( mUnselectedContent, unselectedContentActor ); - mUnselectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - } -} - const Vector4 Button::GetUnselectedColor() const { return mUnselectedColor; } -void Button::SetSelectedColor( const Vector4& color ) +void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) { - mSelectedColor = color; + Actor* contentActor = NULL; // Using a pointer as SetupContent assigns the new Actor to this. + bool imageFileExists = false; + Property::Index visualIndex = Toolkit::Button::Property::SELECTED_STATE_IMAGE; - if( mSelectedContent && !GetSelectedImageFilename().empty() ) + if ( selectedState == SelectedState || selectedState == DisabledSelectedState ) { - // If there is existing unselected content, change the color on it directly. - mSelectedContent.SetColor( mSelectedColor ); + mSelectedColor = color; + contentActor = &mSelectedContent; + imageFileExists = !GetSelectedImageFilename().empty(); } else { - // If there is no existing content, create a new actor to use for flat color. - Toolkit::Control selectedContentActor = Toolkit::Control::New(); - selectedContentActor.SetBackgroundColor( mSelectedColor ); - SetupContent( mSelectedContent, selectedContentActor ); - mSelectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mUnselectedColor = color; + contentActor = &mUnselectedContent; + imageFileExists = !GetUnselectedImageFilename().empty(); + visualIndex = Toolkit::Button::Property::UNSELECTED_STATE_IMAGE; + } + + if ( contentActor ) + { + if( imageFileExists ) + { + // If there is existing unselected content, change the color on it directly. + contentActor->SetColor( color ); + } + else + { + // If there is no existing content, create a new actor to use for flat color. + Actor placementActor = Actor::New(); + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + + Property::Map map; + map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; + map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; + + visual = visualFactory.CreateVisual( map ); + + RegisterVisual( visualIndex, placementActor, visual ); + + SetupContent( *contentActor, placementActor ); // + contentActor->SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + } } } @@ -1386,13 +1399,13 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope case Toolkit::Button::Property::UNSELECTED_COLOR: { - GetImplementation( button ).SetUnselectedColor( value.Get< Vector4 >() ); + GetImplementation( button ).SetColor( value.Get< Vector4 >(), UnselectedState ); break; } case Toolkit::Button::Property::SELECTED_COLOR: { - GetImplementation( button ).SetSelectedColor( value.Get< Vector4 >() ); + GetImplementation( button ).SetColor( value.Get< Vector4 >(), SelectedState ); break; }