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=fcd046825510e55ad8e011774ca47d97360dc7fc;hp=6df5fcffcce007bb09504d747c0806b87c57c007;hb=958bd01cb1bc4cf43cbe740a7b041927d9d34ed6;hpb=e5ca10134c73ca0588f893adde82694ad907dd8d diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 6df5fcf..fcd0468 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -20,15 +20,16 @@ // EXTERNAL INCLUDES #include // for strcmp -#include +#include #include #include -#include +#include #include // INTERNAL INCLUDES #include #include +#include /** * Button states and contents @@ -108,7 +109,7 @@ const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); } // unnamed namespace Button::Button() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), mAutoRepeatingTimer(), mUnselectedColor( Color::WHITE ), // The natural colors of the specified images will be used by default. mSelectedColor( Color::WHITE ), @@ -527,46 +528,48 @@ void Button::SetupContent( Actor& actorToModify, Actor newActor ) } } -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 ); } } @@ -722,32 +725,6 @@ std::string Button::GetSelectedImageFilename() const return std::string(); } -std::string Button::GetBackgroundImageFilename() const -{ - if( mBackgroundContent ) - { - ResourceImage image = ResourceImage::DownCast( mBackgroundContent ); - if( image ) - { - return image.GetUrl(); - } - } - return std::string(); -} - -std::string Button::GetSelectedBackgroundImageFilename() const -{ - if( mSelectedBackgroundContent ) - { - ResourceImage image = ResourceImage::DownCast( mSelectedBackgroundContent ); - if( image ) - { - return image.GetUrl(); - } - } - return std::string(); -} - std::string Button::GetDisabledImageFilename() const { if( mDisabledContent ) @@ -761,32 +738,6 @@ std::string Button::GetDisabledImageFilename() const return std::string(); } -std::string Button::GetDisabledSelectedImageFilename() const -{ - if( mDisabledSelectedContent ) - { - ResourceImage image = ResourceImage::DownCast( mDisabledSelectedContent ); - if( image ) - { - return image.GetUrl(); - } - } - return std::string(); -} - -std::string Button::GetDisabledBackgroundImageFilename() const -{ - if( mDisabledBackgroundContent ) - { - ResourceImage image = ResourceImage::DownCast( mDisabledBackgroundContent ); - if( image ) - { - return image.GetUrl(); - } - } - return std::string(); -} - bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ) { bool ret = false; @@ -942,15 +893,62 @@ bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tr return connected; } -bool Button::OnTouchEvent(const TouchEvent& event) +void Button::OnInitialize() +{ + Actor self = Self(); + + mTapDetector = TapGestureDetector::New(); + mTapDetector.Attach( self ); + mTapDetector.DetectedSignal().Connect(this, &Button::OnTap); + + self.SetKeyboardFocusable( true ); + + self.TouchSignal().Connect( this, &Button::OnTouch ); +} + +bool Button::OnAccessibilityActivated() +{ + return OnKeyboardEnter(); +} + +bool Button::OnKeyboardEnter() +{ + // When the enter key is pressed, or button is activated, the click action is performed. + Property::Map attributes; + bool ret = DoClickAction( attributes ); + + return ret; +} + +void Button::OnStageDisconnection() +{ + if( ButtonDown == mState ) + { + if( !mTogglableButton ) + { + Released(); + + if( mAutoRepeating ) + { + mAutoRepeatingTimer.Reset(); + } + } + } + + mState = ButtonUp; + + Control::OnStageDisconnection(); +} + +bool Button::OnTouch( Actor actor, const TouchData& touch ) { // Only events are processed when the button is not disabled and the touch event has only // one touch point. - if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) ) + if( ( !mDisabled ) && ( 1 == touch.GetPointCount() ) ) { - switch( event.GetPoint(0).state ) + switch( touch.GetState( 0 ) ) { - case TouchPoint::Down: + case PointState::DOWN: { OnButtonDown(); // Notification for derived classes. @@ -958,7 +956,7 @@ bool Button::OnTouchEvent(const TouchEvent& event) mState = ButtonDown; break; } - case TouchPoint::Up: + case PointState::UP: { OnButtonUp(); // Notification for derived classes. @@ -966,7 +964,7 @@ bool Button::OnTouchEvent(const TouchEvent& event) mState = ButtonUp; break; } - case TouchPoint::Interrupted: + case PointState::INTERRUPTED: { OnTouchPointInterrupted(); // Notification for derived classes. @@ -974,7 +972,7 @@ bool Button::OnTouchEvent(const TouchEvent& event) mState = ButtonUp; break; } - case TouchPoint::Leave: + case PointState::LEAVE: { OnTouchPointLeave(); // Notification for derived classes. @@ -982,20 +980,15 @@ bool Button::OnTouchEvent(const TouchEvent& event) mState = ButtonUp; break; } - case TouchPoint::Motion: - case TouchPoint::Stationary: // FALLTHROUGH + case PointState::MOTION: + case PointState::STATIONARY: // FALLTHROUGH { // Nothing to do break; } - default: - { - DALI_ASSERT_ALWAYS( !"Point status unhandled." ); - break; - } } } - else if( 1 < event.GetPointCount() ) + else if( 1 < touch.GetPointCount() ) { OnTouchPointLeave(); // Notification for derived classes. @@ -1006,51 +999,6 @@ bool Button::OnTouchEvent(const TouchEvent& event) return false; } -void Button::OnInitialize() -{ - Actor self = Self(); - - mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach( self ); - mTapDetector.DetectedSignal().Connect(this, &Button::OnTap); - - self.SetKeyboardFocusable( true ); -} - -bool Button::OnAccessibilityActivated() -{ - return OnKeyboardEnter(); -} - -bool Button::OnKeyboardEnter() -{ - // When the enter key is pressed, or button is activated, the click action is performed. - Property::Map attributes; - bool ret = DoClickAction( attributes ); - - return ret; -} - -void Button::OnStageDisconnection() -{ - if( ButtonDown == mState ) - { - if( !mTogglableButton ) - { - Released(); - - if( mAutoRepeating ) - { - mAutoRepeatingTimer.Reset(); - } - } - } - - mState = ButtonUp; - - Control::OnStageDisconnection(); -} - void Button::OnTap(Actor actor, const TapGesture& tap) { // Do nothing. @@ -1441,13 +1389,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; }