+ /* When animating in, we want to respect the origin applied to Self().
+ * For example, if zooming, not only will the final result be anchored to the
+ * selected point, but the zoom will originate from this point also.
+ *
+ * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
+ *
+ * -------- --------
+ * |X| |XXX|
+ * |`` Animates |XXX|
+ * | to: |XXX|
+ * | |````
+ * | |
+ */
+ mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() );
+ mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() );
+
+ // If there is only a title, use less padding.
+ if( mTitle )
+ {
+ if( !mContent && !mFooter )
+ {
+ mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
+ }
+ else
+ {
+ mTitle.SetPadding( DEFAULT_TITLE_PADDING );
+ }
+ }
+
+ // Allow derived classes to perform any layout they may need to do.
+ OnLayoutSetup();
+
+ // Update background visibility.
+ mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
+
+ // Create / destroy / position the tail as needed.
+ LayoutTail();
+
+ // Setup any layout and initialisation required for the selected animation.
+ LayoutAnimation();
+
+ RelayoutRequest();
+}
+
+void Popup::LayoutTail()
+{
+ // Removes the tail actor.
+ if( mTailImage && mTailImage.GetParent() )
+ {
+ mTailImage.GetParent().Remove( mTailImage );
+ mTailImage.Reset();
+ }
+
+ if( !mTailVisible )
+ {
+ return;
+ }
+
+ 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( parentOrigin.y < Math::MACHINE_EPSILON_1 )
+ {
+ image = mTailUpImage;
+ anchorPoint = AnchorPoint::BOTTOM_CENTER;
+ position.y = mBackgroundBorder.top;
+ }
+ else if( parentOrigin.y > ( 1.0f - Math::MACHINE_EPSILON_1 ) )
+ {
+ image = mTailDownImage;
+ anchorPoint = AnchorPoint::TOP_CENTER;
+ position.y = - mBackgroundBorder.bottom;
+ }
+ else if( parentOrigin.x < Math::MACHINE_EPSILON_1 )
+ {
+ image = mTailLeftImage;
+ anchorPoint = AnchorPoint::CENTER_RIGHT;
+ position.x = mBackgroundBorder.left;
+ }
+ 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.
+ mTailImage = Toolkit::ImageView::New( image );
+ mTailImage.SetName( "tailImage" );
+ mTailImage.SetParentOrigin( parentOrigin );
+ mTailImage.SetAnchorPoint( anchorPoint );
+ mTailImage.SetPosition( position );
+
+ if( mPopupBackgroundImage )
+ {
+ mPopupBackgroundImage.Add( mTailImage );
+ }
+ }
+}
+
+void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
+{
+ mContextualMode = mode;
+ mLayoutDirty = true;
+}
+
+Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
+{
+ return mContextualMode;
+}
+
+Toolkit::Control Popup::CreateBacking()
+{
+ Toolkit::Control backing = Control::New();
+ backing.SetBackgroundColor( Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) );
+ backing.SetName( "popupBacking" );
+
+ // Must always be positioned top-left of stage, regardless of parent.
+ backing.SetInheritPosition(false);
+ backing.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ // Always the full size of the stage.
+ backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+ backing.SetSize( Stage::GetCurrent().GetSize() );
+
+ // Catch events.
+ backing.SetSensitive( 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;
+}
+
+Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
+{
+ return mTouchedOutsideSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
+{
+ return mShowingSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
+{
+ return mShownSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
+{
+ return mHidingSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
+{
+ return mHiddenSignal;
+}
+
+void Popup::SetTailVisibility( bool visible )
+{
+ mTailVisible = visible;
+ mLayoutDirty = true;
+}
+
+const bool Popup::IsTailVisible() const
+{
+ return mTailVisible;
+}
+
+void Popup::SetTailPosition( Vector3 position )
+{
+ mTailPosition = position;
+ mLayoutDirty = true;
+}
+
+const Vector3& Popup::GetTailPosition() const
+{
+ return mTailPosition;
+}
+
+void Popup::SetAnimationDuration( float duration )
+{
+ mAnimationDuration = duration;
+ mLayoutDirty = true;
+}
+
+float Popup::GetAnimationDuration() const
+{
+ return mAnimationDuration;
+}
+
+void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
+{
+ mAnimationMode = animationMode;
+ mLayoutDirty = true;
+}
+
+Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
+{
+ return mAnimationMode;
+}
+
+void Popup::SetEntryAnimationData( const Property::Map& map )
+{
+ mEntryAnimationData.Clear();
+ Scripting::NewAnimation( map, mEntryAnimationData );
+}
+
+void Popup::SetExitAnimationData( const Property::Map& map )
+{
+ mExitAnimationData.Clear();
+ Scripting::NewAnimation( map, mExitAnimationData );
+}
+
+void Popup::UpdateBackgroundPositionAndSize()
+{
+ if( mPopupBackgroundImage )
+ {
+ mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
+ mPopupBackgroundImage.SetSizeModeFactor( 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.SetPosition( ( mBackgroundBorder.right - mBackgroundBorder.left ) * 0.5f, ( mBackgroundBorder.bottom - mBackgroundBorder.top ) * 0.5f );
+ }
+}
+
+void Popup::SetAutoHideDelay( int delay )
+{
+ mAutoHideDelay = delay;
+}
+
+int Popup::GetAutoHideDelay() const
+{
+ return mAutoHideDelay;
+}
+
+void Popup::SetBackingEnabled( bool enabled )
+{
+ mBackingEnabled = enabled;
+ mLayoutDirty = true;
+}
+
+const bool Popup::IsBackingEnabled() const
+{
+ return mBackingEnabled;
+}
+
+void Popup::SetBackingColor( Vector4 color )
+{
+ mBackingColor = color;
+ mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
+ mLayoutDirty = true;
+}
+
+const Vector4& Popup::GetBackingColor() const
+{
+ return mBackingColor;
+}
+
+void Popup::SetTailUpImage( std::string image )
+{
+ mTailUpImage = image;
+ mLayoutDirty = true;
+ LayoutTail();
+}
+
+const std::string& Popup::GetTailUpImage() const
+{
+ return mTailUpImage;
+}
+
+void Popup::SetTailDownImage( std::string image )
+{
+ mTailDownImage = image;
+ mLayoutDirty = true;
+ LayoutTail();
+}
+
+const std::string& Popup::GetTailDownImage() const
+{
+ return mTailDownImage;
+}
+
+void Popup::SetTailLeftImage( std::string image )
+{
+ mTailLeftImage = image;
+ mLayoutDirty = true;
+ LayoutTail();
+}
+
+const std::string& Popup::GetTailLeftImage() const
+{
+ return mTailLeftImage;
+}
+
+void Popup::SetTailRightImage( std::string image )
+{
+ mTailRightImage = image;
+ mLayoutDirty = true;
+ LayoutTail();
+}
+
+const std::string& Popup::GetTailRightImage() const
+{
+ return mTailRightImage;
+}
+
+void Popup::SetTouchTransparent( bool enabled )
+{
+ mTouchTransparent = enabled;
+}
+
+const bool Popup::IsTouchTransparent() const
+{
+ return mTouchTransparent;
+}
+
+void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
+{
+ Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
+
+ if ( popup )
+ {
+ Popup& popupImpl( GetImpl( popup ) );
+
+ switch ( propertyIndex )
+ {
+ case Toolkit::Popup::Property::TITLE:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::CONTENT:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetContent( Scripting::NewActor( valueMap ) );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::FOOTER:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::DISPLAY_STATE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
+ if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
+ {
+ popupImpl.SetDisplayState( displayState );
+ }
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
+ {
+ bool valueBool;
+ if( value.Get( valueBool ) )
+ {
+ popupImpl.SetTouchTransparent( valueBool );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_VISIBILITY:
+ {
+ bool valueBool;
+ if( value.Get( valueBool ) )
+ {
+ popupImpl.SetTailVisibility( valueBool );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_POSITION:
+ {
+ Vector3 valueVector3;
+ if( value.Get( valueVector3 ) )
+ {
+ popupImpl.SetTailPosition( valueVector3 );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::CONTEXTUAL_MODE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
+ if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
+ {
+ popupImpl.SetContextualMode( contextualMode );
+ }
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_DURATION:
+ {
+ float valueFloat;
+ if( value.Get( valueFloat ) )
+ {
+ popupImpl.SetAnimationDuration( valueFloat );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_MODE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
+ if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
+ {
+ popupImpl.SetAnimationMode( animationMode );
+ }
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::ENTRY_ANIMATION:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetEntryAnimationData( valueMap );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::EXIT_ANIMATION:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetExitAnimationData( valueMap );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
+ {
+ int valueInt;
+ if( value.Get( valueInt ) )
+ {
+ popupImpl.SetAutoHideDelay( valueInt );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_ENABLED:
+ {
+ bool valueBool;
+ if( value.Get( valueBool ) )
+ {
+ popupImpl.SetBackingEnabled( valueBool );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_COLOR:
+ {
+ Vector4 valueVector4;
+ if( value.Get( valueVector4 ) )
+ {
+ popupImpl.SetBackingColor( valueVector4 );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ 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;
+ }
+ case Toolkit::Popup::Property::TAIL_UP_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailUpImage( valueString );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailDownImage( valueString );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailLeftImage( valueString );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailRightImage( valueString );
+ }
+ break;
+ }
+ }
+ }
+}
+
+Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
+{
+ Property::Value value;
+
+ Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
+
+ if ( popup )
+ {
+ Popup& popupImpl( GetImpl( popup ) );
+
+ switch ( propertyIndex )
+ {
+ case Toolkit::Popup::Property::TITLE:
+ {
+ Property::Map map;
+ Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::CONTENT:
+ {
+ Property::Map map;
+ Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::FOOTER:
+ {
+ Property::Map map;
+ Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::DISPLAY_STATE:
+ {
+ value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
+ break;
+ }
+ case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
+ {
+ value = popupImpl.IsTouchTransparent();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_VISIBILITY:
+ {
+ value = popupImpl.IsTailVisible();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_POSITION:
+ {
+ value = popupImpl.GetTailPosition();
+ break;
+ }
+ case Toolkit::Popup::Property::CONTEXTUAL_MODE:
+ {
+ value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_DURATION:
+ {
+ value = popupImpl.GetAnimationDuration();
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_MODE:
+ {
+ value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
+ break;
+ }
+ case Toolkit::Popup::Property::ENTRY_ANIMATION:
+ {
+ // Note: Cannot retrieve property map from animation.
+ Property::Map map;
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::EXIT_ANIMATION:
+ {
+ // Note: Cannot retrieve property map from animation.
+ Property::Map map;
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
+ {
+ value = popupImpl.GetAutoHideDelay();
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_ENABLED:
+ {
+ value = popupImpl.IsBackingEnabled();
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_COLOR:
+ {
+ value = popupImpl.GetBackingColor();
+ break;
+ }
+ case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
+ {
+ Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( popupImpl.GetPopupBackgroundImage() );
+ if( imageView )
+ {
+ 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();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
+ {
+ value = popupImpl.GetTailDownImage();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
+ {
+ value = popupImpl.GetTailLeftImage();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
+ {
+ value = popupImpl.GetTailRightImage();
+ break;
+ }
+ }
+ }
+
+ return value;
+}