// EXTERNAL INCLUDES
#include <cstring> // for strcmp
-#include <dali/public-api/events/touch-event.h>
+#include <dali/public-api/events/touch-data.h>
#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/object/type-registry-helper.h>
-#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/object/type-registry-helper.h>
#include <dali/devel-api/scripting/scripting.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
/**
* Button states and contents
DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "auto-repeating", BOOLEAN, AUTO_REPEATING )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initial-auto-repeating-delay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "next-auto-repeating-delay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating", BOOLEAN, AUTO_REPEATING )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE )
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselected-state-image", STRING, UNSELECTED_STATE_IMAGE )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-image", STRING, SELECTED_STATE_IMAGE )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-image", STRING, DISABLED_STATE_IMAGE )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselected-color", VECTOR4, UNSELECTED_COLOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-color", VECTOR4, SELECTED_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage", STRING, UNSELECTED_STATE_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage", STRING, SELECTED_STATE_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage", STRING, DISABLED_STATE_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor", VECTOR4, UNSELECTED_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor", VECTOR4, SELECTED_COLOR )
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label", MAP, LABEL )
// Deprecated properties:
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-text", STRING, LABEL_TEXT )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText", STRING, LABEL_TEXT )
// Signals:
DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED )
DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED )
-DALI_SIGNAL_REGISTRATION( Toolkit, Button, "state-changed", SIGNAL_STATE_CHANGED )
+DALI_SIGNAL_REGISTRATION( Toolkit, Button, "stateChanged", SIGNAL_STATE_CHANGED )
// Actions:
-DALI_ACTION_REGISTRATION( Toolkit, Button, "button-click", ACTION_BUTTON_CLICK )
+DALI_ACTION_REGISTRATION( Toolkit, Button, "buttonClick", ACTION_BUTTON_CLICK )
DALI_TYPE_REGISTRATION_END()
} // 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 ),
else
{
// If there is no existing content, create a new actor to use for flat color.
- SetupContent( mUnselectedContent, CreateSolidColorActor( mUnselectedColor ) );
+ Toolkit::Control unselectedContentActor = Toolkit::Control::New();
+ unselectedContentActor.SetBackgroundColor( mUnselectedColor );
+ SetupContent( mUnselectedContent, unselectedContentActor );
mUnselectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
}
}
else
{
// If there is no existing content, create a new actor to use for flat color.
- SetupContent( mSelectedContent, CreateSolidColorActor( mSelectedColor ) );
+ Toolkit::Control selectedContentActor = Toolkit::Control::New();
+ selectedContentActor.SetBackgroundColor( mSelectedColor );
+ SetupContent( mSelectedContent, selectedContentActor );
mSelectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
}
}
void Button::SetUnselectedImage( const std::string& filename )
{
- ImageActor newContent;
+ Toolkit::ImageView newContent;
if( !filename.empty() )
{
- Image resourceimage = Dali::ResourceImage::New( filename );
- if( resourceimage )
- {
- newContent = ImageActor::New( resourceimage );
- }
+ newContent = Toolkit::ImageView::New( filename );
}
else
{
- newContent = ImageActor::New();
+ newContent = Toolkit::ImageView::New();
}
if( newContent )
void Button::SetSelectedImage( const std::string& filename )
{
- ImageActor newContent;
+ Toolkit::ImageView newContent;
if( !filename.empty() )
{
- Image resourceimage = Dali::ResourceImage::New( filename );
- if( resourceimage )
- {
- newContent = ImageActor::New( resourceimage );
- }
+ newContent = Toolkit::ImageView::New( filename );
}
else
{
- newContent = ImageActor::New();
+ newContent = Toolkit::ImageView::New();
}
if( newContent )
void Button::SetBackgroundImage( const std::string& filename )
{
- Image resourceimage = Dali::ResourceImage::New( filename );
- if( resourceimage )
- {
- SetupContent( mBackgroundContent, ImageActor::New( resourceimage ) );
+ SetupContent( mBackgroundContent, Toolkit::ImageView::New( filename ) );
- OnBackgroundImageSet();
- RelayoutRequest();
- }
+ OnBackgroundImageSet();
+ RelayoutRequest();
}
Actor& Button::GetBackgroundImage()
void Button::SetSelectedBackgroundImage( const std::string& filename )
{
- Image resourceimage = Dali::ResourceImage::New( filename );
- if( resourceimage )
- {
- SetupContent( mSelectedBackgroundContent, ImageActor::New( resourceimage ) );
+ SetupContent( mSelectedBackgroundContent, Toolkit::ImageView::New( filename ) );
- OnSelectedBackgroundImageSet();
- RelayoutRequest();
- }
+ OnSelectedBackgroundImageSet();
+ RelayoutRequest();
}
Actor& Button::GetSelectedBackgroundImage()
void Button::SetDisabledImage( const std::string& filename )
{
- Image resourceimage = Dali::ResourceImage::New( filename );
- if( resourceimage )
- {
- SetupContent( mDisabledContent, ImageActor::New( resourceimage ) );
+ SetupContent( mDisabledContent, Toolkit::ImageView::New( filename ) );
- OnDisabledImageSet();
- RelayoutRequest();
- }
+ OnDisabledImageSet();
+ RelayoutRequest();
}
Actor& Button::GetDisabledImage()
void Button::SetDisabledSelectedImage( const std::string& filename )
{
- Image resourceimage = Dali::ResourceImage::New( filename );
- if( resourceimage )
- {
- SetupContent( mDisabledSelectedContent, ImageActor::New( resourceimage ) );
+ SetupContent( mDisabledSelectedContent, Toolkit::ImageView::New( filename ) );
- OnDisabledSelectedImageSet();
- RelayoutRequest();
- }
+ OnDisabledSelectedImageSet();
+ RelayoutRequest();
}
Actor& Button::GetDisabledSelectedImage()
void Button::SetDisabledBackgroundImage( const std::string& filename )
{
- Image resourceimage = Dali::ResourceImage::New( filename );
- if( resourceimage )
- {
- SetupContent( mDisabledBackgroundContent, ImageActor::New( resourceimage ) );
+ SetupContent( mDisabledBackgroundContent, Toolkit::ImageView::New( filename ) );
- OnDisabledBackgroundImageSet();
- RelayoutRequest();
- }
+ OnDisabledBackgroundImageSet();
+ RelayoutRequest();
}
Actor& Button::GetDisabledBackgroundImage()
return false;
}
-void Button::OnButtonStageDisconnection()
-{
- if( ButtonDown == mState )
- {
- if( !mTogglableButton )
- {
- Released();
-
- if( mAutoRepeating )
- {
- mAutoRepeatingTimer.Reset();
- }
- }
- }
-}
-
void Button::OnButtonDown()
{
if( !mTogglableButton )
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.
mState = ButtonDown;
break;
}
- case TouchPoint::Up:
+ case PointState::UP:
{
OnButtonUp(); // Notification for derived classes.
mState = ButtonUp;
break;
}
- case TouchPoint::Interrupted:
+ case PointState::INTERRUPTED:
{
OnTouchPointInterrupted(); // Notification for derived classes.
mState = ButtonUp;
break;
}
- case TouchPoint::Leave:
+ case PointState::LEAVE:
{
OnTouchPointLeave(); // Notification for derived classes.
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.
return false;
}
-void Button::OnInitialize()
-{
- Actor self = Self();
-
- mTapDetector = TapGestureDetector::New();
- mTapDetector.Attach( self );
- mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
-
- OnButtonInitialize();
-
- 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::OnControlStageDisconnection()
-{
- OnButtonStageDisconnection(); // Notification for derived classes.
- mState = ButtonUp;
-}
-
void Button::OnTap(Actor actor, const TapGesture& tap)
{
// Do nothing.
{
if( actor )
{
- actor.Unparent();
Self().Add( actor );
PrepareForTranstionOut( actor );
}
{
if( actor )
{
- actor.Unparent();
Self().Add( actor );
}
}