X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Fcontrols%2Fcontrol-impl.cpp;h=46f24d8adc5f48407d6156473a332b4fa31b63ff;hp=68fd55ad3457c1b982f77889b3fdd87338348c6d;hb=4d3140d11ea9df2cf933d32419f49fc5e63fa4a9;hpb=f8ca770d5047cfb0dc60e321e1194c5dcf5e59cb diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp old mode 100644 new mode 100755 index 68fd55a..46f24d8 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -30,18 +30,19 @@ #include // INTERNAL INCLUDES -#include +#include #include +#include #include #include +#include #include #include -#include #include +#include #include #include #include -#include #include namespace Dali @@ -61,6 +62,30 @@ Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CO #endif /** + * @brief Replace the background visual if it's a color visual with the renderIfTransparent property set as required. + * @param[in] controlImpl The control implementation + * @param[in] renderIfTransaparent Whether we should render if the color is transparent + */ +void ChangeBackgroundColorVisual( Control& controlImpl, bool renderIfTransparent ) +{ + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); + + Toolkit::Visual::Base backgroundVisual = controlDataImpl.GetVisual( Toolkit::Control::Property::BACKGROUND ); + if( backgroundVisual ) + { + Property::Map map; + backgroundVisual.CreatePropertyMap( map ); + Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE ); + if( typeValue && typeValue->Get< int >() == Toolkit::Visual::COLOR ) + { + // Only change it if it's a color visual + map[ Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = renderIfTransparent; + controlImpl.SetBackground( map ); + } + } +} + +/** * @brief Creates a clipping renderer if required. * (EG. If no renders exist and clipping is enabled). * @param[in] controlImpl The control implementation. @@ -72,13 +97,34 @@ void CreateClippingRenderer( Control& controlImpl ) int clippingMode = ClippingMode::DISABLED; if( self.GetProperty( Actor::Property::CLIPPING_MODE ).Get( clippingMode ) ) { - Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); - - if( ( clippingMode == ClippingMode::CLIP_CHILDREN ) && - controlDataImpl.mVisuals.Empty() && - ( self.GetRendererCount() == 0u ) ) + switch( clippingMode ) { - controlImpl.SetBackgroundColor( Color::TRANSPARENT ); + case ClippingMode::CLIP_CHILDREN: + { + if( self.GetRendererCount() == 0u ) + { + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); + if( controlDataImpl.mVisuals.Empty() ) + { + controlImpl.SetBackgroundColor( Color::TRANSPARENT ); + } + else + { + // We have visuals, check if we've set the background and re-create it to + // render even if transparent (only if it's a color visual) + ChangeBackgroundColorVisual( controlImpl, true ); + } + } + break; + } + + case ClippingMode::DISABLED: + case ClippingMode::CLIP_TO_BOUNDING_BOX: + { + // If we have a background visual, check if it's a color visual and remove the render if transparent flag + ChangeBackgroundColorVisual( controlImpl, false ); + break; + } } } } @@ -128,12 +174,15 @@ void Control::SetBackgroundColor( const Vector4& color ) map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; - SetBackground( map ); -} + int clippingMode = ClippingMode::DISABLED; + if( ( Self().GetProperty( Actor::Property::CLIPPING_MODE ).Get( clippingMode ) ) && + ( clippingMode == ClippingMode::CLIP_CHILDREN ) ) + { + // If clipping-mode is set to CLIP_CHILDREN, then force visual to add the render even if transparent + map[ Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = true; + } -Vector4 Control::GetBackgroundColor() const -{ - return mImpl->mBackgroundColor; + SetBackground( map ); } void Control::SetBackground( const Property::Map& map ) @@ -149,24 +198,37 @@ void Control::SetBackground( const Property::Map& map ) } } -void Control::SetBackgroundImage( Image image ) +void Control::ClearBackground() { - Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image ); + mImpl->UnregisterVisual( Toolkit::Control::Property::BACKGROUND ); + mImpl->mBackgroundColor = Color::TRANSPARENT; + + // Trigger a size negotiation request that may be needed when unregistering a visual. + RelayoutRequest(); +} + +void Control::SetShadow( const Property::Map& map ) +{ + Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map ); + visual.SetName("shadow"); + if( visual ) { - mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND ); + mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT ); + + RelayoutRequest(); } } -void Control::ClearBackground() +void Control::ClearShadow() { - mImpl->UnregisterVisual( Toolkit::Control::Property::BACKGROUND ); - mImpl->mBackgroundColor = Color::TRANSPARENT; + mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW ); // Trigger a size negotiation request that may be needed when unregistering a visual. RelayoutRequest(); } + void Control::EnableGestureDetection(Gesture::Type type) { if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector ) @@ -371,13 +433,15 @@ bool Control::EmitKeyEventSignal( const KeyEvent& event ) bool consumed = false; + consumed = mImpl->FilterKeyEvent( event ); + // signals are allocated dynamically when someone connects - if ( !mImpl->mKeyEventSignal.Empty() ) + if ( !consumed && !mImpl->mKeyEventSignal.Empty() ) { consumed = mImpl->mKeyEventSignal.Emit( handle, event ); } - if (!consumed) + if ( !consumed ) { // Notification for derived classes consumed = OnKeyEvent(event); @@ -517,8 +581,12 @@ void Control::OnStageConnection( int depth ) // The clipping renderer is only created if required. CreateClippingRenderer( *this ); + + // Request to be laid out when the control is connected to the Stage. + // Signal that a Relayout may be needed } + void Control::OnStageDisconnection() { mImpl->OnStageDisconnection(); @@ -596,7 +664,35 @@ void Control::OnRelayout( const Vector2& size, RelayoutContainer& container ) { for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i ) { - container.Add( Self().GetChildAt( i ), size ); + Actor child = Self().GetChildAt( i ); + Vector2 newChildSize( size ); + + // When set the padding or margin on the control, child should be resized and repositioned. + if( ( mImpl->mPadding.start != 0 ) || ( mImpl->mPadding.end != 0 ) || ( mImpl->mPadding.top != 0 ) || ( mImpl->mPadding.bottom != 0 ) || + ( mImpl->mMargin.start != 0 ) || ( mImpl->mMargin.end != 0 ) || ( mImpl->mMargin.top != 0 ) || ( mImpl->mMargin.bottom != 0 ) ) + { + Extents padding = mImpl->mPadding; + + Dali::CustomActor ownerActor(GetOwner()); + Dali::LayoutDirection::Type layoutDirection = static_cast( ownerActor.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + + if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection ) + { + std::swap( padding.start, padding.end ); + } + + newChildSize.width = size.width - ( padding.start + padding.end ); + newChildSize.height = size.height - ( padding.top + padding.bottom ); + + // Cannot use childs Position property as it can already have padding and margin applied on it, + // so we end up cumulatively applying them over and over again. + Vector2 childOffset( 0.f, 0.f ); + childOffset.x += ( mImpl->mMargin.start + padding.start ); + childOffset.y += ( mImpl->mMargin.top + padding.top ); + + child.SetPosition( childOffset.x, childOffset.y ); + } + container.Add( child, newChildSize ); } Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND ); @@ -612,11 +708,14 @@ void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dime Vector3 Control::GetNaturalSize() { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetName().c_str() ); Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND ); if( visual ) { Vector2 naturalSize; visual.GetNaturalSize( naturalSize ); + naturalSize.width += ( mImpl->mPadding.start + mImpl->mPadding.end ); + naturalSize.height += ( mImpl->mPadding.top + mImpl->mPadding.bottom ); return Vector3( naturalSize ); } return Vector3::ZERO;