X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fpopup%2Fpopup-impl.cpp;h=42b10832e1a5b356c5a3508bda84d83d2a515c3a;hp=74d5ee8f483cde888676d8a2b66ce1359e3fdf1a;hb=b1e8521ad77e7b4e62b59613b2edef64429130e9;hpb=84e05cec3039abe8ecaaa950d4f93dd4f94282fe diff --git a/dali-toolkit/internal/controls/popup/popup-impl.cpp b/dali-toolkit/internal/controls/popup/popup-impl.cpp old mode 100755 new mode 100644 index 74d5ee8..42b1083 --- a/dali-toolkit/internal/controls/popup/popup-impl.cpp +++ b/dali-toolkit/internal/controls/popup/popup-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -21,23 +21,27 @@ // EXTERNAL INCLUDES #include // for strcmp #include +#include #include #include #include #include -#include +#include #include -#include -#include +#include #include #include +#include #include // INTERNAL INCLUDES +#include #include #include #include -#include +#include +#include +#include #include using namespace Dali; @@ -78,7 +82,7 @@ BaseHandle CreateToast() Toolkit::Popup popup = Toolkit::Popup::New(); // Setup for Toast Popup type. - popup.SetSizeModeFactor( DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO ); + popup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO ); popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); popup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, Toolkit::Popup::NON_CONTEXTUAL ); @@ -95,8 +99,8 @@ BaseHandle CreateToast() popup.SetProperty( Toolkit::Popup::Property::AUTO_HIDE_DELAY, DEFAULT_TOAST_AUTO_HIDE_DELAY ); // Align to the bottom of the screen. - popup.SetParentOrigin( DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN ); - popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + popup.SetProperty( Actor::Property::PARENT_ORIGIN, DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN ); + popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); // Let events pass through the toast popup. popup.SetProperty( Toolkit::Popup::Property::TOUCH_TRANSPARENT, true ); @@ -108,39 +112,40 @@ BaseHandle CreateToast() DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create ) // Main content related properties. -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "title", MAP, TITLE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "content", MAP, CONTENT ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "footer", MAP, FOOTER ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "displayState", STRING, DISPLAY_STATE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "touchTransparent", BOOLEAN, TOUCH_TRANSPARENT ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "title", MAP, TITLE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "content", MAP, CONTENT ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "footer", MAP, FOOTER ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "displayState", STRING, DISPLAY_STATE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "touchTransparent", BOOLEAN, TOUCH_TRANSPARENT ) // Contextual related properties. -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailVisibility", BOOLEAN, TAIL_VISIBILITY ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailPosition", VECTOR3, TAIL_POSITION ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "contextualMode", STRING, CONTEXTUAL_MODE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailVisibility", BOOLEAN, TAIL_VISIBILITY ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailPosition", VECTOR3, TAIL_POSITION ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "contextualMode", STRING, CONTEXTUAL_MODE ) // Animation related properties. -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationDuration", FLOAT, ANIMATION_DURATION ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationMode", STRING, ANIMATION_MODE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "entryAnimation", MAP, ENTRY_ANIMATION ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "exitAnimation", MAP, EXIT_ANIMATION ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "autoHideDelay", INTEGER, AUTO_HIDE_DELAY ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationDuration", FLOAT, ANIMATION_DURATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationMode", STRING, ANIMATION_MODE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "entryAnimation", MAP, ENTRY_ANIMATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "exitAnimation", MAP, EXIT_ANIMATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "autoHideDelay", INTEGER, AUTO_HIDE_DELAY ) // Style related properties. -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingEnabled", BOOLEAN, BACKING_ENABLED ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingColor", VECTOR4, BACKING_COLOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundImage", STRING, POPUP_BACKGROUND_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailUpImage", STRING, TAIL_UP_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailDownImage", STRING, TAIL_DOWN_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailLeftImage", STRING, TAIL_LEFT_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailRightImage", STRING, TAIL_RIGHT_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingEnabled", BOOLEAN, BACKING_ENABLED ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingColor", VECTOR4, BACKING_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundImage", STRING, POPUP_BACKGROUND_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundBorder", RECTANGLE, POPUP_BACKGROUND_BORDER ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailUpImage", STRING, TAIL_UP_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailDownImage", STRING, TAIL_DOWN_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailLeftImage", STRING, TAIL_LEFT_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailRightImage", STRING, TAIL_RIGHT_IMAGE ) // Signals. -DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touchedOutside", SIGNAL_TOUCHED_OUTSIDE ) -DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "showing", SIGNAL_SHOWING ) -DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "shown", SIGNAL_SHOWN ) -DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hiding", SIGNAL_HIDING ) -DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN ) +DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touchedOutside", SIGNAL_TOUCHED_OUTSIDE ) +DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "showing", SIGNAL_SHOWING ) +DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "shown", SIGNAL_SHOWN ) +DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hiding", SIGNAL_HIDING ) +DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN ) DALI_TYPE_REGISTRATION_END() @@ -174,29 +179,29 @@ const Scripting::StringEnum ContextualModeTable[] = { }; const unsigned int ContextualModeTableCount = sizeof( ContextualModeTable ) / sizeof( ContextualModeTable[0] ); // Popup defaults. -const Vector3 DEFAULT_POPUP_PARENT_RELATIVE_SIZE( 0.75f, 1.0f, 1.0f ); ///< Default size percentage of parent. -const float DEFAULT_POPUP_ANIMATION_DURATION = 0.6f; ///< Duration of hide/show animations. -const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension. -const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension. -const Vector3 DEFAULT_TAIL_POSITION( 0.5f, 1.0f, 0.0f ); ///< Position the tail will be displayed when enabled without setting the position. +const Vector3 DEFAULT_POPUP_PARENT_RELATIVE_SIZE( 0.75f, 1.0f, 1.0f ); ///< Default size percentage of parent. +const float DEFAULT_POPUP_ANIMATION_DURATION = 0.6f; ///< Duration of hide/show animations. +const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension. +const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension. +const Vector3 DEFAULT_TAIL_POSITION( 0.5f, 1.0f, 0.0f ); ///< Position the tail will be displayed when enabled without setting the position. // Contextual defaults. -const Vector2 DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN( 10.0f, 10.0f ); ///< How close the Popup will be to it's contextual parent. -const Vector2 DEFAULT_CONTEXTUAL_STAGE_BORDER( 15.0f, 15.0f ); ///< How close the Popup can be to the stage edges. +const Vector2 DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN( 10.0f, 10.0f ); ///< How close the Popup will be to it's contextual parent. +const Vector2 DEFAULT_CONTEXTUAL_STAGE_BORDER( 15.0f, 15.0f ); ///< How close the Popup can be to the stage edges. // Popup style defaults. -const char* DEFAULT_BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "00_popup_bg.9.png"; ///< Background image. -const char* DEFAULT_TAIL_UP_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_up.png"; ///< Tail up image. -const char* DEFAULT_TAIL_DOWN_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_down.png"; ///< Tail down image. -const char* DEFAULT_TAIL_LEFT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_left.png"; ///< Tail left image. -const char* DEFAULT_TAIL_RIGHT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_right.png"; ///< Tail right image. - -const Vector4 DEFAULT_BACKING_COLOR( 0.0f, 0.0f, 0.0f, 0.5f ); ///< Color of the dimmed backing. -const Vector3 BACKGROUND_OUTER_BORDER( 40.0f, 30.0f, 0.0f ); ///< External border. -const Rect DEFAULT_TITLE_PADDING( 20.0f, 20.0f, 20.0f, 20.0f ); ///< Title padding used on popups with content and/or controls (from Tizen GUI UX). -const Rect DEFAULT_TITLE_ONLY_PADDING( 8.0f, 8.0f, 8.0f, 8.0f ); ///< Title padding used on popups with a title only (like toast popups). -const Vector3 FOOTER_SIZE( 620.0f, 96.0f,0.0f ); ///< Default size of the bottom control area. -const float DEFAULT_RELATIVE_PARENT_WIDTH = 0.75f; ///< If width is not fixed, relative size to parent is used by default. +const char* DEFAULT_BACKGROUND_IMAGE_FILE_NAME = "00_popup_bg.9.png"; ///< Background image. +const char* DEFAULT_TAIL_UP_IMAGE_FILE_NAME = "popup_tail_up.png"; ///< Tail up image. +const char* DEFAULT_TAIL_DOWN_IMAGE_FILE_NAME = "popup_tail_down.png"; ///< Tail down image. +const char* DEFAULT_TAIL_LEFT_IMAGE_FILE_NAME = "popup_tail_left.png"; ///< Tail left image. +const char* DEFAULT_TAIL_RIGHT_IMAGE_FILE_NAME = "popup_tail_right.png"; ///< Tail right image. + +const Vector4 DEFAULT_BACKING_COLOR( 0.0f, 0.0f, 0.0f, 0.5f ); ///< Color of the dimmed backing. +const Rect DEFAULT_BACKGROUND_BORDER( 17, 17, 13, 13 ); ///< Default border of the background. +const Rect DEFAULT_TITLE_PADDING( 20.0f, 20.0f, 20.0f, 20.0f ); ///< Title padding used on popups with content and/or controls (from Tizen GUI UX). +const Rect DEFAULT_TITLE_ONLY_PADDING( 8.0f, 8.0f, 8.0f, 8.0f ); ///< Title padding used on popups with a title only (like toast popups). +const Vector3 FOOTER_SIZE( 620.0f, 96.0f,0.0f ); ///< Default size of the bottom control area. +const float DEFAULT_RELATIVE_PARENT_WIDTH = 0.75f; ///< If width is not fixed, relative size to parent is used by default. } // Unnamed namespace @@ -252,40 +257,46 @@ Popup::Popup() mBackingEnabled( true ), mBackingColor( DEFAULT_BACKING_COLOR ), mPopupBackgroundImage(), - mBackgroundOuterBorder(), + mBackgroundBorder( DEFAULT_BACKGROUND_BORDER ), mMargin(), - mTailUpImage( DEFAULT_TAIL_UP_IMAGE_PATH ), - mTailDownImage( DEFAULT_TAIL_DOWN_IMAGE_PATH ), - mTailLeftImage( DEFAULT_TAIL_LEFT_IMAGE_PATH ), - mTailRightImage( DEFAULT_TAIL_RIGHT_IMAGE_PATH ) + mTailUpImage(), + mTailDownImage(), + mTailLeftImage(), + mTailRightImage() { SetKeyboardNavigationSupport( true ); + + const std::string imageDirPath = AssetManager::GetDaliImagePath(); + mTailUpImage = imageDirPath + DEFAULT_TAIL_UP_IMAGE_FILE_NAME; + mTailDownImage = imageDirPath + DEFAULT_TAIL_DOWN_IMAGE_FILE_NAME; + mTailLeftImage = imageDirPath + DEFAULT_TAIL_LEFT_IMAGE_FILE_NAME; + mTailRightImage = imageDirPath + DEFAULT_TAIL_RIGHT_IMAGE_FILE_NAME; } void Popup::OnInitialize() { Actor self = Self(); - self.SetName( "popup" ); + self.SetProperty( Dali::Actor::Property::NAME, "popup" ); // Apply some default resizing rules. - self.SetParentOrigin( ParentOrigin::CENTER ); - self.SetAnchorPoint( AnchorPoint::CENTER ); + self.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + self.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - self.SetSizeModeFactor( DEFAULT_POPUP_PARENT_RELATIVE_SIZE ); + self.SetProperty( Actor::Property::SIZE_MODE_FACTOR, DEFAULT_POPUP_PARENT_RELATIVE_SIZE ); self.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); // Create a new layer so all Popup components can appear above all other actors. mLayer = Layer::New(); - mLayer.SetName( "popupLayer" ); + mLayer.SetProperty( Dali::Actor::Property::NAME, "popupLayer" ); - mLayer.SetParentOrigin( ParentOrigin::CENTER ); - mLayer.SetAnchorPoint( AnchorPoint::CENTER ); + mLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Important to set as invisible as otherwise, if the popup is parented, // but not shown yet it will appear statically on the screen. - mLayer.SetVisible( false ); + mLayer.SetProperty( Actor::Property::VISIBLE, false ); // Add the layer to the hierarchy. self.Add( mLayer ); @@ -295,9 +306,9 @@ void Popup::OnInitialize() mLayer.Add( mBacking ); mPopupContainer = Actor::New(); - mPopupContainer.SetName( "popupContainer" ); - mPopupContainer.SetParentOrigin( ParentOrigin::CENTER ); - mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER ); + mPopupContainer.SetProperty( Dali::Actor::Property::NAME, "popupContainer" ); + mPopupContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mPopupContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); mPopupContainer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); mLayer.Add( mPopupContainer ); @@ -305,27 +316,28 @@ void Popup::OnInitialize() mPopupLayout = Toolkit::TableView::New( 3, 1 ); // Adds the default background image. - SetPopupBackgroundImage( Toolkit::ImageView::New( ResourceImage::New( DEFAULT_BACKGROUND_IMAGE_PATH ) ) ); + const std::string imageDirPath = AssetManager::GetDaliImagePath(); + SetPopupBackgroundImage( Toolkit::ImageView::New( imageDirPath + DEFAULT_BACKGROUND_IMAGE_FILE_NAME ) ); - mPopupLayout.SetName( "popupLayoutTable" ); - mPopupLayout.SetParentOrigin( ParentOrigin::CENTER ); - mPopupLayout.SetAnchorPoint( AnchorPoint::CENTER ); + mPopupLayout.SetProperty( Dali::Actor::Property::NAME, "popupLayoutTable" ); + mPopupLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mPopupLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH ); mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mPopupLayout.SetSize( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f ); + mPopupLayout.SetProperty( Actor::Property::SIZE, Vector2( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f ) ); mPopupLayout.SetFitHeight( 0 ); // Set row to fit. mPopupLayout.SetFitHeight( 1 ); // Set row to fit. - mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched ); - mPopupContainer.Add( mPopupLayout ); // Any content after this point which is added to Self() will be re-parented to mContent. mAlterAddedChild = true; SetAsKeyboardFocusGroup( true ); + + SetupTouch(); } Popup::~Popup() @@ -342,14 +354,14 @@ void Popup::LayoutAnimation() case Toolkit::Popup::ZOOM: { // Zoom animations start fully zoomed out. - mPopupContainer.SetScale( Vector3::ZERO ); + mPopupContainer.SetProperty( Actor::Property::SCALE, Vector3::ZERO ); break; } case Toolkit::Popup::FADE: { // Fade animations start transparent. - mPopupContainer.SetOpacity( 0.0f ); + mPopupContainer.SetProperty( Actor::Property::OPACITY, 0.0f ); break; } @@ -423,7 +435,7 @@ void Popup::StartTransitionAnimation( bool transitionIn, bool instantaneous /* f } else { - mPopupContainer.SetScale( transitionIn ? Vector3::ONE : Vector3::ZERO ); + mPopupContainer.SetProperty( Actor::Property::SCALE, transitionIn ? Vector3::ONE : Vector3::ZERO ); } break; } @@ -444,7 +456,7 @@ void Popup::StartTransitionAnimation( bool transitionIn, bool instantaneous /* f } else { - mPopupContainer.SetOpacity( transitionIn ? 1.0f : 0.0f ); + mPopupContainer.SetProperty( Actor::Property::OPACITY, transitionIn ? 1.0f : 0.0f ); } break; } @@ -526,8 +538,8 @@ void Popup::DisplayStateChangeComplete() { mDisplayState = Toolkit::Popup::HIDDEN; - mLayer.SetVisible( false ); - mPopupLayout.SetSensitive( false ); + mLayer.SetProperty( Actor::Property::VISIBLE, false ); + mPopupLayout.SetProperty( Actor::Property::SENSITIVE, false ); // Guard against destruction during signal emission. Toolkit::Popup handle( GetOwner() ); @@ -568,27 +580,33 @@ void Popup::SetPopupBackgroundImage( Actor image ) // Removes any previous background. if( mPopupBackgroundImage ) { - mPopupContainer.Remove( mPopupBackgroundImage ); + mPopupBackgroundImage.Unparent(); + if( mTailImage ) + { + mTailImage.Unparent(); + } } // Adds new background to the dialog. mPopupBackgroundImage = image; - mPopupBackgroundImage.SetName( "popupBackgroundImage" ); - mPopupBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER ); - mPopupBackgroundImage.SetParentOrigin( ParentOrigin::CENTER ); - - // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing. - mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched ); + mPopupBackgroundImage.SetProperty( Dali::Actor::Property::NAME, "popupBackgroundImage" ); + mPopupBackgroundImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mPopupBackgroundImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); // Set the popup border to be slightly larger than the layout contents. - mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); - mPopupBackgroundImage.SetSizeModeFactor( BACKGROUND_OUTER_BORDER ); + UpdateBackgroundPositionAndSize(); const bool prevAlter = mAlterAddedChild; mAlterAddedChild = false; mPopupContainer.Add( mPopupBackgroundImage ); + mPopupBackgroundImage.LowerToBottom(); mAlterAddedChild = prevAlter; + if( mTailImage ) + { + mPopupBackgroundImage.Add( mTailImage ); + } + mLayoutDirty = true; } @@ -615,7 +633,7 @@ void Popup::SetTitle( Actor titleActor ) { // Set up padding to give sensible default behaviour // (an application developer can later override this if they wish). - mTitle.SetPadding( DEFAULT_TITLE_PADDING ); + mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_PADDING ); mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) ); } @@ -641,7 +659,7 @@ void Popup::SetContent( Actor content ) if( mContent ) { - mContent.SetName( "popupContent" ); + mContent.SetProperty( Dali::Actor::Property::NAME, "popupContent" ); mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) ); } @@ -708,7 +726,7 @@ void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState ) // We are displaying so bring the popup layer to the front, and set it visible so it is rendered. mLayer.RaiseToTop(); - mLayer.SetVisible( true ); + mLayer.SetProperty( Actor::Property::VISIBLE, true ); // Set up the layout if this is the first display or the layout has become dirty. if( mLayoutDirty ) @@ -718,7 +736,7 @@ void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState ) } // Allow the popup to catch events. - mPopupLayout.SetSensitive( true ); + mPopupLayout.SetProperty( Actor::Property::SENSITIVE, true ); // Handle the keyboard focus when popup is shown. Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get(); @@ -726,16 +744,16 @@ void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState ) { mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor(); - if( Self().IsKeyboardFocusable() ) + if( Self().GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) ) { // Setup the actgor to start focus from. Actor focusActor; - if( mContent && mContent.IsKeyboardFocusable() ) + if( mContent && mContent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) ) { // If the content is focusable, move the focus to the content. focusActor = mContent; } - else if( mFooter && mFooter.IsKeyboardFocusable() ) + else if( mFooter && mFooter.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) ) { // If the footer is focusable, move the focus to the footer. focusActor = mFooter; @@ -758,7 +776,7 @@ void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState ) ClearKeyInputFocus(); // Restore the keyboard focus when popup is hidden. - if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() ) + if( mPreviousFocusedActor && mPreviousFocusedActor.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) ) { Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get(); if( keyboardFocusManager ) @@ -794,19 +812,19 @@ void Popup::LayoutPopup() * | |```` * | | */ - mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() ); - mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() ); + mPopupContainer.SetProperty( Actor::Property::PARENT_ORIGIN, Self().GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ) ); + mPopupContainer.SetProperty( Actor::Property::ANCHOR_POINT, Self().GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) ); // If there is only a title, use less padding. if( mTitle ) { if( !mContent && !mFooter ) { - mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING ); + mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_ONLY_PADDING ); } else { - mTitle.SetPadding( DEFAULT_TITLE_PADDING ); + mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_PADDING ); } } @@ -814,7 +832,7 @@ void Popup::LayoutPopup() OnLayoutSetup(); // Update background visibility. - mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) ); + mPopupContainer.SetProperty( Actor::Property::VISIBLE, !( !mFooter && mPopupLayout.GetChildCount() == 0 ) ); // Create / destroy / position the tail as needed. LayoutTail(); @@ -839,38 +857,50 @@ void Popup::LayoutTail() return; } - const Vector3& position = GetTailPosition(); + const Vector3& parentOrigin = GetTailPosition(); + Vector3 position; std::string image; + Vector3 anchorPoint; // depending on position of tail around ParentOrigin, a different tail image is used... - if( position.y < Math::MACHINE_EPSILON_1 ) + if( parentOrigin.y < Math::MACHINE_EPSILON_1 ) { image = mTailUpImage; + anchorPoint = AnchorPoint::BOTTOM_CENTER; + position.y = mBackgroundBorder.top; } - else if( position.y > 1.0f - Math::MACHINE_EPSILON_1 ) + else if( parentOrigin.y > ( 1.0f - Math::MACHINE_EPSILON_1 ) ) { image = mTailDownImage; + anchorPoint = AnchorPoint::TOP_CENTER; + position.y = - mBackgroundBorder.bottom; } - else if( position.x < Math::MACHINE_EPSILON_1 ) + else if( parentOrigin.x < Math::MACHINE_EPSILON_1 ) { image = mTailLeftImage; + anchorPoint = AnchorPoint::CENTER_RIGHT; + position.x = mBackgroundBorder.left; } - else if( position.x > 1.0f - Math::MACHINE_EPSILON_1 ) + else if( parentOrigin.x > ( 1.0f - Math::MACHINE_EPSILON_1 ) ) { image = mTailRightImage; + anchorPoint = AnchorPoint::CENTER_LEFT; + position.x = - mBackgroundBorder.right; } if( !image.empty() ) { // Adds the tail actor. - Image tail = ResourceImage::New( image ); - mTailImage = Toolkit::ImageView::New( tail ); - mTailImage.SetName( "tailImage" ); - const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position; - mTailImage.SetParentOrigin( position ); - mTailImage.SetAnchorPoint( anchorPoint ); + mTailImage = Toolkit::ImageView::New( image ); + mTailImage.SetProperty( Dali::Actor::Property::NAME, "tailImage" ); + mTailImage.SetProperty( Actor::Property::PARENT_ORIGIN, parentOrigin ); + mTailImage.SetProperty( Actor::Property::ANCHOR_POINT, anchorPoint ); + mTailImage.SetProperty( Actor::Property::POSITION, position ); - mPopupContainer.Add( mTailImage ); + if( mPopupBackgroundImage ) + { + mPopupBackgroundImage.Add( mTailImage ); + } } } @@ -888,23 +918,23 @@ Toolkit::Popup::ContextualMode Popup::GetContextualMode() const Toolkit::Control Popup::CreateBacking() { Toolkit::Control backing = Control::New(); - backing.SetBackgroundColor( Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) ); - backing.SetName( "popupBacking" ); + backing.SetProperty( Toolkit::Control::Property::BACKGROUND, + Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ) + .Add( Toolkit::ColorVisual::Property::MIX_COLOR, Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) ) ); + backing.SetProperty( Dali::Actor::Property::NAME, "popupBacking" ); // Must always be positioned top-left of stage, regardless of parent. - backing.SetInheritPosition(false); - backing.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + backing.SetProperty( Actor::Property::INHERIT_POSITION, false ); // Always the full size of the stage. backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - backing.SetSize( Stage::GetCurrent().GetSize() ); + backing.SetProperty( Actor::Property::SIZE, Stage::GetCurrent().GetSize() ); // Catch events. - backing.SetSensitive( true ); + backing.SetProperty( Actor::Property::SENSITIVE, true ); // Default to being transparent. backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f ); - backing.TouchSignal().Connect( this, &Popup::OnBackingTouched ); backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent ); return backing; } @@ -990,6 +1020,18 @@ void Popup::SetExitAnimationData( const Property::Map& map ) Scripting::NewAnimation( map, mExitAnimationData ); } +void Popup::UpdateBackgroundPositionAndSize() +{ + if( mPopupBackgroundImage ) + { + mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); + mPopupBackgroundImage.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( mBackgroundBorder.left + mBackgroundBorder.right, mBackgroundBorder.top + mBackgroundBorder.bottom, 0.0f ) ); + + // Adjust the position of the background so the transparent areas are set appropriately + mPopupBackgroundImage.SetProperty( Actor::Property::POSITION, Vector2( ( mBackgroundBorder.right - mBackgroundBorder.left ) * 0.5f, ( mBackgroundBorder.bottom - mBackgroundBorder.top ) * 0.5f )); + } +} + void Popup::SetAutoHideDelay( int delay ) { mAutoHideDelay = delay; @@ -1027,6 +1069,7 @@ void Popup::SetTailUpImage( std::string image ) { mTailUpImage = image; mLayoutDirty = true; + LayoutTail(); } const std::string& Popup::GetTailUpImage() const @@ -1038,6 +1081,7 @@ void Popup::SetTailDownImage( std::string image ) { mTailDownImage = image; mLayoutDirty = true; + LayoutTail(); } const std::string& Popup::GetTailDownImage() const @@ -1049,6 +1093,7 @@ void Popup::SetTailLeftImage( std::string image ) { mTailLeftImage = image; mLayoutDirty = true; + LayoutTail(); } const std::string& Popup::GetTailLeftImage() const @@ -1060,6 +1105,7 @@ void Popup::SetTailRightImage( std::string image ) { mTailRightImage = image; mLayoutDirty = true; + LayoutTail(); } const std::string& Popup::GetTailRightImage() const @@ -1069,7 +1115,11 @@ const std::string& Popup::GetTailRightImage() const void Popup::SetTouchTransparent( bool enabled ) { - mTouchTransparent = enabled; + if( mTouchTransparent != enabled ) + { + mTouchTransparent = enabled; + SetupTouch(); + } } const bool Popup::IsTouchTransparent() const @@ -1239,12 +1289,33 @@ void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, cons std::string valueString; if( value.Get( valueString ) ) { - Image image = ResourceImage::New( valueString ); - if( image ) - { - Toolkit::ImageView actor = Toolkit::ImageView::New( image ); - popupImpl.SetPopupBackgroundImage( actor ); - } + Toolkit::ImageView actor = Toolkit::ImageView::New( valueString ); + popupImpl.SetPopupBackgroundImage( actor ); + } + break; + } + case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER: + { + bool valueUpdated = false; + + Vector4 valueVector4; + if( value.Get( popupImpl.mBackgroundBorder ) ) + { + valueUpdated = true; + } + else if( value.Get( valueVector4 ) ) + { + popupImpl.mBackgroundBorder.left = valueVector4.x; + popupImpl.mBackgroundBorder.right = valueVector4.y; + popupImpl.mBackgroundBorder.bottom = valueVector4.z; + popupImpl.mBackgroundBorder.top = valueVector4.w; + valueUpdated = true; + } + + if( valueUpdated ) + { + popupImpl.LayoutTail(); // Update the tail if required + popupImpl.UpdateBackgroundPositionAndSize(); // Update the background's size and position } break; } @@ -1387,13 +1458,18 @@ Property::Value Popup::GetProperty( BaseObject* object, Property::Index property } case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE: { - ResourceImage image = ResourceImage::DownCast( popupImpl.GetPopupBackgroundImage() ); - if( image ) + Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( popupImpl.GetPopupBackgroundImage() ); + if( imageView ) { - value = image.GetUrl(); + value = imageView.GetProperty( Toolkit::ImageView::Property::IMAGE ); } break; } + case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER: + { + value = popupImpl.mBackgroundBorder; + break; + } case Toolkit::Popup::Property::TAIL_UP_IMAGE: { value = popupImpl.GetTailUpImage(); @@ -1456,28 +1532,20 @@ bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra return connected; } -bool Popup::OnBackingTouched( Actor actor, const TouchData& touch ) +bool Popup::OnBackingTouched( Actor actor, const TouchEvent& touch ) { - // Allow events to pass through if touch transparency is enabled. - if( mTouchTransparent ) + // Allow events to pass through if the backing isn't the hit-actor + if( (touch.GetHitActor(0) == actor) && + (touch.GetPointCount() > 0) && + (touch.GetState( 0 ) == PointState::DOWN)) { - return false; - } - - if( touch.GetPointCount() > 0 ) - { - if( touch.GetState( 0 ) == PointState::DOWN ) - { - // Guard against destruction during signal emission. - Toolkit::Popup handle( GetOwner() ); + // Guard against destruction during signal emission. + Toolkit::Popup handle( GetOwner() ); - mTouchedOutsideSignal.Emit(); - } + mTouchedOutsideSignal.Emit(); } - // Block anything behind backing becoming touched. - mLayer.SetTouchConsumed( true ); - return true; + return false; } bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event ) @@ -1488,36 +1556,25 @@ bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event ) return false; } - // Consume wheel event in dimmed backing actor. - mLayer.SetTouchConsumed( true ); return true; } -bool Popup::OnDialogTouched( Actor actor, const TouchData& touch ) +bool Popup::OnDialogTouched( Actor actor, const TouchEvent& touch ) { - // Allow events to pass through if touch transparency is enabled. - if( mTouchTransparent ) - { - return false; - } - - // Consume event (stops backing actor receiving touch events) - mLayer.SetTouchConsumed( true ); - return true; + // Only connecting this so the backing does not become the default hit-actor and inadvertently closes the popup + return false; } -void Popup::OnStageConnection( int depth ) +void Popup::OnSceneConnection( int depth ) { - Control::OnStageConnection( depth ); - mLayoutDirty = true; RelayoutRequest(); + + Control::OnSceneConnection( depth ); } void Popup::OnChildAdd( Actor& child ) { - Control::OnChildAdd( child ); - // Re-parent any children added by user to the body layer. if( mAlterAddedChild ) { @@ -1528,6 +1585,8 @@ void Popup::OnChildAdd( Actor& child ) mLayoutDirty = true; RelayoutRequest(); } + + Control::OnChildAdd( child ); } void Popup::LayoutContext( const Vector2& size ) @@ -1540,14 +1599,14 @@ void Popup::LayoutContext( const Vector2& size ) return; } - mPopupContainer.SetParentOrigin( ParentOrigin::CENTER ); + mPopupContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); // We always anchor to the CENTER, rather than a different anchor point for each contextual // mode to allow code-reuse of the bound checking code (for maintainability). - mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER ); + mPopupContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); // Setup with some pre-calculations for speed. Vector3 halfStageSize( Stage().GetCurrent().GetSize() / 2.0f ); - Vector3 parentPosition( parent.GetCurrentPosition() ); + Vector3 parentPosition( parent.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) ); Vector2 halfSize( size / 2.0f ); Vector2 halfParentSize( parent.GetRelayoutSize( Dimension::WIDTH ) / 2.0f, parent.GetRelayoutSize( Dimension::HEIGHT ) / 2.0f ); Vector3 newPosition( Vector3::ZERO ); @@ -1611,7 +1670,7 @@ void Popup::LayoutContext( const Vector2& size ) } // Set the final position. - mPopupContainer.SetPosition( newPosition ); + mPopupContainer.SetProperty( Actor::Property::POSITION, newPosition ); } void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container ) @@ -1736,9 +1795,9 @@ bool Popup::OnKeyEvent( const KeyEvent& event ) bool consumed = false; - if( event.state == KeyEvent::Down ) + if( event.GetState() == KeyEvent::DOWN ) { - if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK) + if (event.GetKeyCode() == Dali::DALI_KEY_ESCAPE || event.GetKeyCode() == Dali::DALI_KEY_BACK) { SetDisplayState( Toolkit::Popup::HIDDEN ); consumed = true; @@ -1755,7 +1814,7 @@ void Popup::AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& f Toolkit::Control control = Toolkit::Control::DownCast( parent ); bool layoutControl = control && GetImplementation( control ).IsKeyboardNavigationSupported(); - if( parent.IsKeyboardFocusable() || layoutControl ) + if( parent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) || layoutControl ) { focusableActors.push_back( parent ); @@ -1796,7 +1855,7 @@ Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit:: std::string currentStr; if( currentFocusedActor ) { - currentStr = currentFocusedActor.GetName(); + currentStr = currentFocusedActor.GetProperty< std::string >( Dali::Actor::Property::NAME ); } Actor nextFocusableActor( currentFocusedActor ); @@ -1813,12 +1872,12 @@ Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit:: ( currentFocusedActor && ( ( !mContent || ( currentFocusGroup != mContent ) ) && ( !mFooter || ( currentFocusGroup != mFooter ) ) ) ) ) { // The current focused actor is not within popup. - if( mContent && mContent.IsKeyboardFocusable() ) + if( mContent && mContent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) ) { // If the content is focusable, move the focus to the content. nextFocusableActor = mContent; } - else if( mFooter && mFooter.IsKeyboardFocusable() ) + else if( mFooter && mFooter.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) ) { // If the footer is focusable, move the focus to the footer. nextFocusableActor = mFooter; @@ -1882,6 +1941,11 @@ Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit:: nextFocusableActor = *( endIterator - 1 ); break; } + + default: + { + break; + } } if( !nextFocusableActor ) @@ -1894,6 +1958,25 @@ Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit:: return nextFocusableActor; } +void Popup::SetupTouch() +{ + if( ! mTouchTransparent ) + { + // Connect all the signals and set us up to consume all touch events + mBacking.TouchSignal().Connect( this, &Popup::OnBackingTouched ); + mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched ); + mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched ); + mLayer.SetProperty( Layer::Property::CONSUMES_TOUCH, true ); + } + else + { + // We are touch transparent so disconnect all signals and ensure our layer does not consumed all touch events + mBacking.TouchSignal().Disconnect( this, &Popup::OnBackingTouched ); + mPopupBackgroundImage.TouchSignal().Disconnect( this, &Popup::OnDialogTouched ); + mPopupLayout.TouchSignal().Disconnect( this, &Popup::OnDialogTouched ); + mLayer.SetProperty( Layer::Property::CONSUMES_TOUCH, false ); + } +} } // namespace Internal