X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftooltip%2Ftooltip.cpp;h=e8274d1558ecbaa58421041b338caf64b2a5365b;hp=3a2ccc09e95bdcffb794622091cac4e0577cc84f;hb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d;hpb=f3e45e41c5f16ccc2538b283897ed6efb07e4ea9 diff --git a/dali-toolkit/internal/controls/tooltip/tooltip.cpp b/dali-toolkit/internal/controls/tooltip/tooltip.cpp index 3a2ccc0..e8274d1 100644 --- a/dali-toolkit/internal/controls/tooltip/tooltip.cpp +++ b/dali-toolkit/internal/controls/tooltip/tooltip.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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,204 +21,196 @@ // EXTERNAL INCLUDES #include -#include -#include #include #include +#include +#include // INTERNAL INCLUDES #include -#include -#include #include -#include -#include #include #include +#include +#include +#include namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { - -DALI_ENUM_TO_STRING_TABLE_BEGIN( TOOLTIP_POSITION ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Tooltip::Position, ABOVE ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Tooltip::Position, BELOW ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Tooltip::Position, HOVER_POINT ) -DALI_ENUM_TO_STRING_TABLE_END( TOOLTIP_POSITION ) +DALI_ENUM_TO_STRING_TABLE_BEGIN(TOOLTIP_POSITION) + DALI_ENUM_TO_STRING_WITH_SCOPE(Toolkit::Tooltip::Position, ABOVE) + DALI_ENUM_TO_STRING_WITH_SCOPE(Toolkit::Tooltip::Position, BELOW) + DALI_ENUM_TO_STRING_WITH_SCOPE(Toolkit::Tooltip::Position, HOVER_POINT) +DALI_ENUM_TO_STRING_TABLE_END(TOOLTIP_POSITION) const float MILLISECONDS_PER_SECOND = 1000.0f; -const char * const PROPERTY_CONTENT_NAME = "content"; -const char * const PROPERTY_LAYOUT_NAME = "layout"; -const char * const PROPERTY_WAIT_TIME_NAME = "waitTime"; -const char * const PROPERTY_BACKGROUND_NAME = "background"; -const char * const PROPERTY_TAIL_NAME = "tail"; -const char * const PROPERTY_POSITION_NAME = "position"; -const char * const PROPERTY_HOVER_POINT_OFFSET_NAME = "hoverPointOffset"; -const char * const PROPERTY_MOVEMENT_THRESHOLD = "movementThreshold"; -const char * const PROPERTY_DISAPPEAR_ON_MOVEMENT = "disappearOnMovement"; +const char* const PROPERTY_CONTENT_NAME = "content"; +const char* const PROPERTY_LAYOUT_NAME = "layout"; +const char* const PROPERTY_WAIT_TIME_NAME = "waitTime"; +const char* const PROPERTY_BACKGROUND_NAME = "background"; +const char* const PROPERTY_TAIL_NAME = "tail"; +const char* const PROPERTY_POSITION_NAME = "position"; +const char* const PROPERTY_HOVER_POINT_OFFSET_NAME = "hoverPointOffset"; +const char* const PROPERTY_MOVEMENT_THRESHOLD = "movementThreshold"; +const char* const PROPERTY_DISAPPEAR_ON_MOVEMENT = "disappearOnMovement"; -const char * const PROPERTY_BACKGROUND_VISUAL = "visual"; -const char * const PROPERTY_BACKGROUND_BORDER = "border"; +const char* const PROPERTY_BACKGROUND_VISUAL = "visual"; +const char* const PROPERTY_BACKGROUND_BORDER = "border"; -const char * const PROPERTY_TAIL_VISIBILITY = "visibility"; -const char * const PROPERTY_TAIL_ABOVE_VISUAL = "aboveVisual"; -const char * const PROPERTY_TAIL_BELOW_VISUAL = "belowVisual"; +const char* const PROPERTY_TAIL_VISIBILITY = "visibility"; +const char* const PROPERTY_TAIL_ABOVE_VISUAL = "aboveVisual"; +const char* const PROPERTY_TAIL_BELOW_VISUAL = "belowVisual"; } // unnamed namespace -TooltipPtr Tooltip::New( Toolkit::Control control ) +TooltipPtr Tooltip::New(Toolkit::Control control) { - return new Tooltip( control ); + return new Tooltip(control); } -void Tooltip::SetProperties( const Property::Value& value ) +void Tooltip::SetProperties(const Property::Value& value) { Toolkit::Control control = mControl.GetHandle(); - if( control ) + if(control) { const Property::Map* properties = value.GetMap(); - if( properties ) + if(properties) { const Property::Map::SizeType count = properties->Count(); - for( Property::Map::SizeType position = 0; position < count; ++position ) + for(Property::Map::SizeType position = 0; position < count; ++position) { - KeyValuePair keyValue = properties->GetKeyValue( position ); - Property::Key& key = keyValue.first; - Property::Value& value = keyValue.second; + KeyValuePair keyValue = properties->GetKeyValue(position); + Property::Key& key = keyValue.first; + Property::Value& value = keyValue.second; - if( key == Toolkit::Tooltip::Property::CONTENT || key == PROPERTY_CONTENT_NAME ) + if(key == Toolkit::Tooltip::Property::CONTENT || key == PROPERTY_CONTENT_NAME) { - SetContent( control, value ); + SetContent(control, value); } - else if( key == Toolkit::Tooltip::Property::LAYOUT || key == PROPERTY_LAYOUT_NAME ) + else if(key == Toolkit::Tooltip::Property::LAYOUT || key == PROPERTY_LAYOUT_NAME) { - value.Get( mLayout ); + value.Get(mLayout); } - else if( key == Toolkit::Tooltip::Property::WAIT_TIME || key == PROPERTY_WAIT_TIME_NAME ) + else if(key == Toolkit::Tooltip::Property::WAIT_TIME || key == PROPERTY_WAIT_TIME_NAME) { float waitTime = 0.0f; - if( value.Get( waitTime ) ) + if(value.Get(waitTime)) { mWaitTime = waitTime * MILLISECONDS_PER_SECOND; } } - else if( key == Toolkit::Tooltip::Property::BACKGROUND || key == PROPERTY_BACKGROUND_NAME ) + else if(key == Toolkit::Tooltip::Property::BACKGROUND || key == PROPERTY_BACKGROUND_NAME) { - SetBackground( value ); + SetBackground(value); } - else if( key == Toolkit::Tooltip::Property::TAIL || key == PROPERTY_TAIL_NAME ) + else if(key == Toolkit::Tooltip::Property::TAIL || key == PROPERTY_TAIL_NAME) { - SetTail( value ); + SetTail(value); } - else if( key == Toolkit::Tooltip::Property::POSITION || key == PROPERTY_POSITION_NAME ) + else if(key == Toolkit::Tooltip::Property::POSITION || key == PROPERTY_POSITION_NAME) { - Scripting::GetEnumerationProperty< Toolkit::Tooltip::Position::Type >( value, TOOLTIP_POSITION_TABLE, TOOLTIP_POSITION_TABLE_COUNT, mPositionType ); + Scripting::GetEnumerationProperty(value, TOOLTIP_POSITION_TABLE, TOOLTIP_POSITION_TABLE_COUNT, mPositionType); } - else if( key == Toolkit::Tooltip::Property::HOVER_POINT_OFFSET || key == PROPERTY_HOVER_POINT_OFFSET_NAME ) + else if(key == Toolkit::Tooltip::Property::HOVER_POINT_OFFSET || key == PROPERTY_HOVER_POINT_OFFSET_NAME) { - value.Get( mHoverPointOffset ); + value.Get(mHoverPointOffset); } - else if( key == Toolkit::Tooltip::Property::MOVEMENT_THRESHOLD || key == PROPERTY_MOVEMENT_THRESHOLD ) + else if(key == Toolkit::Tooltip::Property::MOVEMENT_THRESHOLD || key == PROPERTY_MOVEMENT_THRESHOLD) { - value.Get( mMovementThreshold ); + value.Get(mMovementThreshold); } - else if( key == Toolkit::Tooltip::Property::DISAPPEAR_ON_MOVEMENT || key == PROPERTY_DISAPPEAR_ON_MOVEMENT ) + else if(key == Toolkit::Tooltip::Property::DISAPPEAR_ON_MOVEMENT || key == PROPERTY_DISAPPEAR_ON_MOVEMENT) { - value.Get( mDisappearOnMovement ); + value.Get(mDisappearOnMovement); } } } else { Property::Type type = value.GetType(); - if( ( value.GetType() == Property::STRING ) || ( type == Property::ARRAY ) ) + if((value.GetType() == Property::STRING) || (type == Property::ARRAY)) { - SetContent( control, value ); + SetContent(control, value); } } } } -void Tooltip::CreatePropertyMap( Property::Map& map ) const +void Tooltip::CreatePropertyMap(Property::Map& map) const { - if( ! mContentTextVisual.Empty() ) + if(!mContentTextVisual.Empty()) { Property::Map content = mContentTextVisual; // Need this copy as there's no Value constructor which takes in a 'const Property::Map&'. - map.Insert( Toolkit::Tooltip::Property::CONTENT, content ); + map.Insert(Toolkit::Tooltip::Property::CONTENT, content); } - else if( ! mContentArray.Empty() ) + else if(!mContentArray.Empty()) { Property::Array content = mContentArray; // Need this copy as there's no Value constructor which takes in a 'const Property::Array&'. - map.Insert( Toolkit::Tooltip::Property::CONTENT, content ); + map.Insert(Toolkit::Tooltip::Property::CONTENT, content); } - map.Insert( Toolkit::Tooltip::Property::LAYOUT, mLayout ); - map.Insert( Toolkit::Tooltip::Property::WAIT_TIME, static_cast( mWaitTime ) / MILLISECONDS_PER_SECOND ); - map.Insert( Toolkit::Tooltip::Property::BACKGROUND, - Property::Map().Add( Toolkit::Tooltip::Background::Property::VISUAL, mBackgroundImage ) - .Add( Toolkit::Tooltip::Background::Property::BORDER, mBackgroundBorder ) ); - map.Insert( Toolkit::Tooltip::Property::TAIL, - Property::Map().Add( Toolkit::Tooltip::Tail::Property::VISIBILITY, mTailVisibility ) - .Add( Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL, mTailImages[ Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL ]) - .Add( Toolkit::Tooltip::Tail::Property::BELOW_VISUAL, mTailImages[ Toolkit::Tooltip::Tail::Property::BELOW_VISUAL ]) ); - map.Insert( Toolkit::Tooltip::Property::POSITION, mPositionType ); - map.Insert( Toolkit::Tooltip::Property::HOVER_POINT_OFFSET, mHoverPointOffset ); - map.Insert( Toolkit::Tooltip::Property::MOVEMENT_THRESHOLD, mMovementThreshold ); - map.Insert( Toolkit::Tooltip::Property::DISAPPEAR_ON_MOVEMENT, mDisappearOnMovement ); + map.Insert(Toolkit::Tooltip::Property::LAYOUT, mLayout); + map.Insert(Toolkit::Tooltip::Property::WAIT_TIME, static_cast(mWaitTime) / MILLISECONDS_PER_SECOND); + map.Insert(Toolkit::Tooltip::Property::BACKGROUND, + Property::Map().Add(Toolkit::Tooltip::Background::Property::VISUAL, mBackgroundImage).Add(Toolkit::Tooltip::Background::Property::BORDER, mBackgroundBorder)); + map.Insert(Toolkit::Tooltip::Property::TAIL, + Property::Map().Add(Toolkit::Tooltip::Tail::Property::VISIBILITY, mTailVisibility).Add(Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL, mTailImages[Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL]).Add(Toolkit::Tooltip::Tail::Property::BELOW_VISUAL, mTailImages[Toolkit::Tooltip::Tail::Property::BELOW_VISUAL])); + map.Insert(Toolkit::Tooltip::Property::POSITION, mPositionType); + map.Insert(Toolkit::Tooltip::Property::HOVER_POINT_OFFSET, mHoverPointOffset); + map.Insert(Toolkit::Tooltip::Property::MOVEMENT_THRESHOLD, mMovementThreshold); + map.Insert(Toolkit::Tooltip::Property::DISAPPEAR_ON_MOVEMENT, mDisappearOnMovement); } -Tooltip::Tooltip( Toolkit::Control control ) +Tooltip::Tooltip(Toolkit::Control control) : mPopup(), mTooltipTimer(), - mControl( control ), + mControl(control), mContentTextVisual(), mTailImages(), mContentArray(), - mBackgroundBorder( 0, 0, 0, 0 ), - mLayout( 1, 1 ), + mBackgroundBorder(0, 0, 0, 0), + mLayout(1, 1), mHoverPoint(), - mHoverPointOffset( 10.0f, 10.0f ), + mHoverPointOffset(10.0f, 10.0f), mBackgroundImage(), - mMovementThreshold( 5.0f ), - mWaitTime( 500 ), - mPositionType( Toolkit::Tooltip::Position::ABOVE ), - mTailVisibility( false ), - mDisappearOnMovement( false ), - mSignalsConnected( false ) + mMovementThreshold(5.0f), + mWaitTime(500), + mPositionType(Toolkit::Tooltip::Position::ABOVE), + mTailVisibility(false), + mDisappearOnMovement(false), + mSignalsConnected(false) { - mTailImages[ Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL ] = ""; - mTailImages[ Toolkit::Tooltip::Tail::Property::BELOW_VISUAL ] = ""; + mTailImages[Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL] = ""; + mTailImages[Toolkit::Tooltip::Tail::Property::BELOW_VISUAL] = ""; } Tooltip::~Tooltip() { - if( mPopup ) + if(mPopup) { mPopup.Unparent(); mPopup.Reset(); } } -void Tooltip::SetContent( Toolkit::Control& control, const Property::Value& value ) +void Tooltip::SetContent(Toolkit::Control& control, const Property::Value& value) { // Delete popup & timer - if( mTooltipTimer ) + if(mTooltipTimer) { mTooltipTimer.Stop(); mTooltipTimer.Reset(); } - if( mPopup ) + if(mPopup) { mPopup.Unparent(); mPopup.Reset(); @@ -227,26 +219,26 @@ void Tooltip::SetContent( Toolkit::Control& control, const Property::Value& valu bool connectSignals = false; Property::Type type = value.GetType(); - if( type == Property::MAP ) + if(type == Property::MAP) { const Property::Map* map = value.GetMap(); - if( map ) + if(map) { - mContentTextVisual.Merge( *map ); + mContentTextVisual.Merge(*map); - Property::Value* typeValue = map->Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE ); - if( typeValue ) + Property::Value* typeValue = map->Find(Toolkit::Visual::Property::TYPE, VISUAL_TYPE); + if(typeValue) { // Set to an invalid value so it definitely changes if set in Scripting::GetEnumerationProperty - Toolkit::Visual::Type visualType = static_cast< Toolkit::Visual::Type >( -1 ); + Toolkit::Visual::Type visualType = static_cast(-1); - if( Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, visualType ) ) + if(Scripting::GetEnumerationProperty(*typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, visualType)) { - if( visualType == Toolkit::Visual::TEXT ) + if(visualType == Toolkit::Visual::TEXT) { // Visual Type is text, ensure we have a the TEXT property set before we connect to the signals. - if( map->Find( Toolkit::TextVisual::Property::TEXT, TEXT_PROPERTY ) ) + if(map->Find(Toolkit::TextVisual::Property::TEXT, TEXT_PROPERTY)) { mContentArray.Clear(); connectSignals = true; @@ -263,66 +255,66 @@ void Tooltip::SetContent( Toolkit::Control& control, const Property::Value& valu } } } - else if( type == Property::ARRAY ) + else if(type == Property::ARRAY) { - if( value.Get( mContentArray ) ) + if(value.Get(mContentArray)) { mContentTextVisual.Clear(); connectSignals = true; } } - else if( type == Property::STRING ) + else if(type == Property::STRING) { std::string text; - if( value.Get( text ) ) + if(value.Get(text)) { - mContentTextVisual[ Toolkit::TextVisual::Property::TEXT ] = text; - mContentTextVisual[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::TEXT; + mContentTextVisual[Toolkit::TextVisual::Property::TEXT] = text; + mContentTextVisual[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::TEXT; mContentArray.Clear(); connectSignals = true; } } - if( connectSignals && ! mSignalsConnected ) + if(connectSignals && !mSignalsConnected) { - control.HoveredSignal().Connect( this, &Tooltip::OnHovered ); - control.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); + control.HoveredSignal().Connect(this, &Tooltip::OnHovered); + control.SetProperty(Actor::Property::LEAVE_REQUIRED, true); mSignalsConnected = true; } } -void Tooltip::SetBackground( const Property::Value& value ) +void Tooltip::SetBackground(const Property::Value& value) { Property::Type type = value.GetType(); - if( type == Property::STRING ) + if(type == Property::STRING) { - value.Get( mBackgroundImage ); - mBackgroundBorder.Set( 0, 0, 0, 0 ); + value.Get(mBackgroundImage); + mBackgroundBorder.Set(0, 0, 0, 0); } - else if( type == Property::MAP ) + else if(type == Property::MAP) { const Property::Map* map = value.GetMap(); - if( map ) + if(map) { const Property::Map::SizeType count = map->Count(); - for( Property::Map::SizeType position = 0; position < count; ++position ) + for(Property::Map::SizeType position = 0; position < count; ++position) { - KeyValuePair keyValue = map->GetKeyValue( position ); - Property::Key& key = keyValue.first; - Property::Value& value = keyValue.second; + KeyValuePair keyValue = map->GetKeyValue(position); + Property::Key& key = keyValue.first; + Property::Value& value = keyValue.second; - if( key == Toolkit::Tooltip::Background::Property::VISUAL || key == PROPERTY_BACKGROUND_VISUAL ) + if(key == Toolkit::Tooltip::Background::Property::VISUAL || key == PROPERTY_BACKGROUND_VISUAL) { - value.Get( mBackgroundImage ); + value.Get(mBackgroundImage); } - else if( key == Toolkit::Tooltip::Background::Property::BORDER || key == PROPERTY_BACKGROUND_BORDER ) + else if(key == Toolkit::Tooltip::Background::Property::BORDER || key == PROPERTY_BACKGROUND_BORDER) { - if( ! value.Get( mBackgroundBorder ) ) + if(!value.Get(mBackgroundBorder)) { // If not a Property::RECTANGLE, then check if it's a Vector4 and set it accordingly Vector4 valueVector4; - if( value.Get( valueVector4 ) ) + if(value.Get(valueVector4)) { mBackgroundBorder.left = valueVector4.x; mBackgroundBorder.right = valueVector4.y; @@ -336,46 +328,46 @@ void Tooltip::SetBackground( const Property::Value& value ) } } -void Tooltip::SetTail( const Property::Value& value ) +void Tooltip::SetTail(const Property::Value& value) { Property::Type type = value.GetType(); - if( type == Property::BOOLEAN ) + if(type == Property::BOOLEAN) { - value.Get( mTailVisibility ); + value.Get(mTailVisibility); } - else if( type == Property::MAP ) + else if(type == Property::MAP) { Property::Map map; - if( value.Get( map ) ) + if(value.Get(map)) { const Property::Map::SizeType count = map.Count(); - for( Property::Map::SizeType position = 0; position < count; ++position ) + for(Property::Map::SizeType position = 0; position < count; ++position) { - KeyValuePair keyValue = map.GetKeyValue( position ); - Property::Key& key = keyValue.first; - Property::Value& value = keyValue.second; + KeyValuePair keyValue = map.GetKeyValue(position); + Property::Key& key = keyValue.first; + Property::Value& value = keyValue.second; // Set the values manually rather than merging so that we only have to deal with Property indices when creating the actual tooltip. - if( key == Toolkit::Tooltip::Tail::Property::VISIBILITY || key == PROPERTY_TAIL_VISIBILITY ) + if(key == Toolkit::Tooltip::Tail::Property::VISIBILITY || key == PROPERTY_TAIL_VISIBILITY) { - value.Get( mTailVisibility ); + value.Get(mTailVisibility); } - else if( key == Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL || key == PROPERTY_TAIL_ABOVE_VISUAL ) + else if(key == Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL || key == PROPERTY_TAIL_ABOVE_VISUAL) { std::string path; - if( value.Get( path ) ) + if(value.Get(path)) { - mTailImages[ Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL ] = path; + mTailImages[Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL] = path; } } - else if( key == Toolkit::Tooltip::Tail::Property::BELOW_VISUAL || key == PROPERTY_TAIL_BELOW_VISUAL ) + else if(key == Toolkit::Tooltip::Tail::Property::BELOW_VISUAL || key == PROPERTY_TAIL_BELOW_VISUAL) { std::string path; - if( value.Get( path ) ) + if(value.Get(path)) { - mTailImages[ Toolkit::Tooltip::Tail::Property::BELOW_VISUAL ] = path; + mTailImages[Toolkit::Tooltip::Tail::Property::BELOW_VISUAL] = path; } } } @@ -383,53 +375,53 @@ void Tooltip::SetTail( const Property::Value& value ) } } -bool Tooltip::OnHovered( Actor /* actor */, const HoverEvent& hover ) +bool Tooltip::OnHovered(Actor /* actor */, const HoverEvent& hover) { - const PointState::Type state = hover.GetState( 0 ); - switch( state ) + const PointState::Type state = hover.GetState(0); + switch(state) { case PointState::STARTED: case PointState::MOTION: { - if( ! mPopup ) + if(!mPopup) { - if( ! mTooltipTimer ) + if(!mTooltipTimer) { - mHoverPoint = hover.GetScreenPosition( 0 ); - mTooltipTimer = Timer::New( mWaitTime ); - mTooltipTimer.TickSignal().Connect( this, &Tooltip::OnTimeout ); + mHoverPoint = hover.GetScreenPosition(0); + mTooltipTimer = Timer::New(mWaitTime); + mTooltipTimer.TickSignal().Connect(this, &Tooltip::OnTimeout); mTooltipTimer.Start(); } else { - Vector2 movement = mHoverPoint - hover.GetScreenPosition( 0 ); - if( std::abs( movement.Length() ) > mMovementThreshold ) + Vector2 movement = mHoverPoint - hover.GetScreenPosition(0); + if(std::abs(movement.Length()) > mMovementThreshold) { mTooltipTimer.Stop(); mTooltipTimer.Reset(); - mHoverPoint = hover.GetScreenPosition( 0 ); - mTooltipTimer = Timer::New( mWaitTime ); - mTooltipTimer.TickSignal().Connect( this, &Tooltip::OnTimeout ); + mHoverPoint = hover.GetScreenPosition(0); + mTooltipTimer = Timer::New(mWaitTime); + mTooltipTimer.TickSignal().Connect(this, &Tooltip::OnTimeout); mTooltipTimer.Start(); } } } - else if( mDisappearOnMovement ) + else if(mDisappearOnMovement) { // Popup is showing, and we're set to disappear on excessive movement so make sure we're still within the threshold. - Vector2 movement = mHoverPoint - hover.GetScreenPosition( 0 ); - if( std::abs( movement.Length() ) > mMovementThreshold ) + Vector2 movement = mHoverPoint - hover.GetScreenPosition(0); + if(std::abs(movement.Length()) > mMovementThreshold) { // Exceeding the threshold, hide the popup. - if( mTooltipTimer ) + if(mTooltipTimer) { mTooltipTimer.Stop(); mTooltipTimer.Reset(); } - if( mPopup ) + if(mPopup) { mPopup.Unparent(); mPopup.Reset(); @@ -442,12 +434,12 @@ bool Tooltip::OnHovered( Actor /* actor */, const HoverEvent& hover ) case PointState::LEAVE: case PointState::INTERRUPTED: { - if( mTooltipTimer ) + if(mTooltipTimer) { mTooltipTimer.Stop(); mTooltipTimer.Reset(); } - if( mPopup ) + if(mPopup) { mPopup.Unparent(); mPopup.Reset(); @@ -467,122 +459,122 @@ bool Tooltip::OnHovered( Actor /* actor */, const HoverEvent& hover ) bool Tooltip::OnTimeout() { Toolkit::Control control = mControl.GetHandle(); - if( ! mPopup && control ) + if(!mPopup && control) { mPopup = Toolkit::Popup::New(); // General set up of popup - mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "NON_CONTEXTUAL" ); - mPopup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "NONE" ); - mPopup.SetProperty( Toolkit::Popup::Property::BACKING_ENABLED, false ); // Disable the dimmed backing. - mPopup.SetProperty( Toolkit::Popup::Property::TOUCH_TRANSPARENT, true ); // Let events pass through the popup - mPopup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mPopup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mPopup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Toolkit::Popup::Property::CONTEXTUAL_MODE, "NON_CONTEXTUAL"); + mPopup.SetProperty(Toolkit::Popup::Property::ANIMATION_MODE, "NONE"); + mPopup.SetProperty(Toolkit::Popup::Property::BACKING_ENABLED, false); // Disable the dimmed backing. + mPopup.SetProperty(Toolkit::Popup::Property::TOUCH_TRANSPARENT, true); // Let events pass through the popup + mPopup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mPopup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); // Background - mPopup.SetProperty( Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE, mBackgroundImage ); - mPopup.SetProperty( Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER, mBackgroundBorder ); + mPopup.SetProperty(Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE, mBackgroundImage); + mPopup.SetProperty(Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER, mBackgroundBorder); // Tail - mPopup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, mTailVisibility ); - mPopup.SetProperty( Toolkit::Popup::Property::TAIL_UP_IMAGE, mTailImages[ Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL ] ); - mPopup.SetProperty( Toolkit::Popup::Property::TAIL_DOWN_IMAGE, mTailImages[ Toolkit::Tooltip::Tail::Property::BELOW_VISUAL ] ); + mPopup.SetProperty(Toolkit::Popup::Property::TAIL_VISIBILITY, mTailVisibility); + mPopup.SetProperty(Toolkit::Popup::Property::TAIL_UP_IMAGE, mTailImages[Toolkit::Tooltip::Tail::Property::ABOVE_VISUAL]); + mPopup.SetProperty(Toolkit::Popup::Property::TAIL_DOWN_IMAGE, mTailImages[Toolkit::Tooltip::Tail::Property::BELOW_VISUAL]); Vector3 tailPosition; - switch( mPositionType ) + switch(mPositionType) { case Toolkit::Tooltip::Position::HOVER_POINT: case Toolkit::Tooltip::Position::BELOW: { - tailPosition = Vector3( 0.5f, 0.0f, 0.0 ); + tailPosition = Vector3(0.5f, 0.0f, 0.0); break; } case Toolkit::Tooltip::Position::ABOVE: { - tailPosition = Vector3( 0.5f, 1.0f, 0.0 ); + tailPosition = Vector3(0.5f, 1.0f, 0.0); break; } } - mPopup.SetProperty( Toolkit::Popup::Property::TAIL_POSITION, tailPosition ); + mPopup.SetProperty(Toolkit::Popup::Property::TAIL_POSITION, tailPosition); // Content Actor content; - if( ! mContentTextVisual.Empty() ) + if(!mContentTextVisual.Empty()) { content = Toolkit::Control::New(); - content.SetProperty( Toolkit::Control::Property::BACKGROUND, mContentTextVisual ); + content.SetProperty(Toolkit::Control::Property::BACKGROUND, mContentTextVisual); } - else if( ! mContentArray.Empty() ) + else if(!mContentArray.Empty()) { const unsigned int visuals = mContentArray.Size(); - unsigned int rows = mLayout.x; - unsigned int columns = mLayout.y; - if( Equals( mLayout.x, 1.0f, Math::MACHINE_EPSILON_1 ) && - Equals( mLayout.y, 1.0f, Math::MACHINE_EPSILON_1 ) && - visuals > 1 ) + unsigned int rows = mLayout.x; + unsigned int columns = mLayout.y; + if(Equals(mLayout.x, 1.0f, Math::MACHINE_EPSILON_1) && + Equals(mLayout.y, 1.0f, Math::MACHINE_EPSILON_1) && + visuals > 1) { - rows = mLayout.x; + rows = mLayout.x; columns = visuals; } - Toolkit::TableView tableView = Toolkit::TableView::New( rows, columns ); - tableView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + Toolkit::TableView tableView = Toolkit::TableView::New(rows, columns); + tableView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); - for( unsigned int currentContent = 0, currentRow = 0; currentRow < rows && currentContent < visuals; ++currentRow ) + for(unsigned int currentContent = 0, currentRow = 0; currentRow < rows && currentContent < visuals; ++currentRow) { - tableView.SetFitHeight( currentRow ); - for( unsigned int currentColumn = 0; currentColumn < columns && currentContent < visuals; ++currentColumn ) + tableView.SetFitHeight(currentRow); + for(unsigned int currentColumn = 0; currentColumn < columns && currentContent < visuals; ++currentColumn) { Actor child = Toolkit::Control::New(); - child.SetProperty( Toolkit::Control::Property::BACKGROUND, mContentArray[ currentContent ] ); + child.SetProperty(Toolkit::Control::Property::BACKGROUND, mContentArray[currentContent]); - Toolkit::TableView::CellPosition cellPosition( currentRow, currentColumn ); - tableView.AddChild( child, cellPosition ); - tableView.SetCellAlignment( cellPosition, HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - tableView.SetFitWidth( currentColumn ); + Toolkit::TableView::CellPosition cellPosition(currentRow, currentColumn); + tableView.AddChild(child, cellPosition); + tableView.SetCellAlignment(cellPosition, HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + tableView.SetFitWidth(currentColumn); ++currentContent; } } content = tableView; } - mPopup.SetContent( content ); + mPopup.SetContent(content); // Connect to the relayout signal of the background of the popup as at that point we have the full size - Actor popupBackground = GetImpl( mPopup ).GetPopupBackgroundImage(); - if( popupBackground ) + Actor popupBackground = GetImpl(mPopup).GetPopupBackgroundImage(); + if(popupBackground) { - popupBackground.OnRelayoutSignal().Connect( this, &Tooltip::OnRelayout ); + popupBackground.OnRelayoutSignal().Connect(this, &Tooltip::OnRelayout); } - mPopup.SetDisplayState( Toolkit::Popup::SHOWN ); + mPopup.SetDisplayState(Toolkit::Popup::SHOWN); - Stage::GetCurrent().Add( mPopup ); + Stage::GetCurrent().Add(mPopup); } return false; } -void Tooltip::OnRelayout( Actor actor ) +void Tooltip::OnRelayout(Actor actor) { - if( mPopup && actor ) + if(mPopup && actor) { - float popupWidth = actor.GetRelayoutSize( Dimension::WIDTH ); - float popupHeight = actor.GetRelayoutSize( Dimension::HEIGHT ); - float tailHeight = 0.0f; + float popupWidth = actor.GetRelayoutSize(Dimension::WIDTH); + float popupHeight = actor.GetRelayoutSize(Dimension::HEIGHT); + float tailHeight = 0.0f; Actor tail; - if( mTailVisibility ) + if(mTailVisibility) { // Popup's background has the tail, we want to know the tail size as well. - if( actor.GetChildCount() ) + if(actor.GetChildCount()) { - tail = actor.GetChildAt( 0 ); - if( tail ) + tail = actor.GetChildAt(0); + if(tail) { - tailHeight = tail.GetRelayoutSize( Dimension::HEIGHT ); + tailHeight = tail.GetRelayoutSize(Dimension::HEIGHT); } } } @@ -590,7 +582,7 @@ void Tooltip::OnRelayout( Actor actor ) Vector2 stageSize = Stage::GetCurrent().GetSize(); Vector3 position; - switch( mPositionType ) + switch(mPositionType) { case Toolkit::Tooltip::Position::HOVER_POINT: { @@ -602,10 +594,10 @@ void Tooltip::OnRelayout( Actor actor ) case Toolkit::Tooltip::Position::ABOVE: { Toolkit::Control control = mControl.GetHandle(); - if( control ) + if(control) { - Vector3 worldPos = control.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_POSITION ); - float height = control.GetRelayoutSize( Dimension::HEIGHT ); + Vector3 worldPos = control.GetCurrentProperty(Actor::Property::WORLD_POSITION); + float height = control.GetRelayoutSize(Dimension::HEIGHT); position.x = stageSize.width * 0.5f + worldPos.x - popupWidth * 0.5f; position.y = stageSize.height * 0.5f + worldPos.y - height * 0.5f - popupHeight * 1.0f - tailHeight; @@ -616,10 +608,10 @@ void Tooltip::OnRelayout( Actor actor ) case Toolkit::Tooltip::Position::BELOW: { Toolkit::Control control = mControl.GetHandle(); - if( control ) + if(control) { - Vector3 worldPos = control.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_POSITION ); - float height = control.GetRelayoutSize( Dimension::HEIGHT ); + Vector3 worldPos = control.GetCurrentProperty(Actor::Property::WORLD_POSITION); + float height = control.GetRelayoutSize(Dimension::HEIGHT); position.x = stageSize.width * 0.5f + worldPos.x - popupWidth * 0.5f; position.y = stageSize.height * 0.5f + worldPos.y + height * 0.5f + tailHeight; @@ -630,34 +622,34 @@ void Tooltip::OnRelayout( Actor actor ) // Ensure the Popup is still on the screen - if( position.x < 0.0f ) + if(position.x < 0.0f) { position.x = 0.0f; } - else if( ( position.x + popupWidth ) > stageSize.width ) + else if((position.x + popupWidth) > stageSize.width) { position.x -= position.x + popupWidth - stageSize.width; } bool yPosChanged = false; - if( position.y < 0.0f ) + if(position.y < 0.0f) { yPosChanged = true; - position.y = 0.0f; + position.y = 0.0f; } - else if( ( position.y + popupHeight ) > stageSize.height ) + else if((position.y + popupHeight) > stageSize.height) { yPosChanged = true; position.y -= position.y + popupHeight - stageSize.height; } - if( yPosChanged && tail ) + if(yPosChanged && tail) { // If we change the y position, then the tail may be shown pointing to the wrong control so just hide it. - tail.SetProperty( Actor::Property::VISIBLE, false ); + tail.SetProperty(Actor::Property::VISIBLE, false); } - mPopup.SetProperty( Actor::Property::POSITION, position ); + mPopup.SetProperty(Actor::Property::POSITION, position); } }