//Test properties
std::string testString = "Hello World";
popup.SetProperty(popup.GetPropertyIndex("title"), testString);
- DALI_TEST_EQUALS( testString, popup.GetTitle().GetText(), TEST_LOCATION );
+ DALI_TEST_EQUALS( testString, popup.GetTitle(), TEST_LOCATION );
END_TEST;
}
int UtcDaliPopupSetTitle(void)
{
- ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
- tet_infoline(" UtcDaliPopupSetTitle");
-
- // Create the Popup actor
- Popup popup = Popup::New();
- Stage::GetCurrent().Add( popup );
- // Put in show state so it's layer is connected to popup (for ancestor check).
- popup.SetState(Popup::POPUP_SHOW, 0.0f);
-
- TextView titleActor = TextView::New();
- titleActor.SetText("title");
-
- DALI_TEST_CHECK( !popup.GetTitle() );
- popup.SetTitle(titleActor);
- DALI_TEST_CHECK( popup.GetTitle() == titleActor );
- DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
- // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
- DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
-
- TextView titleActor2 = TextView::New();
- titleActor2.SetText("anothertitle");
- popup.SetTitle(titleActor2);
- DALI_TEST_CHECK( popup.GetTitle() != titleActor );
- DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
- DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "anothertitle") );
- // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
- DALI_TEST_CHECK( HasAncestor(titleActor2, popup) );
- END_TEST;
-}
-
-int UtcDaliPopupSetTitleText(void)
-{
- ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
- tet_infoline(" UtcDaliPopupSetTitleText");
-
- // Create the Popup actor
- Popup popup = Popup::New();
- Stage::GetCurrent().Add( popup );
- // Put in show state so it's layer is connected to popup (for ancestor check).
- popup.SetState(Popup::POPUP_SHOW, 0.0f);
-
- TextView titleActor = TextView::New();
- titleActor.SetText("title");
-
- DALI_TEST_CHECK( !popup.GetTitle() );
- popup.SetTitle(titleActor);
- DALI_TEST_CHECK( popup.GetTitle() == titleActor );
- DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
- // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
- DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
-
- // this text should replace titleImage actor.
- popup.SetTitle("newtext");
- DALI_TEST_CHECK( popup.GetTitle() != titleActor );
- DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "newtext") );
- // verify titleActor is no longer inside popup. (been displaced by newtext actor)
- DALI_TEST_CHECK( !HasAncestor(titleActor, popup) );
+ // TODO
END_TEST;
}
PushButton button1 = PushButton::New();
PushButton button2 = PushButton::New();
- button1.SetPreferredSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
+ button1.SetSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
popup.AddButton(button1);
- button2.SetPreferredSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
+ button2.SetSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
popup.AddButton(button2);
// Showing/Hiding popup, results in all child Actors being
Actor imageActor;
Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
- ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
- imageActor01.SetSize( 20.f, 20.f );
-
- Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
- ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
- imageActor02.SetSize( 40.f, 40.f );
-
- Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
- ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
- imageActor03.SetSize( 60.f, 60.f );
-
- Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
- ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
- imageActor04.SetSize( 80.f, 80.f );
-
- Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
- ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
- imageActor05.SetSize( 100.f, 100.f );
Vector3 size;
PushButton pushButton = PushButton::New();
+ Stage::GetCurrent().Add( pushButton );
application.SendNotification();
application.Render();
application.SendNotification();
application.Render();
- size = pushButton.GetButtonImage().GetCurrentSize();
+ size = pushButton.GetCurrentSize();
DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
- pushButton.SetButtonImage( imageActor01 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetButtonImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
-
- pushButton.SetBackgroundImage( image02 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetBackgroundImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
-
- pushButton.SetBackgroundImage( imageActor02 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetBackgroundImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
-
- pushButton.SetSelectedImage( image03 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetSelectedImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
-
- pushButton.SetSelectedImage( imageActor03 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetSelectedImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
-
- pushButton.SetDisabledBackgroundImage( image04 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetDisabledBackgroundImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
-
- pushButton.SetDisabledBackgroundImage( imageActor04 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetDisabledBackgroundImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
-
- pushButton.SetDisabledImage( image05 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetDisabledImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
-
- pushButton.SetDisabledImage( imageActor05 );
-
- application.SendNotification();
- application.Render();
-
- size = pushButton.GetDisabledImage().GetCurrentSize();
-
- DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
- DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
END_TEST;
}
application.SendNotification();
application.Render();
- TextView textView;
-
pushButton.SetLabel( STR );
- textView = TextView::DownCast( pushButton.GetLabel() );
- DALI_TEST_CHECK( STR == textView.GetText() );
-
- TextView text = TextView::New( STR );
- pushButton.SetLabel( text );
-
- textView = TextView::DownCast( pushButton.GetLabel() );
- DALI_TEST_CHECK( STR == textView.GetText() );
END_TEST;
}
#include <dali/public-api/scripting/scripting.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+ /**
+ * Button states and contents
+ * (3) mSelectedContent
+ * (2) mButtonContent (2) mSelectedBackgroundContent
+ * (1) mBackgroundContent (1) mBackgroundContent
+ * < unselected > ----------------------- < selected >
+ * | OnSelect() |
+ * | OnDisabled() | OnDisabled()
+ * | |
+ * < disabled > < disabled-selected >
+ * (2) mDisabledContent (2) mDisabledSelectedContent
+ * (1) mDisabledBackgroundContent (1) mDisabledBackgroundContent
+ *
+ * The drawing order of child actors is as follows.
+ *
+ * Top mLabel
+ * | mButtonContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent
+ * | mSelectedBackgroundContent
+ * Bottom mBackgroundContent / mDisabledBackgroundContent
+ *
+ * Some of contents may be missed.
+ * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image.
+ */
+
namespace Dali
{
mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
mAnimationTime( 0.0f ),
mClickActionPerforming( false ),
- mState( ButtonUp )
+ mState( ButtonUp ),
+ mPaintState( UnselectedState )
{
}
{
if( disabled != mDisabled )
{
+ unsigned int backgroundIndex;
+ unsigned int buttonIndex;
+
+ bool animationStarted = false;
+
mDisabled = disabled;
- OnDisabled( mDisabled );
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledUnselectedState;
+ }
+ break;
+ }
+ case SelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case DisabledSelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+ InsertChild( backgroundIndex, mBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledUnselectedState;
+ }
+ break;
+ }
+ case UnselectedDisabledTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledUnselectedState;
+ }
+ break;
+ }
+ case SelectedDisabledTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ }
}
}
if( mSelected )
{
// Emit a signal is not wanted, only change the appearance.
- OnSelected( false );
-
- mSelected = false;
-
- RelayoutRequest();
+ SetSelected( false, false );
}
}
}
{
if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
{
- // Notifies the derived class the button has been selected.
- OnSelected( selected );
+ SetSelected( selected, true );
+ }
+ }
- mSelected = selected;
+ void Button::SetSelected( bool selected, bool emitSignal )
+ {
+ unsigned int buttonIndex, backgroundIndex;
+ bool animationStarted = false;
+ mSelected = selected;
+
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case SelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 2;
+ }
+ else
+ {
+ backgroundIndex = 1;
+ }
+ }
+ else if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+
+ if( emitSignal )
+ {
Toolkit::Button handle( GetOwner() );
// Emit signal.
mStateChangedSignal.Emit( handle );
-
- RelayoutRequest();
}
+
+ RelayoutRequest();
}
bool Button::IsSelected() const
void Button::SetLabel( const std::string& label )
{
- Toolkit::TextView textView = Toolkit::TextView::New( label );
- textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button
- SetLabel( textView );
+ Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
+ SetLabel( textLabel );
}
void Button::SetLabel( Actor label )
}
mLabel = label;
+ mLabel.SetPosition( 0.f, 0.f );
+
+ // label should be the top of the button
+ Self().Add( mLabel );
OnLabelSet();
return mLabel;
}
+ void Button::SetButtonImage( Actor image )
+ {
+ StopAllAnimations();
+
+ if( mButtonContent && mButtonContent.GetParent() )
+ {
+ Self().Remove( mButtonContent );
+ }
+
+ mButtonContent = image;
+
+ mButtonContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mButtonContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mButtonContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == UnselectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mButtonContent );
+ }
+
+ OnButtonImageSet();
+ }
+
Actor Button::GetButtonImage() const
{
return mButtonContent;
return mButtonContent;
}
+ void Button::SetSelectedImage( Actor image )
+ {
+ StopAllAnimations();
+
+ if( mSelectedContent && mSelectedContent.GetParent() )
+ {
+ Self().Remove( mSelectedContent );
+ }
+
+ mSelectedContent = image;
+
+ mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mSelectedContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == SelectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mSelectedContent );
+ }
+
+ OnSelectedImageSet();
+ }
+
Actor Button::GetSelectedImage() const
{
return mSelectedContent;
return mSelectedContent;
}
+ void Button::SetBackgroundImage( Actor image )
+ {
+ StopAllAnimations();
+
+ if( mBackgroundContent && mBackgroundContent.GetParent() )
+ {
+ Self().Remove( mBackgroundContent );
+ }
+
+ mBackgroundContent = image;
+
+ mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mBackgroundContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == UnselectedState || mPaintState == SelectedState )
+ {
+ Self().Insert( 0, mBackgroundContent );
+ }
+
+ OnBackgroundImageSet();
+ }
+
Actor Button::GetBackgroundImage() const
{
return mBackgroundContent;
return mBackgroundContent;
}
+ void Button::SetSelectedBackgroundImage( Actor image )
+ {
+ StopAllAnimations();
+
+ if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
+ {
+ Self().Remove( mSelectedBackgroundContent );
+ }
+
+ mSelectedBackgroundContent = image;
+
+ mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == SelectedState )
+ {
+ if( mBackgroundContent )
+ {
+ Self().Insert( 1, mSelectedBackgroundContent );
+ }
+ else
+ {
+ Self().Insert( 0, mSelectedBackgroundContent );
+ }
+ }
+
+ OnSelectedBackgroundImageSet();
+ }
+
+ Actor Button::GetSelectedBackgroundImage() const
+ {
+ return mSelectedBackgroundContent;
+ }
+
+ Actor& Button::GetSelectedBackgroundImage()
+ {
+ return mSelectedBackgroundContent;
+ }
+
+ void Button::SetDisabledImage( Actor image )
+ {
+ StopAllAnimations();
+
+ if( mDisabledContent && mDisabledContent.GetParent() )
+ {
+ Self().Remove( mDisabledContent );
+ }
+
+ mDisabledContent = image;
+
+ mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mDisabledContent );
+ }
+
+ OnDisabledImageSet();
+ }
+
Actor Button::GetDisabledImage() const
{
return mDisabledContent;
return mDisabledContent;
}
+ void Button::SetDisabledSelectedImage( Actor image )
+ {
+ StopAllAnimations();
+
+ if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
+ {
+ Self().Remove( mDisabledSelectedContent );
+ }
+
+ mDisabledSelectedContent = image;
+
+ mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledSelectedContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == DisabledSelectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mDisabledSelectedContent );
+ }
+
+ OnDisabledSelectedImageSet();
+ }
+
Actor Button::GetDisabledSelectedImage() const
{
return mDisabledSelectedContent;
return mDisabledSelectedContent;
}
+ void Button::SetDisabledBackgroundImage( Actor image )
+ {
+ StopAllAnimations();
+
+ if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
+ {
+ Self().Remove( mDisabledBackgroundContent );
+ }
+
+ mDisabledBackgroundContent = image;
+
+ mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
+ {
+ Self().Insert( 0, mDisabledBackgroundContent );
+ }
+
+ OnDisabledBackgroundImageSet();
+ }
+
Actor Button::GetDisabledBackgroundImage() const
{
return mDisabledBackgroundContent;
}
}
+ void Button::UpdatePaintTransitionState()
+ {
+ switch( mPaintState )
+ {
+ case UnselectedSelectedTransition:
+ {
+ RemoveChild( mButtonContent );
+ mPaintState = SelectedState;
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ RemoveChild( mSelectedBackgroundContent );
+ RemoveChild( mSelectedContent );
+ mPaintState = UnselectedState;
+ break;
+ }
+ case UnselectedDisabledTransition:
+ {
+ RemoveChild( mBackgroundContent );
+ RemoveChild( mButtonContent );
+ mPaintState = DisabledUnselectedState;
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ RemoveChild( mDisabledBackgroundContent );
+ RemoveChild( mDisabledContent );
+ mPaintState = UnselectedState;
+ break;
+ }
+ case SelectedDisabledTransition:
+ {
+ RemoveChild( mBackgroundContent );
+ RemoveChild( mSelectedBackgroundContent );
+ RemoveChild( mSelectedContent );
+ mPaintState = DisabledSelectedState;
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ RemoveChild( mDisabledBackgroundContent );
+ RemoveChild( mDisabledSelectedContent );
+ mPaintState = SelectedState;
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ }
+
void Button::OnButtonStageDisconnection()
{
if( ButtonDown == mState )
{
if( !mTogglableButton )
{
- Toolkit::Button handle( GetOwner() );
-
- // Notifies the derived class the button has been released.
- OnReleased();
+ Released();
if( mAutoRepeating )
{
{
Toolkit::Button handle( GetOwner() );
- // Notifies the derived class the button has been pressed.
- OnPressed();
+ Pressed();
if( mAutoRepeating )
{
}
else
{
- // Notifies the derived class the button has been clicked.
- OnReleased();
- OnClicked();
+ Released();
if( mAutoRepeating )
{
{
Toolkit::Button handle( GetOwner() );
- // Notifies the derived class the button has been released.
- OnReleased();
+ Released();
if( mAutoRepeating )
{
OnButtonInitialize();
+ self.SetDrawMode( DrawMode::OVERLAY );
self.SetKeyboardFocusable( true );
}
DoClickAction( attributes );
}
+ void Button::OnControlStageDisconnection()
+ {
+ OnButtonStageDisconnection(); // Notification for derived classes.
+ mState = ButtonUp;
+ }
+
void Button::OnTap(Actor actor, const TapGesture& tap)
{
// Do nothing.
// Restart the autorepeat timer.
SetUpTimer( mNextAutoRepeatingDelay );
- Toolkit::Button handle( GetOwner() );
+ Pressed();
- // Notifies the derived class the button has been pressed.
- OnPressed();
+ Toolkit::Button handle( GetOwner() );
//Emit signal.
consumed = mReleasedSignal.Emit( handle );
return consumed;
}
- void Button::OnControlStageDisconnection()
+ void Button::Pressed()
{
- OnButtonStageDisconnection(); // Notification for derived classes.
- mState = ButtonUp;
+ unsigned int buttonIndex, backgroundIndex;
+ bool animationStarted = false;
+
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been pressed.
+ animationStarted = OnPressed();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ // Notifies the derived class the button has been pressed.
+ animationStarted = OnPressed();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 2;
+ }
+ else
+ {
+ backgroundIndex = 1;
+ }
+ }
+ else if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been pressed.
+ animationStarted = OnPressed();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ void Button::Released()
+ {
+ unsigned int buttonIndex;
+ bool animationStarted = false;
+
+ switch( mPaintState )
+ {
+ case SelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been released.
+ animationStarted = OnReleased();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ // Notifies the derived class the button has been released.
+ animationStarted = OnReleased();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been released.
+ animationStarted = OnReleased();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
}
Button::ButtonState Button::GetState()
return mState;
}
+ Button::PaintState Button::GetPaintState()
+ {
+ return mPaintState;
+ }
+
+ void Button::InsertChild( unsigned int index, Actor& actor )
+ {
+ if( actor )
+ {
+ Self().Insert( index, actor);
+ }
+ }
+
+ void Button::RemoveChild( Actor& actor )
+ {
+ if( actor && actor.GetParent() )
+ {
+ Self().Remove( actor );
+ }
+ }
+
+ unsigned int Button::FindChildIndex( Actor& actor )
+ {
+ Actor self = Self();
+ unsigned int childrenNum = self.GetChildCount();
+
+ for( unsigned int i = 0; i < childrenNum; i++ )
+ {
+ Actor child = self.GetChildAt( i );
+ if( child == actor )
+ {
+ return i;
+ }
+ }
+
+ return childrenNum;
+ }
+
void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
{
Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
namespace Dali
{
{
const float TEXT_PADDING = 12.0f;
-
- const float LABEL_DEPTH( 0.75f );
- const float FOREGROUND_DEPTH( 0.5f );
- const float BACKGROUND_DEPTH( 0.25f );
-
const float ANIMATION_TIME( 0.2f );
BaseHandle Create()
PushButton::PushButton()
: Button(),
- mSize(),
- mPaintState( UnselectedState )
+ mSize()
{
SetAnimationTime( ANIMATION_TIME );
}
{
}
- void PushButton::SetButtonImage( Actor image )
+ void PushButton::OnButtonInitialize()
{
- Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
-
- switch( mPaintState )
- {
- case UnselectedState:
- {
- if( buttonImage && buttonImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Foreground, buttonImage );
-
- buttonImage = image;
-
- FadeInImage( buttonImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- buttonImage = image;
- Self().Insert( 0, buttonImage );
- }
- break;
- }
- case UnselectedSelectedTransition: // FALLTHROUGH
- case UnselectedDisabledTransition:
- {
- float opacity = 1.f;
- if( fadeOutButtonImage )
- {
- opacity = fadeOutButtonImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
-
- // Replaces the button image.
- buttonImage = image;
-
- Self().Insert( 0, buttonImage );
- FadeOutImage( Foreground, buttonImage, opacity );
-
- StartFadeOutAnimation();
- break;
- }
- case SelectedUnselectedTransition: // FALLTHROUGH
- case DisabledUnselectedTransition:
- {
- StopFadeInAnimation();
- Self().Remove( buttonImage );
-
- buttonImage = image;
-
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeInAnimation();
- break;
- }
- default:
- buttonImage = image;
- break;
- }
+ // Push button requires the Leave event.
+ Actor self = Self();
+ self.SetLeaveRequired( true );
- buttonImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- buttonImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
- buttonImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
- buttonImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- buttonImage.SetName( "BUTTON_IMAGE" );
+ // Set resize policy to natural size so that buttons will resize to background images
+ self.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
}
- void PushButton::SetSelectedImage( Actor image )
+ void PushButton::OnLabelSet()
{
- Actor& selectedImage = GetSelectedImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& label = GetLabel();
- switch( mPaintState )
+ if( label )
{
- case SelectedState:
- {
- if( selectedImage && selectedImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Foreground, selectedImage );
-
- selectedImage = image;
+ label.SetAnchorPoint( AnchorPoint::CENTER );
+ label.SetParentOrigin( ParentOrigin::CENTER );
+ label.SetSize( mSize );
+ }
+ }
- FadeInImage( selectedImage, 0.0f, 0 );
+ void PushButton::OnButtonImageSet()
+ {
+ Actor& buttonImage = GetButtonImage();
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- selectedImage = image;
- Self().Insert( 0, selectedImage );
- }
- break;
- }
- case SelectedUnselectedTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- float opacity = 1.f;
- if( fadeOutButtonImage )
- {
- opacity = fadeOutButtonImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
+ buttonImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- // Replaces the button image.
- selectedImage = image;
+ buttonImage.RelayoutRequestTree();
- Self().Insert( 0, selectedImage );
- FadeOutImage( Foreground, selectedImage, opacity );
+ RelayoutRequest();
+ }
- StartFadeOutAnimation();
- break;
- }
- case UnselectedSelectedTransition: // FALLTHROUGH
- case DisabledSelectedTransition:
- {
- StopFadeInAnimation();
- Self().Remove( selectedImage );
+ void PushButton::OnSelectedImageSet()
+ {
+ Actor& selectedImage = GetSelectedImage();
- selectedImage = image;
+ selectedImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- FadeInImage( selectedImage, 0.0f, 0 );
- StartFadeInAnimation();
- break;
- }
- default:
- selectedImage = image;
- break;
- }
+ selectedImage.RelayoutRequestTree();
- selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
- selectedImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
- selectedImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ RelayoutRequest();
}
- void PushButton::SetBackgroundImage( Actor image )
+ void PushButton::OnBackgroundImageSet()
{
Actor& backgroundImage = GetBackgroundImage();
- Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage();
- switch( mPaintState )
- {
- case UnselectedState: // FALLTHROUGH
- case SelectedState:
- case UnselectedSelectedTransition:
- case SelectedUnselectedTransition:
- {
- if( backgroundImage && backgroundImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Background, backgroundImage );
-
- backgroundImage = image;
-
- FadeInImage( backgroundImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- backgroundImage = image;
- Self().Insert( 0, backgroundImage );
- }
- break;
- }
- case UnselectedDisabledTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- float opacity = 1.f;
- if( fadeOutBackgroundImage )
- {
- opacity = fadeOutBackgroundImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
-
- // Replaces the button image.
- backgroundImage = image;
-
- Self().Insert( 0, backgroundImage );
- FadeOutImage( Background, backgroundImage, opacity );
+ backgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- StartFadeOutAnimation();
- break;
- }
- case DisabledUnselectedTransition: // FALLTHROUGH
- case DisabledSelectedTransition:
- {
- StopFadeInAnimation();
- Self().Remove( backgroundImage );
+ backgroundImage.RelayoutRequestTree();
- backgroundImage = image;
+ RelayoutRequest();
+ }
- FadeInImage( backgroundImage, 0.0f, 0 );
- StartFadeInAnimation();
- break;
- }
- default:
- backgroundImage = image;
- break;
- }
+ void PushButton::OnSelectedBackgroundImageSet()
+ {
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
- backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
- backgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH );
- backgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ selectedBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
}
- void PushButton::SetDisabledImage( Actor image )
+ void PushButton::OnDisabledImageSet()
{
Actor& disabledImage = GetDisabledImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
-
- switch( mPaintState )
- {
- case DisabledUnselectedState: // FALLTHROUGH
- case DisabledSelectedState:
- {
- if( disabledImage && disabledImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Foreground, disabledImage );
-
- disabledImage = image;
-
- FadeInImage( disabledImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- disabledImage = image;
- Self().Add( disabledImage );
- }
- break;
- }
- case UnselectedDisabledTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- StopFadeInAnimation();
- Self().Remove( disabledImage );
-
- disabledImage = image;
-
- FadeInImage( disabledImage, 0.0f, 0 );
- StartFadeInAnimation();
- break;
- }
- case DisabledUnselectedTransition: // FALLTHROUGH
- case DisabledSelectedTransition:
- {
- float opacity = 1.f;
- if( fadeOutButtonImage )
- {
- opacity = fadeOutButtonImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
-
- // Replaces the button image.
- disabledImage = image;
- Self().Add( disabledImage );
- FadeOutImage( Foreground, disabledImage, opacity );
+ disabledImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- StartFadeOutAnimation();
- break;
- }
- default:
- disabledImage = image;
- break;
- }
+ disabledImage.RelayoutRequestTree();
- disabledImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- disabledImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
- disabledImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
- disabledImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ RelayoutRequest();
}
- void PushButton::SetDisabledBackgroundImage( Actor image )
+ void PushButton::OnDisabledBackgroundImageSet()
{
Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
- Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage();
-
- switch( mPaintState )
- {
- case DisabledUnselectedState: // FALLTHROUGH
- case DisabledSelectedState:
- {
- if( disabledBackgroundImage && disabledBackgroundImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Background, disabledBackgroundImage );
- disabledBackgroundImage = image;
-
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- disabledBackgroundImage = image;
- Self().Add( disabledBackgroundImage );
- }
- break;
- }
- case UnselectedDisabledTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- StopFadeInAnimation();
- Self().Remove( disabledBackgroundImage );
-
- disabledBackgroundImage = image;
-
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
- StartFadeInAnimation();
- break;
- }
- case DisabledUnselectedTransition: // FALLTHROUGH
- case DisabledSelectedTransition:
- {
- float opacity = 1.f;
- if( fadeOutBackgroundImage )
- {
- opacity = fadeOutBackgroundImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
-
- // Replaces the button image.
- disabledBackgroundImage = image;
-
- Self().Add( disabledBackgroundImage );
- FadeOutImage( Background, disabledBackgroundImage, opacity );
-
- StartFadeOutAnimation();
- break;
- }
- default:
- disabledBackgroundImage = image;
- break;
- }
-
- disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
- disabledBackgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH );
disabledBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- }
-
- void PushButton::OnButtonInitialize()
- {
- // Push button requires the Leave event.
- Actor root = Self();
- root.SetLeaveRequired( true );
-
- // Set resize policy to natural size so that buttons will resize to background images
- root.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
- }
-
- void PushButton::OnLabelSet()
- {
- Actor& label = GetLabel();
- if( label )
- {
- label.SetAnchorPoint( AnchorPoint::CENTER );
- label.SetParentOrigin( ParentOrigin::CENTER );
- label.SetPosition( 0.f, 0.f, LABEL_DEPTH );
- label.SetSize( mSize );
+ disabledBackgroundImage.RelayoutRequestTree();
- Self().Add( label );
- }
+ RelayoutRequest();
}
- void PushButton::OnSelected( bool selected )
+ bool PushButton::OnSelected()
{
- Actor& selectedImage = GetSelectedImage();
Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
- switch( mPaintState )
+ PaintState paintState = GetPaintState();
+
+ switch( paintState )
{
case UnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, buttonImage );
- FadeInImage( selectedImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ FadeOutImage( buttonImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
break;
}
case SelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, selectedImage );
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
case UnselectedSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeInImage( buttonImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( buttonImage, 1.f - opacity );
+ StartTransitionAnimation();
break;
}
case SelectedUnselectedTransition:
{
float opacity = 0.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = 1.f - fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeInImage( selectedImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( buttonImage, 1.f - opacity );
+ FadeInImage( selectedBackgroundImage, opacity );
+ FadeInImage( selectedImage, opacity );
+ StartTransitionAnimation();
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ StopTransitionAnimation();
+ FadeOutImage( buttonImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ StopTransitionAnimation();
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
default:
break;
}
}
+
+ if( mTransitionAnimation )
+ {
+ return true;
+ }
+
+ return false;
}
- void PushButton::OnDisabled( bool disabled )
+ bool PushButton::OnDisabled()
{
Actor& buttonImage = GetButtonImage();
Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
Actor& backgroundImage = GetBackgroundImage();
Actor& disabledImage = GetDisabledImage();
+ Actor& disabledSelectedImage = GetDisabledSelectedImage();
Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
- switch( mPaintState )
- {
- case UnselectedState:
+ PaintState paintState = GetPaintState();
+
+ switch( paintState )
{
- if( disabled )
+ case UnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, backgroundImage );
- FadeOutImage( Foreground, buttonImage );
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
- FadeInImage( disabledImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = UnselectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledUnselectedState;
- }
+ FadeOutImage( backgroundImage );
+ FadeOutImage( buttonImage );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case SelectedState:
- {
- if( disabled )
+ case SelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, backgroundImage );
- FadeOutImage( Foreground, selectedImage );
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
- FadeInImage( disabledImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = SelectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledSelectedState;
- }
+ FadeOutImage( backgroundImage );
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledSelectedImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledUnselectedState:
- {
- if( !disabled )
+ case DisabledUnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, disabledBackgroundImage );
- FadeOutImage( Foreground, disabledImage );
- FadeInImage( backgroundImage, 0.0f, 0 );
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ FadeOutImage( disabledBackgroundImage );
+ FadeOutImage( disabledImage );
+ FadeInImage( backgroundImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledSelectedState:
- {
- if( !disabled )
+ case DisabledSelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, disabledBackgroundImage );
- FadeOutImage( Foreground, disabledImage );
- FadeInImage( backgroundImage, 0.0f, 0 );
- FadeInImage( selectedImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ FadeOutImage( disabledBackgroundImage );
+ FadeOutImage( disabledSelectedImage );
+ FadeInImage( backgroundImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case UnselectedSelectedTransition:
- {
- if( disabled )
+ case UnselectedSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation();
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage );
-
- FadeInImage( disabledImage, 0.0f, 0 );
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = SelectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledSelectedState;
- }
+ StopTransitionAnimation();
+ FadeOutImage( backgroundImage );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledSelectedImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case SelectedUnselectedTransition:
- {
- if( disabled )
+ case SelectedUnselectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( buttonImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = buttonImage.GetCurrentOpacity();
}
- StopFadeOutAnimation();
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage );
-
- FadeInImage( disabledImage, 0.0f, 0);
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = UnselectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledUnselectedState;
- }
+ StopTransitionAnimation();
+ FadeOutImage( backgroundImage );
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case UnselectedDisabledTransition:
- {
- if( !disabled )
+ case UnselectedDisabledTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( disabledImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = disabledImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
- FadeOutImage( Foreground, disabledImage, 1.f - opacity );
- FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity );
- FadeInImage( buttonImage, opacity, 0 );
- FadeInImage( backgroundImage, opacity, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( disabledBackgroundImage, opacity );
+ FadeOutImage( disabledImage, opacity );
+ FadeInImage( backgroundImage, 1.f - opacity );
+ FadeInImage( buttonImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledUnselectedTransition:
- {
- if( disabled )
+ case DisabledUnselectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( buttonImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = buttonImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage, 1.f - opacity );
- FadeInImage( disabledImage, opacity, 0 );
- FadeInImage( disabledBackgroundImage, opacity, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = UnselectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledUnselectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( backgroundImage, opacity );
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( disabledBackgroundImage, 1.f - opacity );
+ FadeInImage( disabledImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case SelectedDisabledTransition:
- {
- if( !disabled )
+ case SelectedDisabledTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( disabledSelectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = disabledSelectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
- FadeOutImage( Foreground, disabledImage, 1.f - opacity );
- FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity );
- FadeInImage( selectedImage, opacity, 0 );
- FadeInImage( backgroundImage, opacity, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( disabledBackgroundImage, opacity );
+ FadeOutImage( disabledSelectedImage, opacity );
+ FadeInImage( backgroundImage, 1.f - opacity );
+ FadeInImage( selectedBackgroundImage, 1.f - opacity );
+ FadeInImage( selectedImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledSelectedTransition:
- {
- if( disabled )
+ case DisabledSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage, 1.f - opacity );
- FadeInImage( disabledImage, opacity, 0 );
- FadeInImage( disabledBackgroundImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = SelectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledSelectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( backgroundImage, opacity );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( disabledBackgroundImage, 1.f - opacity );
+ FadeInImage( disabledSelectedImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
}
- default:
- break;
+
+ if( mTransitionAnimation )
+ {
+ return true;
}
+
+ return false;
}
- void PushButton::OnPressed()
+ bool PushButton::OnPressed()
{
- Actor& selectedImage = GetSelectedImage();
Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
+
+ PaintState paintState = GetPaintState();
- switch( mPaintState )
+ switch( paintState )
{
case UnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, buttonImage );
- FadeInImage( selectedImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ FadeOutImage( buttonImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
break;
}
- case UnselectedSelectedTransition:
+ case SelectedUnselectedTransition:
{
- if( !IsAutoRepeating() )
+ float opacity = 1.f;
+ if( buttonImage )
{
- mPaintState = SelectedUnselectedTransition;
+ opacity = buttonImage.GetCurrentOpacity();
}
+
+ StopTransitionAnimation( false );
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( selectedBackgroundImage, 1.f - opacity );
+ FadeInImage( selectedImage, 1.f - opacity );
+ StartTransitionAnimation();
break;
}
- case SelectedUnselectedTransition:
+ case DisabledUnselectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( buttonImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = buttonImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeInImage( selectedImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ StopTransitionAnimation();
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
break;
}
default:
break;
}
+
+ if( mTransitionAnimation )
+ {
+ return true;
+ }
+
+ return false;
}
- void PushButton::OnReleased()
+ bool PushButton::OnReleased()
{
- Actor& selectedImage = GetSelectedImage();
Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
+
+ PaintState paintState = GetPaintState();
- switch( mPaintState )
+ switch( paintState )
{
case SelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, selectedImage );
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
case UnselectedSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeInImage( buttonImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
+ StopTransitionAnimation( false );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( buttonImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ float opacity = 1.f;
+ if( selectedImage )
{
- mPaintState = UnselectedState;
+ opacity = selectedImage.GetCurrentOpacity();
}
+
+ StopTransitionAnimation();
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
default:
break;
}
}
+
+ if( mTransitionAnimation )
+ {
+ return true;
+ }
+
+ return false;
}
- void PushButton::OnClicked()
+ void PushButton::StopAllAnimations()
{
- OnReleased();
+ StopTransitionAnimation();
}
void PushButton::OnControlSizeSet( const Vector3& targetSize )
Vector3 PushButton::GetNaturalSize()
{
- Vector3 size = Control::GetNaturalSize();
-
- const bool widthIsZero = EqualsZero( size.width );
- const bool heightIsZero = EqualsZero( size.height );
-
- if( widthIsZero || heightIsZero )
- {
- // If background and background not scale9 try get size from that
- ImageActor imageActor = FindImageActor( GetButtonImage() );
- if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
- {
- Vector3 imageSize = imageActor.GetNaturalSize();
-
- if( widthIsZero )
- {
- size.width = imageSize.width;
- }
-
- if( heightIsZero )
- {
- size.height = imageSize.height;
- }
- }
-
- ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() );
- if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
- {
- Vector3 imageSize = backgroundImageActor.GetNaturalSize();
-
- if( widthIsZero )
- {
- size.width = std::max( size.width, imageSize.width );
- }
-
- if( heightIsZero )
- {
- size.height = std::max( size.height, imageSize.height );
- }
- }
-
- // If label, test against it's size
- Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( GetLabel() );
- if( textLabel )
- {
- Vector3 textLabelSize = textLabel.GetNaturalSize();
-
- if( widthIsZero )
- {
- size.width = std::max( size.width, textLabelSize.width + TEXT_PADDING * 2.0f );
- }
-
- if( heightIsZero )
- {
- size.height = std::max( size.height, textLabelSize.height + TEXT_PADDING * 2.0f );
- }
- }
- }
-
- return size;
- }
-
- Actor& PushButton::GetFadeOutButtonImage()
- {
- return mFadeOutButtonContent;
- }
+ Vector3 size;
- Actor& PushButton::GetFadeOutBackgroundImage()
- {
- return mFadeOutBackgroundContent;
- }
-
- void PushButton::AddToFadeInAnimation( const Actor& actor )
- {
- if( !mFadeInAnimation )
+ // If background and background not scale9 try get size from that
+ ImageActor imageActor = FindImageActor( GetButtonImage() );
+ if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
{
- mFadeInAnimation = Dali::Animation::New( GetAnimationTime() );
+ size.width = imageActor.GetRelayoutSize( WIDTH );
+ size.height = imageActor.GetRelayoutSize( HEIGHT );
}
- mFadeInAnimation.OpacityTo( actor, 1.f );
- }
-
- void PushButton::StartFadeInAnimation()
- {
- if( mFadeInAnimation )
+ ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() );
+ if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
{
- mFadeInAnimation.FinishedSignal().Connect( this, &PushButton::FadeInAnimationFinished );
- mFadeInAnimation.Play();
+ size.width = std::max( size.width, backgroundImageActor.GetRelayoutSize( WIDTH ) );
+ size.height = std::max( size.height, backgroundImageActor.GetRelayoutSize( HEIGHT ) );
}
- }
- void PushButton::StopFadeInAnimation()
- {
- if( mFadeInAnimation )
+ // If label, test against it's size
- Toolkit::TextView textView = Toolkit::TextView::DownCast( GetLabel() );
- if( textView )
++ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
++ if( label )
{
- mFadeInAnimation.Clear();
- mFadeInAnimation.Reset();
- }
- }
- Vector3 textViewSize = textView.GetNaturalSize();
++ Vector3 labelSize = label.GetNaturalSize();
- void PushButton::AddToFadeOutAnimation( const Actor& actor )
- {
- if( !mFadeOutAnimation )
- {
- mFadeOutAnimation = Dali::Animation::New( GetAnimationTime() );
- size.width = std::max( size.width, textViewSize.width + TEXT_PADDING * 2.0f );
- size.height = std::max( size.height, textViewSize.height + TEXT_PADDING * 2.0f );
++ size.width = std::max( size.width, labelSize.width + TEXT_PADDING * 2.0f );
++ size.height = std::max( size.height, labelSize.height + TEXT_PADDING * 2.0f );
}
- mFadeOutAnimation.OpacityTo( actor, 0.f );
+ return size;
}
- void PushButton::StartFadeOutAnimation()
+ void PushButton::StartTransitionAnimation()
{
- if( mFadeOutAnimation )
+ if( mTransitionAnimation )
{
- mFadeOutAnimation.FinishedSignal().Connect( this, &PushButton::FadeOutAnimationFinished );
- mFadeOutAnimation.Play();
+ mTransitionAnimation.FinishedSignal().Connect( this, &PushButton::TransitionAnimationFinished );
+ mTransitionAnimation.Play();
}
}
- void PushButton::StopFadeOutAnimation( bool remove )
+ void PushButton::StopTransitionAnimation( bool remove )
{
- if( mFadeOutAnimation )
+ if( mTransitionAnimation )
{
- mFadeOutAnimation.Clear();
- mFadeOutAnimation.Reset();
+ mTransitionAnimation.Clear();
+ mTransitionAnimation.Reset();
}
if( remove )
{
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
- Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage();
-
- if( fadeOutButtonImage && fadeOutButtonImage.GetParent() )
- {
- fadeOutButtonImage.GetParent().Remove( fadeOutButtonImage );
- }
-
- if( fadeOutBackgroundImage && fadeOutBackgroundImage.GetParent() )
- {
- fadeOutBackgroundImage.GetParent().Remove( fadeOutBackgroundImage );
- }
-
- fadeOutButtonImage.Reset();
- fadeOutBackgroundImage.Reset();
+ UpdatePaintTransitionState();
}
}
- void PushButton::FadeInImage( Actor& image, float opacity, int priority )
+ void PushButton::FadeInImage( Actor& image, float opacity, Vector3 scale )
{
if( image )
{
image.SetOpacity( opacity );
- if( !image.GetParent() )
+ image.SetScale( scale );
+
+ if( !mTransitionAnimation )
{
- if( priority > -1 )
- {
- Self().Insert( priority, image );
- }
- else
- {
- Self().Add( image );
- }
+ mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
}
- AddToFadeInAnimation( image );
+ mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 1.f );
}
}
- void PushButton::FadeOutImage( ImageLayer layer, Actor& image, float opacity )
+ void PushButton::FadeOutImage( Actor& image, float opacity, Vector3 scale )
{
if( image )
{
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
- Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage();
-
- Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutButtonImage );
-
- actorLayer = image;
- actorLayer.SetOpacity( opacity );
-
- AddToFadeOutAnimation( actorLayer );
- }
- }
+ image.SetOpacity( opacity );
+ image.SetScale( scale );
- void PushButton::FadeOutAnimationFinished( Dali::Animation& source )
- {
- switch( mPaintState )
- {
- case UnselectedSelectedTransition:
- {
- mPaintState = SelectedState;
- break;
- }
- case SelectedUnselectedTransition:
- {
- mPaintState = UnselectedState;
- break;
- }
- case UnselectedDisabledTransition:
- {
- mPaintState = DisabledUnselectedState;
- break;
- }
- case DisabledUnselectedTransition:
- {
- mPaintState = UnselectedState;
- break;
- }
- case SelectedDisabledTransition:
- {
- mPaintState = DisabledSelectedState;
- break;
- }
- case DisabledSelectedTransition:
- {
- mPaintState = SelectedState;
- break;
- }
- default:
+ if( !mTransitionAnimation )
{
- break;
+ mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
}
- }
- StopFadeOutAnimation();
+ mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 0.f );
+ }
}
- void PushButton::FadeInAnimationFinished( Dali::Animation& source )
+ void PushButton::TransitionAnimationFinished( Dali::Animation& source )
{
- switch( mPaintState )
- {
- case UnselectedSelectedTransition:
- {
- mPaintState = SelectedState;
- break;
- }
- case SelectedUnselectedTransition:
- {
- mPaintState = UnselectedState;
- break;
- }
- case UnselectedDisabledTransition:
- {
- mPaintState = DisabledUnselectedState;
- break;
- }
- case DisabledUnselectedTransition:
- {
- mPaintState = UnselectedState;
- break;
- }
- case SelectedDisabledTransition:
- {
- mPaintState = DisabledSelectedState;
- break;
- }
- case DisabledSelectedTransition:
- {
- mPaintState = SelectedState;
- break;
- }
- default:
- {
- break;
- }
- }
-
- StopFadeInAnimation();
+ StopTransitionAnimation();
}
} // namespace Internal
#include <dali/public-api/common/dali-vector.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
#include <dali-toolkit/public-api/controls/buttons/radio-button.h>
#include <dali-toolkit/public-api/controls/table-view/table-view.h>
#include "button-impl.h"
/**
* Create a new RadioButton.
*
- * @return A smart-pointer to the newly allocated PushButton.
+ * @return A smart-pointer to the newly allocated RadioButton.
*/
static Dali::Toolkit::RadioButton New();
- /**
- * Construct a new PushButton.
- */
- RadioButton();
-
- /**
- * Construct a new PushButton with label.
- */
- RadioButton( const std::string& label );
+ private:
/**
- * Construct a new PushButton with label.
+ * Construct a new RadioButton.
*/
- RadioButton( Actor label );
+ RadioButton();
/**
* A reference counted object may only be deleted by calling Unreference()
*/
virtual ~RadioButton();
- public: // From Button
-
- /**
- * @copydoc Toolkit::Internal::Button::SetButtonImage( Actor image )
- */
- virtual void SetButtonImage( Actor image );
-
- /**
- * @copydoc Toolkit::Internal::Button::SetSelectedImage( Actor image )
- */
- virtual void SetSelectedImage( Actor image );
-
private: // From Button
/**
/**
* @copydoc Toolkit::Internal::Button::OnSelected()
*/
- virtual void OnSelected( bool selected );
+ virtual bool OnSelected();
/**
* @copydoc Toolkit::Internal::Button::OnLabelSet()
private:
- /**
- * @brief Set the image to display
- *
- * @param[in] image The image to set
- */
- void SetImage( Actor image );
-
- private:
-
// Undefined
RadioButton( const RadioButton& origin );
// Undefined
RadioButton& operator=( const RadioButton& origin );
-
- private:
-
- Toolkit::TableView mLayoutContainer; ///< Container to position button images and labels
-
};
} // namespace Internal
// OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
- mBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ mBackgroundImage.SetResizePolicy( SIZE_FIXED_OFFSET_FROM_PARENT, ALL_DIMENSIONS );
mBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
mBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
- mBackgroundImage.SetSizeMode( SIZE_FIXED_OFFSET_FROM_PARENT );
Vector3 border( mPopupStyle->backgroundOuterBorder.x, mPopupStyle->backgroundOuterBorder.z, 0.0f );
mBackgroundImage.SetSizeModeFactor( border );
void Popup::SetTitle( const std::string& text )
{
- Toolkit::TextView titleActor = Toolkit::TextView::New();
- titleActor.SetName( "POPUP_TITLE" );
- titleActor.SetText( text );
- titleActor.SetColor( Color::BLACK );
- titleActor.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
- titleActor.SetWidthExceedPolicy( Toolkit::TextView::Split );
- titleActor.SetLineJustification( Toolkit::TextView::Center );
-
- SetTitle( titleActor );
-}
-
-void Popup::SetTitle( Toolkit::TextView titleActor )
-{
// Replaces the current title actor.
if( mPopupLayout )
{
mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) );
}
- mTitle = titleActor;
+ mTitle = Toolkit::TextLabel::New( text );
+ mTitle.SetName( "POPUP_TITLE" );
+ mTitle.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+ mTitle.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
if( mPopupLayout )
{
mTitle.SetPadding( Padding( 0.0f, 0.0f, mPopupStyle->margin, mPopupStyle->margin ) );
mTitle.SetResizePolicy( FILL_TO_PARENT, WIDTH );
- mTitle.SetDimensionDependency( HEIGHT, WIDTH ); // HeightForWidth
+ mTitle.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
}
RelayoutRequest();
}
-Toolkit::TextView Popup::GetTitle() const
+std::string Popup::GetTitle() const
{
- return mTitle;
+ if( mTitle )
+ {
+ return mTitle.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
+ }
+
+ return std::string();
}
void Popup::CreateFooter()
const float titleBuffer = 0.5f;
titleNaturalSize.width += titleBuffer;
- // As TextView GetNaturalSize does not take wrapping into account, limit the width
+ // As TextLabel GetNaturalSize does not take wrapping into account, limit the width
// to that of the stage
if( titleNaturalSize.width >= maxWidth)
{
--- /dev/null
- self.SetDimensionDependency( HEIGHT, WIDTH );
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/scripting/scripting.h>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/text/rendering-backend.h>
+#include <dali-toolkit/internal/text/layouts/layout-engine.h>
+#include <dali-toolkit/internal/text/rendering/text-backend.h>
+#include <dali-toolkit/internal/styling/style-manager-impl.h>
+
+using Dali::Toolkit::Text::LayoutEngine;
+using Dali::Toolkit::Text::Backend;
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+ const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
+}
+
+namespace
+{
+
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
+{
+ { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
+ { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
+ { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
+};
+const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
+
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] =
+{
+ { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
+ { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
+ { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
+};
+const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
+
+// Type registration
+BaseHandle Create()
+{
+ return Toolkit::TextLabel::New();
+}
+
+// Setup properties, signals and actions using the type-registry.
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
+
+DALI_PROPERTY_REGISTRATION( TextLabel, "rendering-backend", INTEGER, RENDERING_BACKEND )
+DALI_PROPERTY_REGISTRATION( TextLabel, "text", STRING, TEXT )
+DALI_PROPERTY_REGISTRATION( TextLabel, "font-family", STRING, FONT_FAMILY )
+DALI_PROPERTY_REGISTRATION( TextLabel, "font-style", STRING, FONT_STYLE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "point-size", FLOAT, POINT_SIZE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "multi-line", BOOLEAN, MULTI_LINE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( TextLabel, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( TextLabel, "text-color", VECTOR4, TEXT_COLOR )
+DALI_PROPERTY_REGISTRATION( TextLabel, "shadow-offset", VECTOR2, SHADOW_OFFSET )
+DALI_PROPERTY_REGISTRATION( TextLabel, "shadow-color", VECTOR4, SHADOW_COLOR )
+DALI_PROPERTY_REGISTRATION( TextLabel, "underline-enabled", BOOLEAN, UNDERLINE_ENABLED )
+DALI_PROPERTY_REGISTRATION( TextLabel, "underline-color", VECTOR4, UNDERLINE_COLOR )
+DALI_TYPE_REGISTRATION_END()
+
+} // namespace
+
+Toolkit::TextLabel TextLabel::New()
+{
+ // Create the implementation, temporarily owned by this handle on stack
+ IntrusivePtr< TextLabel > impl = new TextLabel();
+
+ // Pass ownership to CustomActor handle
+ Toolkit::TextLabel handle( *impl );
+
+ // Second-phase init of the implementation
+ // This can only be done after the CustomActor connection has been made...
+ impl->Initialize();
+
+ return handle;
+}
+
+void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
+
+ if( label )
+ {
+ TextLabel& impl( GetImpl( label ) );
+ switch( index )
+ {
+ case Toolkit::TextLabel::Property::RENDERING_BACKEND:
+ {
+ int backend = value.Get< int >();
+
+ if( impl.mRenderingBackend != backend )
+ {
+ impl.mRenderingBackend = backend;
+ impl.mRenderer.Reset();
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::TEXT:
+ {
+ if( impl.mController )
+ {
+ impl.mController->SetText( value.Get< std::string >() );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::FONT_FAMILY:
+ {
+ if( impl.mController )
+ {
+ std::string fontFamily = value.Get< std::string >();
+
+ if( impl.mController->GetDefaultFontFamily() != fontFamily )
+ {
+ impl.mController->SetDefaultFontFamily( fontFamily );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::FONT_STYLE:
+ {
+ if( impl.mController )
+ {
+ std::string fontStyle = value.Get< std::string >();
+
+ if( impl.mController->GetDefaultFontStyle() != fontStyle )
+ {
+ impl.mController->SetDefaultFontStyle( fontStyle );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::POINT_SIZE:
+ {
+ if( impl.mController )
+ {
+ float pointSize = value.Get< float >();
+
+ if( impl.mController->GetDefaultPointSize() != pointSize /*TODO - epsilon*/ )
+ {
+ impl.mController->SetDefaultPointSize( pointSize );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::MULTI_LINE:
+ {
+ if( impl.mController )
+ {
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
+ LayoutEngine::Layout layout = value.Get< bool >() ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX;
+
+ if( engine.GetLayout() != layout )
+ {
+ engine.SetLayout( layout );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
+ {
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
+ const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::HorizontalAlignment >( value.Get< std::string >().c_str(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
+
+ if( engine.GetHorizontalAlignment() != alignment )
+ {
+ engine.SetHorizontalAlignment( alignment );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
+ {
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
+ const LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::VerticalAlignment >( value.Get< std::string >().c_str(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
+
+ if( engine.GetVerticalAlignment() != alignment )
+ {
+ engine.SetVerticalAlignment( alignment );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+
+ case Toolkit::TextLabel::Property::TEXT_COLOR:
+ {
+ if ( impl.mController )
+ {
+ Vector4 textColor = value.Get< Vector4 >();
+ if ( impl.mController->GetTextColor() != textColor )
+ {
+ impl.mController->SetTextColor( textColor );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+
+ case Toolkit::TextLabel::Property::SHADOW_OFFSET:
+ {
+ if( impl.mController )
+ {
+ Vector2 shadowOffset = value.Get< Vector2 >();
+ if ( impl.mController->GetShadowOffset() != shadowOffset )
+ {
+ impl.mController->SetShadowOffset( shadowOffset );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::SHADOW_COLOR:
+ {
+ if( impl.mController )
+ {
+ Vector4 shadowColor = value.Get< Vector4 >();
+ if ( impl.mController->GetShadowColor() != shadowColor )
+ {
+ impl.mController->SetShadowColor( shadowColor );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
+ {
+ if( impl.mController )
+ {
+ Vector4 color = value.Get< Vector4 >();
+ if ( impl.mController->GetUnderlineColor() != color )
+ {
+ impl.mController->SetUnderlineColor( color );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
+ {
+ if( impl.mController )
+ {
+ bool enabled = value.Get< bool >();
+ if ( impl.mController->IsUnderlineEnabled() != enabled )
+ {
+ impl.mController->SetUnderlineEnabled( enabled );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
+{
+ Property::Value value;
+
+ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
+
+ if( label )
+ {
+ TextLabel& impl( GetImpl( label ) );
+ switch( index )
+ {
+ case Toolkit::TextLabel::Property::RENDERING_BACKEND:
+ {
+ value = impl.mRenderingBackend;
+ break;
+ }
+ case Toolkit::TextLabel::Property::TEXT:
+ {
+ if( impl.mController )
+ {
+ std::string text;
+ impl.mController->GetText( text );
+ value = text;
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::MULTI_LINE:
+ {
+ if( impl.mController )
+ {
+ value = static_cast<bool>( LayoutEngine::MULTI_LINE_BOX == impl.mController->GetLayoutEngine().GetLayout() );
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
+ {
+ if( impl.mController )
+ {
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
+ {
+ if( impl.mController )
+ {
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::TEXT_COLOR:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->GetTextColor();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::SHADOW_OFFSET:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->GetShadowOffset();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::SHADOW_COLOR:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->GetShadowColor();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->GetUnderlineColor();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->IsUnderlineEnabled();
+ }
+ break;
+ }
+ }
+ }
+
+ return value;
+}
+
+void TextLabel::OnInitialize()
+{
+ Actor self = Self();
+
+ mController = Text::Controller::New( *this );
+
+ // Use height-for-width negotiation by default
+ self.SetResizePolicy( FILL_TO_PARENT, WIDTH );
++ self.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
+}
+
+void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
+{
+ GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+}
+
+Vector3 TextLabel::GetNaturalSize()
+{
+ return mController->GetNaturalSize();
+}
+
+float TextLabel::GetHeightForWidth( float width )
+{
+ return mController->GetHeightForWidth( width );
+}
+
+void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
+{
+ if( mController->Relayout( size ) ||
+ !mRenderer )
+ {
+ if( !mRenderer )
+ {
+ mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
+ }
+
+ RenderableActor renderableActor;
+ if( mRenderer )
+ {
+ renderableActor = mRenderer->Render( mController->GetView() );
+ }
+
+ if( renderableActor != mRenderableActor )
+ {
+ UnparentAndReset( mRenderableActor );
+
+ if( renderableActor )
+ {
+ const Vector2& alignmentOffset = mController->GetAlignmentOffset();
+ renderableActor.SetPosition( alignmentOffset.x, alignmentOffset.y );
+
+ Self().Add( renderableActor );
+ }
+
+ mRenderableActor = renderableActor;
+ }
+ }
+}
+
+void TextLabel::RequestTextRelayout()
+{
+ RelayoutRequest();
+}
+
+TextLabel::TextLabel()
+: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+ mRenderingBackend( DEFAULT_RENDERING_BACKEND )
+{
+}
+
+TextLabel::~TextLabel()
+{
+}
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
- captionTextLabel.SetPreferredSize( textSize.GetVectorXY() );
- pressedCaptionTextLabel.SetPreferredSize( textSize.GetVectorXY() );
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/buttons/push-button.h>
+#include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/images/nine-patch-image.h>
+#include <dali/public-api/images/resource-image.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/math/vector4.h>
+#include <libintl.h>
+
+// todo Move this to adaptor??
+#define GET_LOCALE_TEXT(string) dgettext("elementary", string)
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+const Dali::Vector4 DEFAULT_POPUP_BACKGROUND( Dali::Vector4( .20f, 0.29f, 0.44f, 1.0f ) );
+const Dali::Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Dali::Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) );
+const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.36f, 0.45f, 0.59f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_TEXT( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_TEXT_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+
+const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "popup_bubble_bg.#.png" );
+const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
+const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
+const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
+const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
+const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
+const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
+
+const Dali::Vector2 DEFAULT_POPUP_MAX_SIZE( 470.0f, 120.0f ); ///< The maximum size of the popup.
+
+const float OPTION_TEXT_LINE_HEIGHT( 32.0f ); ///< The line height of the text.
+const Dali::Vector2 OPTION_ICON_SIZE( 0.f, 0.f ); ///< The size of the icon.
+const float OPTION_GAP_ICON_TEXT( 6.f ); ///< The gap between the icon and the text
+const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon.
+const float OPTION_MAX_WIDTH( DEFAULT_POPUP_MAX_SIZE.width / 6 ); ///< The maximum width of the option (currently set to the max)
+const float OPTION_MIN_WIDTH( 86.0f ); ///< The minimum width of the option.
+
+const float POPUP_DIVIDER_WIDTH( 1.f ); ///< The size of the divider.
+
+const Dali::Vector2 POPUP_TAIL_SIZE( 20.0f, 16.0f ); ///< The size of the tail.
+const float POPUP_TAIL_Y_OFFSET( 5.f ); ///< The y offset of the tail (when its position is on the bottom).
+const float POPUP_TAIL_TOP_Y_OFFSET( 3.f ); ///< The y offset of the tail (when its position is on the top).
+
+const float HIDE_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup hide animation in seconds.
+const float SHOW_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup show animation in seconds.
+
+const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
+const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
+const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
+const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
+const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
+const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
+
+} // namespace
+
+//// Comparison function for ButtonRequirement Priority
+//bool TextSelectionPopup::PriorityCompare( ButtonRequirement const& a, ButtonRequirement const& b )
+//{
+// return a.priority < b.priority;
+//}
+
+
+Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New()
+{
+ // Create the implementation, temporarily owned by this handle on stack
+ IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup();
+
+ // Pass ownership to CustomActor handle
+ Dali::Toolkit::TextSelectionPopup handle( *impl );
+
+ // Second-phase init of the implementation
+ // This can only be done after the CustomActor connection has been made...
+ impl->Initialize();
+
+ return handle;
+}
+
+void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+ Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
+
+ if( selectionPopup )
+ {
+ TextSelectionPopup& impl( GetImpl( selectionPopup ) );
+
+ switch( index )
+ {
+ case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
+ {
+ impl.SetPopupMaxSize( value.Get< Vector2 >() );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ impl.SetPopupImage( POPUP_BACKGROUND, image );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ impl.SetPopupImage( POPUP_CLIPBOARD_BUTTON, image );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ impl.SetPopupImage( POPUP_CUT_BUTTON_ICON, image );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ impl.SetPopupImage( POPUP_COPY_BUTTON_ICON, image );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ impl.SetPopupImage( POPUP_PASTE_BUTTON_ICON, image );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ impl.SetPopupImage( POPUP_SELECT_BUTTON_ICON, image );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ impl.SetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON, image );
+ break;
+ }
+ } // switch
+ } // TextSelectionPopup
+}
+
+Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
+{
+ Property::Value value;
+
+ Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
+
+ if( selectionPopup )
+ {
+ TextSelectionPopup& impl( GetImpl( selectionPopup ) );
+
+ switch( index )
+ {
+ case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
+ {
+ value = impl.GetPopupMaxSize();
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_BACKGROUND ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CLIPBOARD_BUTTON ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CUT_BUTTON_ICON ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_COPY_BUTTON_ICON ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_PASTE_BUTTON_ICON ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_BUTTON_ICON ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ } // switch
+ }
+ return value;
+}
+
+void TextSelectionPopup::OnInitialize()
+{
+ CreatePopup();
+}
+
+void TextSelectionPopup::OnRelayout( const Vector2& size, RelayoutContainer& container )
+{
+
+}
+
+void TextSelectionPopup::SetPopupMaxSize( const Size& maxSize )
+{
+ mMaxSize = maxSize;
+}
+
+const Dali::Vector2& TextSelectionPopup::GetPopupMaxSize() const
+{
+ return mMaxSize;
+}
+
+void TextSelectionPopup::SetPopupImage( PopupParts part, Dali::Image image )
+{
+ switch ( part )
+ {
+ case POPUP_BACKGROUND :
+ {
+ mBackgroundImage = image;
+ }
+ break;
+ case POPUP_CLIPBOARD_BUTTON :
+ {
+ mClipboardIconImage = image;
+ }
+ break;
+ case POPUP_CUT_BUTTON_ICON :
+ {
+ mCutIconImage = image;
+ }
+ break;
+ case POPUP_COPY_BUTTON_ICON :
+ {
+ mCopyIconImage = image;
+ }
+ break;
+ case POPUP_PASTE_BUTTON_ICON :
+ {
+ mPasteIconImage = image;
+ }
+ break;
+ case POPUP_SELECT_BUTTON_ICON :
+ {
+ mSelectIconImage = image;
+ }
+ break;
+ case POPUP_SELECT_ALL_BUTTON_ICON :
+ {
+ mSelectAllIconImage = image;
+ }
+ break;
+
+ } // switch
+}
+
+Dali::Image TextSelectionPopup::GetPopupImage( PopupParts part )
+{
+ switch ( part )
+ {
+ case POPUP_BACKGROUND :
+ {
+ return mBackgroundImage;
+ }
+ break;
+ case POPUP_CLIPBOARD_BUTTON :
+ {
+ return mClipboardIconImage;
+ }
+ break;
+ case POPUP_CUT_BUTTON_ICON :
+ {
+ return mCutIconImage;
+ }
+ break;
+ case POPUP_COPY_BUTTON_ICON :
+ {
+ return mCopyIconImage;
+ }
+ break;
+ case POPUP_PASTE_BUTTON_ICON :
+ {
+ return mPasteIconImage;
+ }
+ break;
+ case POPUP_SELECT_BUTTON_ICON :
+ {
+ return mSelectIconImage;
+ }
+ break;
+ case POPUP_SELECT_ALL_BUTTON_ICON :
+ {
+ return mSelectAllIconImage;
+ }
+ break;
+ default :
+ {
+ DALI_ASSERT_DEBUG( "Unknown Popup Part" );
+ }
+ } // switch
+
+ return Dali::Image();
+}
+
+ void TextSelectionPopup::CreateOrderedListOfPopupOptions()
+ {
+ mOrderListOfButtons.clear();
+
+ // Create button for each possible option using Option priority
+ if ( !mCutIconImage )
+ {
+ mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
+ }
+ mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), mCutIconImage, true ) );
+
+ if ( !mCopyIconImage )
+ {
+ mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
+ }
+ mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), mCopyIconImage, true ) );
+
+ if ( !mPasteIconImage )
+ {
+ mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
+ }
+ mOrderListOfButtons.push_back( ButtonRequirement( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), mPasteIconImage, true ) );
+
+ if ( !mSelectIconImage )
+ mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
+ mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), mSelectIconImage, true ) );
+
+ if ( !mSelectAllIconImage )
+ {
+ mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
+ }
+ mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), mSelectAllIconImage, true ) );
+
+ if ( !mClipboardIconImage )
+ {
+ mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
+ }
+ mOrderListOfButtons.push_back( ButtonRequirement( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), mClipboardIconImage, true ) );
+
+ // Sort the buttons according their priorities.
+ std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
+ }
+
+ void TextSelectionPopup::CreateBackground()
+ {
+ if ( !mBackgroundImage )
+ {
+ mBackgroundImage = ResourceImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE );
+ }
+
+ NinePatchImage backgroundImageNinePatch = NinePatchImage::DownCast( mBackgroundImage );
+ if( backgroundImageNinePatch )
+ {
+ const Size ninePatchImageSize = Size( static_cast<float>( mBackgroundImage.GetWidth() ), static_cast<float>( mBackgroundImage.GetHeight() ) );
+ Rect<int> childRect = backgroundImageNinePatch.GetChildRectangle();
+
+ // -1u because of the cropping.
+ mNinePatchMargins.x = childRect.x - 1u;
+ mNinePatchMargins.y = ninePatchImageSize.width - ( childRect.x + childRect.width ) - 1u;
+ mNinePatchMargins.z = childRect.y - 1u;
+ mNinePatchMargins.w = ninePatchImageSize.height - ( childRect.y + childRect.height ) - 1u;
+ }
+
+ SetBackgroundImage( mBackgroundImage );
+ SetBackgroundColor( mBackgroundColor );
+ }
+
+ void TextSelectionPopup::AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons )
+ {
+ // 1. Create the backgrounds for the popup option both normal and pressed.
+ // Both containers will be added to a button.
+ Actor optionContainer = Actor::New();
+ optionContainer.SetRelayoutEnabled( true );
+ optionContainer.SetResizePolicy( FIXED, ALL_DIMENSIONS );
+ optionContainer.SetDrawMode( DrawMode::OVERLAY );
+ optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ ImageActor optionPressedContainer = Toolkit::CreateSolidColorActor( mBackgroundPressedColor );
+ optionPressedContainer.SetResizePolicy( FIXED, ALL_DIMENSIONS );
+ optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
+ optionPressedContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ // 2. Add text.
+ Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
+ captionTextLabel.SetResizePolicy( FIXED, ALL_DIMENSIONS );
+ captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
+ // optionContainer.Add( captionTextLabel ); Temporary removed.
+
+ Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
+ pressedCaptionTextLabel.SetResizePolicy( FIXED, ALL_DIMENSIONS );
+ pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
+ // optionPressedContainer.Add( pressedCaptionTextLabel ); Temporary removed.
+
+ // Calculates the icon/text position.
+ float iconTextOffsetY = 0.0f;
+
+ if ( showIcons )
+ {
+ // 3. Create the icons
+ ImageActor pressedIcon = ImageActor::New( iconImage );
+ ImageActor icon = ImageActor::New( iconImage );
+
+ optionContainer.Add( icon );
+ optionPressedContainer.Add( pressedIcon );
+
+ iconTextOffsetY = 0.5f * ( ( DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w ) - ( OPTION_ICON_SIZE.height + OPTION_GAP_ICON_TEXT + OPTION_TEXT_LINE_HEIGHT ) );
+
+ icon.SetParentOrigin( ParentOrigin::TOP_CENTER );
+ icon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+ icon.SetY( iconTextOffsetY );
+
+ pressedIcon.SetParentOrigin( ParentOrigin::TOP_CENTER );
+ pressedIcon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+ pressedIcon.SetY( iconTextOffsetY );
+
+ // Layout icon + gap + text
+ captionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+ pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+ pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+ captionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+ pressedCaptionTextLabel.SetY( -iconTextOffsetY );
+ captionTextLabel.SetY( -iconTextOffsetY );
+ }
+ else
+ {
+ // Centre option text
+ captionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
+ captionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
+ pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
+ pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
+ }
+
+ // Calculate the size of the text.
+ Vector3 textSize = captionTextLabel.GetNaturalSize();
+ textSize.width = std::min( textSize.width, OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH );
+
+ // Set the size to the text. Text will be ellipsized if exceeds the max width.
- optionContainer.SetPreferredSize( optionSize );
- optionPressedContainer.SetPreferredSize( optionSize );
++ captionTextLabel.SetSize( textSize.GetVectorXY() );
++ pressedCaptionTextLabel.SetSize( textSize.GetVectorXY() );
+
+ // 4. Calculate the size of option.
+
+ // The width is the max size of the text or the icon plus the margins clamped between the option min and max size.
+ // The height is the whole popup height minus the ninepatch margins.
+ const Vector2 optionSize( std::min( OPTION_MAX_WIDTH, std::max( OPTION_MIN_WIDTH, std::max( textSize.width, OPTION_ICON_SIZE.width ) + 2.f * OPTION_MARGIN_WIDTH ) ),
+ DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w );
+
- option.SetPreferredSize( optionSize );
++ optionContainer.SetSize( optionSize );
++ optionPressedContainer.SetSize( optionSize );
+
+ // 5. Create a option.
+ Toolkit::PushButton option = Toolkit::PushButton::New();
+ option.SetResizePolicy( FIXED, ALL_DIMENSIONS );
- divider.SetPreferredSize( size );
++ option.SetSize( optionSize );
+ option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ option.SetX( mContentSize.width );
+ option.SetName( name );
+ option.SetAnimationTime( 0.0f );
+ //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
+
+ parent.Add( option );
+
+ // 6. Set the normal option image.
+ option.SetButtonImage( optionContainer );
+
+ // 7. Set the pressed option image
+ option.SetSelectedImage( optionPressedContainer );
+
+ // 8. Update the content size.
+ mContentSize.width += optionSize.width;
+ mContentSize.height = std::max ( optionSize.height, mContentSize.height );
+
+ // 9. Add the divider
+ if( !finalOption )
+ {
+ const Size size( POPUP_DIVIDER_WIDTH, mContentSize.height );
+
+ ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
+ divider.SetResizePolicy( FIXED, ALL_DIMENSIONS );
- self.SetPreferredSize( mRequiredPopUpSize ); // control matches stencil size
++ divider.SetSize( size );
+ divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ divider.SetPosition( mContentSize.width - POPUP_DIVIDER_WIDTH, 0.0f );
+ parent.Add( divider );
+ }
+ }
+
+ void TextSelectionPopup::SetUpPopup( Size& size )
+ {
+ Actor self = Self();
+
+ // Create Layer and Stencil.
+ mStencilLayer = Layer::New();
+ ImageActor stencil = CreateSolidColorActor( Color::RED );
+ stencil.SetDrawMode( DrawMode::STENCIL );
+ stencil.SetVisible( true );
+ Actor scrollview = Actor::New(); //todo make a scrollview
+ stencil.SetRelayoutEnabled( true );
+
+ self.SetResizePolicy( FIXED, ALL_DIMENSIONS );
- mStencilLayer.SetPreferredSize( size ); // matches stencil size
++ self.SetSize( mRequiredPopUpSize ); // control matches stencil size
+
+ mStencilLayer.SetResizePolicy( FIXED, ALL_DIMENSIONS );
++ mStencilLayer.SetSize( size ); // matches stencil size
+
+ stencil.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ scrollview.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ mButtons.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+
+ mStencilLayer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+ scrollview.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+ mButtons.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ mStencilLayer.SetPosition( mNinePatchMargins.x, mNinePatchMargins.y );
+
+ self.Add( mStencilLayer );
+ mStencilLayer.Add( stencil );
+ mStencilLayer.Add( scrollview );
+ scrollview.Add( mButtons );
+ }
+
+ void TextSelectionPopup::AddPopupOptions( bool createTail, bool showIcons )
+ {
+ mShowIcons = showIcons;
+
+ mContentSize = Vector2::ZERO;
+
+ mButtons = Actor::New();
+ mButtons.SetRelayoutEnabled( true );
+
+ // Add the options into the buttons container.
+
+ // 1. Determine how many buttons are active and should be added to container.
+ std::size_t numberOfOptions = 0u;
+ for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
+ {
+ const ButtonRequirement& button( *it );
+ if( button.enabled )
+ {
+ ++numberOfOptions;
+ }
+ }
+
+ // 2. Iterate list of buttons and add active ones.
+ std::size_t optionsAdded = 0u;
+ for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
+ {
+ const ButtonRequirement& button( *it );
+ if ( button.enabled )
+ {
+ ++optionsAdded;
+ AddOption( mButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions, mShowIcons );
+ }
+ }
+
+ // Calculate the size of the whole popup which may not be all visible.
+ mRequiredPopUpSize = Size( std::min( mMaxSize.width, mContentSize.width + mNinePatchMargins.x + mNinePatchMargins.y ), DEFAULT_POPUP_MAX_SIZE.height );
+
+ // Size of the contents within the popup
+ mVisiblePopUpSize = Size( mRequiredPopUpSize.width - mNinePatchMargins.x - mNinePatchMargins.y, mRequiredPopUpSize.height - mNinePatchMargins.z - mNinePatchMargins.w );
+ }
+
+ void TextSelectionPopup::CreatePopup()
+ {
+ if ( !mStencilLayer )
+ {
+ CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
+ CreateBackground();
+ AddPopupOptions( true, true );
+ SetUpPopup( mVisiblePopUpSize );
+ }
+
+ mStencilLayer.RaiseToTop();
+ }
+
+TextSelectionPopup::TextSelectionPopup()
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ),
+ mMaxSize ( DEFAULT_POPUP_MAX_SIZE ),
+ mVisiblePopUpSize( DEFAULT_POPUP_MAX_SIZE ),
+ mRequiredPopUpSize( DEFAULT_POPUP_MAX_SIZE ),
+ mBackgroundColor( DEFAULT_POPUP_BACKGROUND ),
+ mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ),
+ mLineColor( DEFAULT_POPUP_LINE_COLOR ),
+ mIconColor( DEFAULT_OPTION_ICON ),
+ mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
+ mTextColor( DEFAULT_OPTION_TEXT ),
+ mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED ),
+ mSelectOptionPriority( 1 ),
+ mSelectAllOptionPriority ( 2 ),
+ mCutOptionPriority ( 3 ),
+ mCopyOptionPriority ( 4 ),
+ mPasteOptionPriority ( 5 ),
+ mClipboardOptionPriority( 6 ),
+ mShowIcons( true )
+{
+}
+
+TextSelectionPopup::~TextSelectionPopup()
+{
+}
+
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
- mGrabArea.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- mGrabArea.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/text/decorator/text-decorator.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/adaptor-framework/timer.h>
+#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/actors/mesh-actor.h>
+#include <dali/public-api/common/constants.h>
+#include <dali/public-api/events/tap-gesture.h>
+#include <dali/public-api/events/tap-gesture-detector.h>
+#include <dali/public-api/events/pan-gesture.h>
+#include <dali/public-api/events/pan-gesture-detector.h>
+#include <dali/public-api/geometry/mesh.h>
+#include <dali/public-api/geometry/mesh-data.h>
+#include <dali/public-api/images/resource-image.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/math/vector4.h>
+//#include <dali/public-api/images/nine-patch-image.h>
+#include <dali/public-api/signals/connection-tracker.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/control.h>
+#include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/buttons/push-button.h>
+#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/text-controls/text-selection-popup.h>
+
+#ifdef DEBUG_ENABLED
+#define DECORATOR_DEBUG
+#endif
+
+// Local Data
+namespace
+{
+
+const char* DEFAULT_GRAB_HANDLE_IMAGE( DALI_IMAGE_DIR "insertpoint-icon.png" );
+const char* DEFAULT_SELECTION_HANDLE_ONE( DALI_IMAGE_DIR "text-input-selection-handle-left.png" );
+const char* DEFAULT_SELECTION_HANDLE_TWO( DALI_IMAGE_DIR "text-input-selection-handle-right.png" );
+//const char* DEFAULT_SELECTION_HANDLE_ONE_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-left-press.png" );
+//const char* DEFAULT_SELECTION_HANDLE_TWO_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-right-press.png" );
+
+const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.5f, 2.0f, 1.0f );
+const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.5f, 1.5f, 1.0f );
+
+const std::size_t CURSOR_BLINK_INTERVAL = 500; // Cursor blink interval
+const std::size_t MILLISECONDS = 1000;
+
+const float DISPLAYED_HIGHLIGHT_Z_OFFSET( -0.05f );
+
+/**
+ * structure to hold coordinates of each quad, which will make up the mesh.
+ */
+struct QuadCoordinates
+{
+ /**
+ * Default constructor
+ */
+ QuadCoordinates()
+ {
+ }
+
+ /**
+ * Constructor
+ * @param[in] x1 left co-ordinate
+ * @param[in] y1 top co-ordinate
+ * @param[in] x2 right co-ordinate
+ * @param[in] y2 bottom co-ordinate
+ */
+ QuadCoordinates(float x1, float y1, float x2, float y2)
+ : min(x1, y1),
+ max(x2, y2)
+ {
+ }
+
+ Dali::Vector2 min; ///< top-left (minimum) position of quad
+ Dali::Vector2 max; ///< bottom-right (maximum) position of quad
+};
+
+typedef std::vector<QuadCoordinates> QuadContainer;
+
+} // end of namespace
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Text
+{
+
+struct Decorator::Impl : public ConnectionTracker
+{
+ struct CursorImpl
+ {
+ CursorImpl()
+ : x(0.0f),
+ y(0.0f),
+ height(0.0f),
+ color(Dali::Color::WHITE)
+ {
+ }
+
+ float x;
+ float y;
+ float height;
+
+ Vector4 color;
+ };
+
+ struct SelectionHandleImpl
+ {
+ SelectionHandleImpl()
+ : x(0.0f),
+ y(0.0f),
+ cursorHeight(0.0f),
+ flipped(false)
+ {
+ }
+
+ float x;
+ float y;
+ float cursorHeight; ///< Not the handle height
+ bool flipped;
+
+ ImageActor actor;
+ Actor grabArea;
+
+ Image pressedImage;
+ Image releasedImage;
+ };
+
+ Impl( Dali::Toolkit::Internal::Control& parent, Observer& observer )
+ : mTextControlParent(parent),
+ mObserver(observer),
+ mActiveCursor(ACTIVE_CURSOR_NONE),
+ mActiveGrabHandle(false),
+ mActiveSelection( false ),
+ mActiveCopyPastePopup( false ),
+ mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
+ mCursorBlinkDuration( 0.0f ),
+ mCursorBlinkStatus( true ),
+ mGrabDisplacementX( 0.0f ),
+ mGrabDisplacementY( 0.0f ),
+ mHighlightColor( 0.07f, 0.41f, 0.59f, 1.0f ), // light blue
+ mBoundingBox( Rect<int>() )
+ {
+ }
+
+ /**
+ * Relayout of the decorations owned by the decorator.
+ * @param[in] size The Size of the UI control the decorater is adding it's decorations to.
+ */
+ void Relayout( const Vector2& size, const Vector2& scrollPosition )
+ {
+ // TODO - Remove this if nothing is active
+ CreateActiveLayer();
+
+ // Show or hide the cursors
+ CreateCursors();
+ if( mPrimaryCursor )
+ {
+ mPrimaryCursor.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x,
+ mCursor[PRIMARY_CURSOR].y + scrollPosition.y );
+ mPrimaryCursor.SetSize( Vector2( 1.0f, mCursor[PRIMARY_CURSOR].height ) );
+ }
+ if( mSecondaryCursor )
+ {
+ mSecondaryCursor.SetPosition( mCursor[SECONDARY_CURSOR].x + scrollPosition.x,
+ mCursor[SECONDARY_CURSOR].y + scrollPosition.y );
+ mSecondaryCursor.SetSize( Vector2( 1.0f, mCursor[SECONDARY_CURSOR].height ) );
+ }
+
+ // Show or hide the grab handle
+ if( mActiveGrabHandle )
+ {
+ SetupTouchEvents();
+
+ CreateGrabHandle();
+
+ mGrabHandle.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x,
+ mCursor[PRIMARY_CURSOR].y + scrollPosition.y + mCursor[PRIMARY_CURSOR].height );
+ }
+ else if( mGrabHandle )
+ {
+ UnparentAndReset( mGrabHandle );
+ }
+
+ // Show or hide the selection handles/highlight
+ if( mActiveSelection )
+ {
+ SetupTouchEvents();
+
+ CreateSelectionHandles();
+
+ SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
+ primary.actor.SetPosition( primary.x + scrollPosition.x,
+ primary.y + scrollPosition.y + primary.cursorHeight );
+
+ SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
+ secondary.actor.SetPosition( secondary.x + scrollPosition.x,
+ secondary.y + scrollPosition.y + secondary.cursorHeight );
+
+ CreateHighlight();
+ UpdateHighlight();
+ }
+ else
+ {
+ UnparentAndReset( mSelectionHandle[ PRIMARY_SELECTION_HANDLE ].actor );
+ UnparentAndReset( mSelectionHandle[ SECONDARY_SELECTION_HANDLE ].actor );
+ UnparentAndReset( mHighlightMeshActor );
+ }
+
+ if ( mActiveCopyPastePopup )
+ {
+ if ( !mCopyPastePopup )
+ {
+ mCopyPastePopup = TextSelectionPopup::New();
+ mActiveLayer.Add ( mCopyPastePopup );
+ }
+ mCopyPastePopup.SetPosition( Vector3( 200.0f, -100.0f, 0.0f ) ); //todo grabhandle or selection handle positions to be used
+ }
+ else
+ {
+ if ( mCopyPastePopup )
+ {
+ UnparentAndReset( mCopyPastePopup );
+ }
+ }
+ }
+
+ void CreateCursor( ImageActor& cursor )
+ {
+ cursor = CreateSolidColorActor( Color::WHITE );
+ cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
+ cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+ cursor.SetRelayoutEnabled( false );
+ }
+
+ // Add or Remove cursor(s) from parent
+ void CreateCursors()
+ {
+ if( mActiveCursor == ACTIVE_CURSOR_NONE )
+ {
+ UnparentAndReset( mPrimaryCursor );
+ UnparentAndReset( mSecondaryCursor );
+ }
+ else
+ {
+ /* Create Primary and or Secondary Cursor(s) if active and add to parent */
+ if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
+ mActiveCursor == ACTIVE_CURSOR_BOTH )
+ {
+ if ( !mPrimaryCursor )
+ {
+ CreateCursor( mPrimaryCursor );
+#ifdef DECORATOR_DEBUG
+ mPrimaryCursor.SetName( "PrimaryCursorActor" );
+#endif
+ mActiveLayer.Add( mPrimaryCursor);
+ }
+ }
+
+ if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
+ {
+ if ( !mSecondaryCursor )
+ {
+ CreateCursor( mSecondaryCursor );
+#ifdef DECORATOR_DEBUG
+ mSecondaryCursor.SetName( "SecondaryCursorActor" );
+#endif
+ mActiveLayer.Add( mSecondaryCursor);
+ }
+ }
+ }
+ }
+
+ bool OnCursorBlinkTimerTick()
+ {
+ // Cursor blinking
+ if ( mPrimaryCursor )
+ {
+ mPrimaryCursor.SetVisible( mCursorBlinkStatus );
+ }
+ if ( mSecondaryCursor )
+ {
+ mSecondaryCursor.SetVisible( mCursorBlinkStatus );
+ }
+
+ mCursorBlinkStatus = !mCursorBlinkStatus;
+
+ return true;
+ }
+
+ void SetupTouchEvents()
+ {
+ if ( !mTapDetector )
+ {
+ mTapDetector = TapGestureDetector::New();
+ mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
+ }
+
+ if ( !mPanGestureDetector )
+ {
+ mPanGestureDetector = PanGestureDetector::New();
+ mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
+ }
+ }
+
+ void CreateActiveLayer()
+ {
+ if( !mActiveLayer )
+ {
+ Actor parent = mTextControlParent.Self();
+
+ mActiveLayer = Layer::New();
+#ifdef DECORATOR_DEBUG
+ mActiveLayer.SetName ( "ActiveLayerActor" );
+#endif
+
+ mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
+ mActiveLayer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
+
+ parent.Add( mActiveLayer );
+ }
+
+ mActiveLayer.RaiseToTop();
+ }
+
+ void CreateGrabHandle()
+ {
+ if( !mGrabHandle )
+ {
+ if ( !mGrabHandleImage )
+ {
+ mGrabHandleImage = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE );
+ }
+
+ mGrabHandle = ImageActor::New( mGrabHandleImage );
+#ifdef DECORATOR_DEBUG
+ mGrabHandle.SetName( "GrabHandleActor" );
+#endif
+ mGrabHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+ mGrabHandle.SetDrawMode( DrawMode::OVERLAY );
+ // Area that Grab handle responds to, larger than actual handle so easier to move
+#ifdef DECORATOR_DEBUG
+ mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
+ mGrabArea.SetName( "GrabArea" );
+#else
+ mGrabArea = Actor::New();
+ mGrabArea.SetRelayoutEnabled( true );
+#endif
+ mGrabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
+ mGrabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- primary.grabArea.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
++ mGrabArea.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
+ mGrabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
+ mGrabHandle.Add( mGrabArea );
+
+ mTapDetector.Attach( mGrabArea );
+ mPanGestureDetector.Attach( mGrabArea );
+
+ mActiveLayer.Add(mGrabHandle);
+ }
+ }
+
+ void CreateSelectionHandles()
+ {
+ SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
+ if ( !primary.actor )
+ {
+ if ( !primary.releasedImage )
+ {
+ primary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE );
+ }
+
+ primary.actor = ImageActor::New( primary.releasedImage );
+#ifdef DECORATOR_DEBUG
+ primary.actor.SetName("SelectionHandleOne");
+#endif
+ primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
+ primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
+ primary.flipped = false;
+
+ primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
+ primary.grabArea.SetRelayoutEnabled( true );
+#ifdef DECORATOR_DEBUG
+ primary.grabArea.SetName("SelectionHandleOneGrabArea");
+#endif
- secondary.grabArea.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
++ primary.grabArea.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
+ primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
+ primary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
+
+ mTapDetector.Attach( primary.grabArea );
+ mPanGestureDetector.Attach( primary.grabArea );
+ primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
+
+ primary.actor.Add( primary.grabArea );
+ mActiveLayer.Add( primary.actor );
+ }
+
+ SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
+ if ( !secondary.actor )
+ {
+ if ( !secondary.releasedImage )
+ {
+ secondary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO );
+ }
+
+ secondary.actor = ImageActor::New( secondary.releasedImage );
+#ifdef DECORATOR_DEBUG
+ secondary.actor.SetName("SelectionHandleTwo");
+#endif
+ secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
+ secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
+ secondary.flipped = false;
+
+ secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
+ secondary.grabArea.SetRelayoutEnabled( true );
+#ifdef DECORATOR_DEBUG
+ secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
+#endif
++ secondary.grabArea.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
+ secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
+ secondary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
+
+ mTapDetector.Attach( secondary.grabArea );
+ mPanGestureDetector.Attach( secondary.grabArea );
+ secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
+
+ secondary.actor.Add( secondary.grabArea );
+ mActiveLayer.Add( secondary.actor );
+ }
+
+ //SetUpHandlePropertyNotifications(); TODO
+ }
+
+ void CreateHighlight()
+ {
+ if ( !mHighlightMeshActor )
+ {
+ mHighlightMaterial = Material::New( "HighlightMaterial" );
+ mHighlightMaterial.SetDiffuseColor( mHighlightColor );
+
+ mHighlightMeshData.SetMaterial( mHighlightMaterial );
+ mHighlightMeshData.SetHasNormals( true );
+
+ mHighlightMesh = Mesh::New( mHighlightMeshData );
+
+ mHighlightMeshActor = MeshActor::New( mHighlightMesh );
+#ifdef DECORATOR_DEBUG
+ mHighlightMeshActor.SetName( "HighlightMeshActor" );
+#endif
+ mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mHighlightMeshActor.SetPosition( 0.0f, 0.0f, DISPLAYED_HIGHLIGHT_Z_OFFSET );
+
+ Actor parent = mTextControlParent.Self();
+ parent.Add( mHighlightMeshActor );
+ }
+ }
+
+ void UpdateHighlight()
+ {
+ // Construct a Mesh with a texture to be used as the highlight 'box' for selected text
+ //
+ // Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
+ //
+ // [ TOP ] [ TOP ] [TOP ] [ TOP ] [ TOP ] [ TOP ]
+ // [ MIDDLE ] [BOTTOM] [BOTTOM] [ MIDDLE ] [ MIDDLE ]
+ // [ BOTTOM] [ MIDDLE ] [ MIDDLE ]
+ // [BOTTOM] [ MIDDLE ]
+ // [BOTTOM]
+ //
+ // Each quad is created as 2 triangles.
+ // Middle is just 1 quad regardless of its size.
+ //
+ // (0,0) (0,0)
+ // 0* *2 0* *2
+ // TOP TOP
+ // 3* *1 3* *1
+ // 4* *1 4* *6
+ // MIDDLE BOTTOM
+ // 6* *5 7* *5
+ // 6* *8
+ // BOTTOM
+ // 9* *7
+ //
+
+ if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
+ {
+ MeshData::VertexContainer vertices;
+ Dali::MeshData::FaceIndices faceIndices;
+
+ std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
+ std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
+
+ // vertex position defaults to (0 0 0)
+ MeshData::Vertex vertex;
+ // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
+ vertex.nZ = 1.0f;
+
+ for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
+ {
+ // Add each quad geometry (a sub-selection) to the mesh data.
+
+ // 0-----1
+ // |\ |
+ // | \ A |
+ // | \ |
+ // | B \ |
+ // | \|
+ // 2-----3
+
+ QuadCoordinates& quad = *iter;
+ // top-left (v+0)
+ vertex.x = quad.min.x;
+ vertex.y = quad.min.y;
+ vertices.push_back( vertex );
+
+ // top-right (v+1)
+ vertex.x = quad.max.x;
+ vertex.y = quad.min.y;
+ vertices.push_back( vertex );
+
+ // bottom-left (v+2)
+ vertex.x = quad.min.x;
+ vertex.y = quad.max.y;
+ vertices.push_back( vertex );
+
+ // bottom-right (v+3)
+ vertex.x = quad.max.x;
+ vertex.y = quad.max.y;
+ vertices.push_back( vertex );
+
+ // triangle A (3, 1, 0)
+ faceIndices.push_back( v + 3 );
+ faceIndices.push_back( v + 1 );
+ faceIndices.push_back( v );
+
+ // triangle B (0, 2, 3)
+ faceIndices.push_back( v );
+ faceIndices.push_back( v + 2 );
+ faceIndices.push_back( v + 3 );
+
+ mHighlightMeshData.SetFaceIndices( faceIndices );
+ }
+
+ BoneContainer bones(0); // passed empty as bones not required
+ mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
+ mHighlightMesh.UpdateMeshData( mHighlightMeshData );
+ }
+ }
+
+ void OnTap( Actor actor, const TapGesture& tap )
+ {
+ if( actor == mGrabHandle )
+ {
+ // TODO
+ }
+ }
+
+ void OnPan( Actor actor, const PanGesture& gesture )
+ {
+ if( actor == mGrabArea )
+ {
+ if( Gesture::Started == gesture.state )
+ {
+ mGrabDisplacementX = mGrabDisplacementY = 0;
+ }
+
+ mGrabDisplacementX += gesture.displacement.x;
+ mGrabDisplacementY += gesture.displacement.y;
+
+ float x = mCursor[PRIMARY_CURSOR].x + mGrabDisplacementX;
+ float y = mCursor[PRIMARY_CURSOR].y + mCursor[PRIMARY_CURSOR].height*0.5f + mGrabDisplacementY;
+
+ if( Gesture::Started == gesture.state ||
+ Gesture::Continuing == gesture.state )
+ {
+ mObserver.GrabHandleEvent( GRAB_HANDLE_PRESSED, x, y );
+ }
+ else if( Gesture::Finished == gesture.state ||
+ Gesture::Cancelled == gesture.state )
+ {
+ mObserver.GrabHandleEvent( GRAB_HANDLE_RELEASED, x, y );
+ }
+ }
+ }
+
+ bool OnHandleOneTouched( Actor actor, const TouchEvent& touch )
+ {
+ // TODO
+ return false;
+ }
+
+ bool OnHandleTwoTouched( Actor actor, const TouchEvent& touch )
+ {
+ // TODO
+ return false;
+ }
+
+
+ Internal::Control& mTextControlParent;
+ Observer& mObserver;
+
+ Layer mActiveLayer; // Layer for active handles and alike that ensures they are above all else.
+
+ unsigned int mActiveCursor;
+ bool mActiveGrabHandle;
+ bool mActiveSelection;
+ bool mActiveCopyPastePopup;
+
+ CursorImpl mCursor[CURSOR_COUNT];
+
+ Timer mCursorBlinkTimer; // Timer to signal cursor to blink
+ unsigned int mCursorBlinkInterval;
+ float mCursorBlinkDuration;
+ bool mCursorBlinkStatus; // Flag to switch between blink on and blink off
+
+ ImageActor mPrimaryCursor;
+ ImageActor mSecondaryCursor;
+
+ ImageActor mGrabHandle;
+ Actor mGrabArea;
+ float mGrabDisplacementX;
+ float mGrabDisplacementY;
+
+ SelectionHandleImpl mSelectionHandle[SELECTION_HANDLE_COUNT];
+
+ MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
+ Mesh mHighlightMesh; ///< Mesh for highlight
+ MeshData mHighlightMeshData; ///< Mesh Data for highlight
+ Material mHighlightMaterial; ///< Material used for highlight
+ Vector4 mHighlightColor; ///< Color of the highlight
+ QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight
+
+ TextSelectionPopup mCopyPastePopup;
+
+ Image mCursorImage;
+ Image mGrabHandleImage;
+
+ TapGestureDetector mTapDetector;
+ PanGestureDetector mPanGestureDetector;
+
+ Rect<int> mBoundingBox;
+};
+
+DecoratorPtr Decorator::New( Internal::Control& parent, Observer& observer )
+{
+ return DecoratorPtr( new Decorator(parent, observer) );
+}
+
+void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
+{
+ mImpl->mBoundingBox = boundingBox;
+}
+
+const Rect<int>& Decorator::GetBoundingBox() const
+{
+ return mImpl->mBoundingBox;
+}
+
+void Decorator::Relayout( const Vector2& size, const Vector2& scrollPosition )
+{
+ mImpl->Relayout( size, scrollPosition );
+}
+
+/** Cursor **/
+
+void Decorator::SetActiveCursor( ActiveCursor activeCursor )
+{
+ mImpl->mActiveCursor = activeCursor;
+}
+
+unsigned int Decorator::GetActiveCursor() const
+{
+ return mImpl->mActiveCursor;
+}
+
+void Decorator::SetPosition( Cursor cursor, float x, float y, float height )
+{
+ // Adjust grab handle displacement
+ mImpl->mGrabDisplacementX -= x - mImpl->mCursor[cursor].x;
+ mImpl->mGrabDisplacementY -= y - mImpl->mCursor[cursor].y;
+
+ mImpl->mCursor[cursor].x = x;
+ mImpl->mCursor[cursor].y = y;
+ mImpl->mCursor[cursor].height = height;
+}
+
+void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& height ) const
+{
+ x = mImpl->mCursor[cursor].x;
+ y = mImpl->mCursor[cursor].y;
+ height = mImpl->mCursor[cursor].height;
+}
+
+void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
+{
+ mImpl->mCursor[cursor].color = color;
+}
+
+const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
+{
+ return mImpl->mCursor[cursor].color;
+}
+
+void Decorator::StartCursorBlink()
+{
+ if ( !mImpl->mCursorBlinkTimer )
+ {
+ mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
+ mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
+ }
+
+ if ( !mImpl->mCursorBlinkTimer.IsRunning() )
+ {
+ mImpl->mCursorBlinkTimer.Start();
+ }
+}
+
+void Decorator::StopCursorBlink()
+{
+ if ( mImpl->mCursorBlinkTimer )
+ {
+ mImpl->mCursorBlinkTimer.Stop();
+ }
+}
+
+void Decorator::SetCursorBlinkInterval( float seconds )
+{
+ mImpl->mCursorBlinkInterval = seconds*MILLISECONDS; // Convert to milliseconds
+}
+
+float Decorator::GetCursorBlinkInterval() const
+{
+ return mImpl->mCursorBlinkInterval;
+}
+
+void Decorator::SetCursorBlinkDuration( float seconds )
+{
+ mImpl->mCursorBlinkDuration = seconds;
+}
+
+float Decorator::GetCursorBlinkDuration() const
+{
+ return mImpl->mCursorBlinkDuration;
+}
+
+/** GrabHandle **/
+
+void Decorator::SetGrabHandleActive( bool active )
+{
+ mImpl->mActiveGrabHandle = active;
+}
+
+bool Decorator::IsGrabHandleActive() const
+{
+ return mImpl->mActiveGrabHandle;
+}
+
+void Decorator::SetGrabHandleImage( Dali::Image image )
+{
+ mImpl->mGrabHandleImage = image;
+}
+
+Dali::Image Decorator::GetGrabHandleImage() const
+{
+ return mImpl->mGrabHandleImage;
+}
+
+/** Selection **/
+
+void Decorator::SetSelectionActive( bool active )
+{
+ mImpl->mActiveSelection = active;
+}
+
+bool Decorator::IsSelectionActive() const
+{
+ return mImpl->mActiveSelection;
+}
+
+void Decorator::SetPosition( SelectionHandle handle, float x, float y, float height )
+{
+ mImpl->mSelectionHandle[handle].x = x;
+ mImpl->mSelectionHandle[handle].y = y;
+ mImpl->mSelectionHandle[handle].cursorHeight = height;
+}
+
+void Decorator::GetPosition( SelectionHandle handle, float& x, float& y, float& height ) const
+{
+ x = mImpl->mSelectionHandle[handle].x;
+ y = mImpl->mSelectionHandle[handle].y;
+ height = mImpl->mSelectionHandle[handle].cursorHeight;
+}
+
+void Decorator::SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image )
+{
+ if( SELECTION_HANDLE_PRESSED == state )
+ {
+ mImpl->mSelectionHandle[handle].pressedImage = image;
+ }
+ else
+ {
+ mImpl->mSelectionHandle[handle].releasedImage = image;
+ }
+}
+
+Dali::Image Decorator::GetImage( SelectionHandle handle, SelectionHandleState state ) const
+{
+ if( SELECTION_HANDLE_PRESSED == state )
+ {
+ return mImpl->mSelectionHandle[handle].pressedImage;
+ }
+
+ return mImpl->mSelectionHandle[handle].releasedImage;
+}
+
+void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
+{
+ mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
+}
+
+void Decorator::ClearHighlights()
+{
+ mImpl->mHighlightQuadList.clear();
+}
+
+void Decorator::SetPopupActive( bool active )
+{
+ mImpl->mActiveCopyPastePopup = active;
+}
+
+bool Decorator::IsPopupActive() const
+{
+ return mImpl->mActiveCopyPastePopup ;
+}
+
+Decorator::~Decorator()
+{
+ delete mImpl;
+}
+
+Decorator::Decorator( Dali::Toolkit::Internal::Control& parent, Observer& observer )
+: mImpl( NULL )
+{
+ mImpl = new Decorator::Impl( parent, observer );
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
- actor.SetRelayoutEnabled( true );
- actor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+ actor.SetRelayoutEnabled( false );
+
+ Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
+ ParentSource( Actor::Property::SIZE ),
+ EqualToConstraint() );
+ actor.ApplyConstraint( constraint );
}
} // unnamed namespace
// Construction & Destruction
Impl(Control& controlImpl)
: mControlImpl( controlImpl ),
+ mStyleName(""),
mBackground( NULL ),
mStartingPinchScale( NULL ),
mKeyEventSignal(),
switch ( index )
{
+ case Toolkit::Control::Property::STYLE_NAME:
+ {
+ controlImpl.SetStyleName( value.Get< std::string >() );
+ break;
+ }
+
case Toolkit::Control::Property::BACKGROUND_COLOR:
{
controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
switch ( index )
{
+ case Toolkit::Control::Property::STYLE_NAME:
+ {
+ value = controlImpl.GetStyleName();
+ break;
+ }
+
case Toolkit::Control::Property::BACKGROUND_COLOR:
{
value = controlImpl.GetBackgroundColor();
// Data
Control& mControlImpl;
+ std::string mStyleName;
Background* mBackground; ///< Only create the background if we use it
Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
Toolkit::Control::KeyEventSignalType mKeyEventSignal;
static PropertyRegistration PROPERTY_1;
static PropertyRegistration PROPERTY_2;
static PropertyRegistration PROPERTY_3;
+ static PropertyRegistration PROPERTY_4;
};
// Properties registered without macro to use specific member variables.
-PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
Toolkit::Control Control::New()
{
return mImpl->mLongPressGestureDetector;
}
+void Control::SetStyleName( const std::string& styleName )
+{
+ if( styleName != mImpl->mStyleName )
+ {
+ mImpl->mStyleName = styleName;
+
+ // Apply new style
+ Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
+ GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+ }
+}
+
+const std::string& Control::GetStyleName() const
+{
+ return mImpl->mStyleName;
+}
+
void Control::SetBackgroundColor( const Vector4& color )
{
Background& background( mImpl->GetBackground() );
Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
// Register for style changes
- styleManager.StyleChangeSignal().Connect( this, &Control::DoStyleChange );
+ styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
// SetTheme
GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
{
}
-void Control::OnThemeChange( Toolkit::StyleManager styleManager )
-{
- GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
-}
-
-void Control::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange )
+void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
{
+ // By default the control is only interested in theme (not font) changes
+ if( change.themeChange )
+ {
+ GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+ }
}
void Control::OnPinch(const PinchGesture& pinch)
mImpl->SignalDisconnected( slotObserver, callback );
}
-void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
-{
- if( change.themeChange )
- {
- OnThemeChange( styleManager );
- }
- else if( change.defaultFontChange || change.defaultFontSizeChange )
- {
- OnFontChange( change.defaultFontChange, change.defaultFontSizeChange );
- }
-}
-
} // namespace Internal
} // namespace Toolkit
Name: dali-toolkit
Summary: The OpenGLES Canvas Core Library Toolkit
- Version: 1.0.35
+ Version: 1.0.36
Release: 1
Group: System/Libraries
License: Apache-2.0
URL: https://review.tizen.org/git/?p=platform/core/uifw/dali-toolkit.git;a=summary
Source0: %{name}-%{version}.tar.gz
+%define dali_profile MOBILE
+
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
Requires: dali
BuildRequires: boost-devel
BuildRequires: pkgconfig(dali)
BuildRequires: pkgconfig(dali-core)
-BuildRequires: fribidi-devel
%description
The OpenGLES Canvas Core Library Toolkit - a set of controls that provide
autoreconf --install
DALI_DATA_RW_DIR="%{dali_data_rw_dir}" ; export DALI_DATA_RW_DIR
DALI_DATA_RO_DIR="%{dali_data_ro_dir}" ; export DALI_DATA_RO_DIR
-%configure
+%configure --enable-profile=%{dali_profile}
make %{?jobs:-j%jobs}
##############################