Previously would create another Toolkit::Control and set background.
Change-Id: I8377098a506b0a9b895e1ee77df646970af64a10
bool* mCallbackFlag;
};
-
-Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
-{
- BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
-
- // Create the image
- PixelBuffer* pixbuf = imageData.GetBuffer();
- unsigned int size = width * height;
-
- for( size_t i = 0; i < size; i++ )
- {
- pixbuf[i*4+0] = 0xFF * color.r;
- pixbuf[i*4+1] = 0xFF * color.g;
- pixbuf[i*4+2] = 0xFF * color.b;
- pixbuf[i*4+3] = 0xFF * color.a;
- }
-
- imageData.Update();
-
- return imageData;
-}
-
Dali::Integration::Point GetPointDownInside()
{
Dali::Integration::Point point;
END_TEST;
}
+
+int UtcDaliButtonSetSelectedColorP(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliButtonSetSelectedColorP");
+
+ PushButton pushButton = PushButton::New();
+ Stage::GetCurrent().Add( pushButton );
+
+ application.SendNotification();
+ application.Render();
+
+ const Vector4 SET_COLOR = Color::BLUE;
+
+ pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
+ pushButton.SetProperty( Button::Property::SELECTED_COLOR, SET_COLOR );
+
+ application.SendNotification();
+ application.Render();
+
+ Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
+
+ DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliButtonSetUnSelectedColorP(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliButtonSetUnSelectedColorP");
+
+ PushButton pushButton = PushButton::New();
+ Stage::GetCurrent().Add( pushButton );
+
+ application.SendNotification();
+ application.Render();
+
+ const Vector4 SET_COLOR = Color::BLUE;
+
+ pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
+ pushButton.SetProperty( Button::Property::UNSELECTED_COLOR, SET_COLOR );
+
+ application.SendNotification();
+ application.Render();
+
+ Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::UNSELECTED_COLOR );
+
+ DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
+
+ END_TEST;
+}
+
return point;
}
-Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
-{
- BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
-
- // Create the image
- PixelBuffer* pixbuf = imageData.GetBuffer();
- unsigned int size = width * height;
-
- for( size_t i = 0; i < size; i++ )
- {
- pixbuf[i*4+0] = 0xFF * color.r;
- pixbuf[i*4+1] = 0xFF * color.g;
- pixbuf[i*4+2] = 0xFF * color.b;
- pixbuf[i*4+3] = 0xFF * color.a;
- }
-
- imageData.Update();
-
- return imageData;
-}
-
} //namespace
int UtcDaliPushButtonConstructorP(void)
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
/**
* Button states and contents
}
}
-void Button::SetUnselectedColor( const Vector4& color )
+const Vector4 Button::GetUnselectedColor() const
+{
+ return mUnselectedColor;
+}
+
+void Button::SetColor( const Vector4& color, Button::PaintState selectedState )
{
- mUnselectedColor = color;
+ Actor& contentActor = mSelectedContent;
+ bool imageFileExists = false;
- if( mUnselectedContent && !GetUnselectedImageFilename().empty() )
+ if ( selectedState == SelectedState || selectedState == DisabledSelectedState )
{
- // If there is existing unselected content, change the color on it directly.
- mUnselectedContent.SetColor( mUnselectedColor );
+ mSelectedColor = color;
+ imageFileExists = !GetSelectedImageFilename().empty();
}
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 );
+ mUnselectedColor = color;
+ contentActor = mUnselectedContent;
+ imageFileExists = !GetUnselectedImageFilename().empty();
}
-}
-const Vector4 Button::GetUnselectedColor() const
-{
- return mUnselectedColor;
-}
-
-void Button::SetSelectedColor( const Vector4& color )
-{
- mSelectedColor = color;
-
- if( mSelectedContent && !GetSelectedImageFilename().empty() )
+ if( contentActor && imageFileExists )
{
// If there is existing unselected content, change the color on it directly.
- mSelectedContent.SetColor( mSelectedColor );
+ contentActor.SetColor( color );
}
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 );
+ Actor placementActor = Actor::New();
+ Toolkit::RendererFactory rendererFactory = Toolkit::RendererFactory::Get();
+ Toolkit::ControlRenderer colorRenderer;
+
+ Property::Map map;
+ map["rendererType"] = "color";
+ map["mixColor"] = color;
+
+ colorRenderer = rendererFactory.CreateControlRenderer( map );
+ colorRenderer.SetOnStage( placementActor );
+ SetupContent( contentActor, placementActor );
+ contentActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
}
}
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;
}
class Button : public Control
{
-protected:
-
- /**
- * Construct a new Button.
- */
- Button();
-
- /**
- * A reference counted object may only be deleted by calling Unreference()
- */
- virtual ~Button();
-
public:
/**
protected:
+ enum ButtonState
+ {
+ ButtonUp, ///< The button is up.
+ ButtonDown, ///< The button is down.
+ };
+
+ /**
+ * Button paint states.
+ */
+ enum PaintState
+ {
+ UnselectedState, ///< The button is unselected.
+ SelectedState, ///< The button is selected.
+ DisabledUnselectedState, ///< The button is disabled and unselected.
+ DisabledSelectedState, ///< The button is disabled and selected.
+ };
+
+ /**
+ * Enum to specify which decoration when getting and setting decorations.
+ */
+ enum DecorationState
+ {
+ UNSELECTED_DECORATION = 0,
+ SELECTED_DECORATION,
+ DECORATION_STATES
+ };
+
+ /**
+ * Construct a new Button.
+ */
+ Button();
+
+ /**
+ * A reference counted object may only be deleted by calling Unreference()
+ */
+ virtual ~Button();
/**
* @return A reference to the label actor.
*/
*/
void OnStageDisconnection();
+
private:
/**
void SetupContent( Actor& actorToModify, Actor newActor );
/**
- * Sets the color of the unselected image.
- * If no image exists, it is created.
- * @param[in] color The color to use.
- */
- void SetUnselectedColor( const Vector4& color );
-
- /**
* Gets the unselected content color.
* @return The currently used unselected color.
*/
const Vector4 GetUnselectedColor() const;
/**
- * Sets the color of the selected image.
- * If no image exists, it is created.
+ * Sets the color of button in selected or unselected state, if image also supplied this color will be appplied to it.
+ * If no visual exists, it is created.
* @param[in] color The color to use.
+ * @param[in] selectedState The state to apply the color to, SelectedState or DisabledUnselectedState.
*/
- void SetSelectedColor( const Vector4& color );
+ void SetColor( const Vector4& color, PaintState selectedState );
/**
* Gets the selected content color.
protected:
- enum ButtonState
- {
- ButtonUp, ///< The button is up.
- ButtonDown, ///< The button is down.
- };
-
- /**
- * Button paint states.
- */
- enum PaintState
- {
- UnselectedState, ///< The button is unselected.
- SelectedState, ///< The button is selected.
- DisabledUnselectedState, ///< The button is disabled and unselected.
- DisabledSelectedState, ///< The button is disabled and selected.
- };
-
- /**
- * Enum to specify which decoration when getting and setting decorations.
- */
- enum DecorationState
- {
- UNSELECTED_DECORATION = 0,
- SELECTED_DECORATION,
- DECORATION_STATES
- };
-
ButtonState GetState();
PaintState GetPaintState();
void SetDecoration( DecorationState state, Actor actor );