From bef1f57ae2a7b02484658bca8264e264554fdb40 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Thu, 5 Oct 2023 18:31:30 +0100 Subject: [PATCH] Reduce unused methods and CC of actor classes Change-Id: I73bbca5c6556aabc0674af92ea3a6c8bbcf39945 --- dali/internal/event/actors/actor-impl.cpp | 20 --- dali/internal/event/actors/actor-impl.h | 32 ---- .../event/actors/actor-property-handler.cpp | 190 +++++++++------------ 3 files changed, 81 insertions(+), 161 deletions(-) diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 92e1668..99bd8e3 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -476,16 +476,6 @@ const Vector3& Actor::GetCurrentAnchorPoint() const return (mAnchorPoint) ? *mAnchorPoint : AnchorPoint::DEFAULT; } -void Actor::SetPosition(float x, float y) -{ - SetPosition(Vector3(x, y, 0.0f)); -} - -void Actor::SetPosition(float x, float y, float z) -{ - SetPosition(Vector3(x, y, z)); -} - void Actor::SetPosition(const Vector3& position) { mTargetPosition = position; @@ -626,16 +616,6 @@ const Quaternion& Actor::GetCurrentWorldOrientation() const return GetNode().GetWorldOrientation(GetEventThreadServices().GetEventBufferIndex()); } -void Actor::SetScale(float scale) -{ - SetScale(Vector3(scale, scale, scale)); -} - -void Actor::SetScale(float x, float y, float z) -{ - SetScale(Vector3(x, y, z)); -} - void Actor::SetScale(const Vector3& scale) { mTargetScale = scale; diff --git a/dali/internal/event/actors/actor-impl.h b/dali/internal/event/actors/actor-impl.h index b3132bc..f60e531 100644 --- a/dali/internal/event/actors/actor-impl.h +++ b/dali/internal/event/actors/actor-impl.h @@ -365,24 +365,6 @@ public: /** * Sets the position of the Actor. * The coordinates are relative to the Actor's parent. - * The Actor's z position will be set to 0.0f. - * @param [in] x The new x position - * @param [in] y The new y position - */ - void SetPosition(float x, float y); - - /** - * Sets the position of the Actor. - * The coordinates are relative to the Actor's parent. - * @param [in] x The new x position - * @param [in] y The new y position - * @param [in] z The new z position - */ - void SetPosition(float x, float y, float z); - - /** - * Sets the position of the Actor. - * The coordinates are relative to the Actor's parent. * @param [in] position The new position. */ void SetPosition(const Vector3& position); @@ -515,20 +497,6 @@ public: /** * Sets a scale factor applied to an actor. - * @param [in] scale The scale factor applied on all axes. - */ - void SetScale(float scale); - - /** - * Sets a scale factor applied to an actor. - * @param [in] scaleX The scale factor applied along the x-axis. - * @param [in] scaleY The scale factor applied along the y-axis. - * @param [in] scaleZ The scale factor applied along the z-axis. - */ - void SetScale(float scaleX, float scaleY, float scaleZ); - - /** - * Sets a scale factor applied to an actor. * @param [in] scale A vector representing the scale factor for each axis. */ void SetScale(const Vector3& scale); diff --git a/dali/internal/event/actors/actor-property-handler.cpp b/dali/internal/event/actors/actor-property-handler.cpp index 1792cc2..2815b29 100644 --- a/dali/internal/event/actors/actor-property-handler.cpp +++ b/dali/internal/event/actors/actor-property-handler.cpp @@ -114,21 +114,68 @@ bool GetAnchorPointParentOriginConstant(const std::string& value, Vector3& ancho bool GetVector3Value(const Property::Value& property, Vector3& vector3) { - Property::Type type = property.GetType(); - if(type == Property::VECTOR3) + if(property.Get(vector3)) { - property.Get(vector3); return true; } - else if(type == Property::STRING) + else { std::string stringConstant; - property.Get(stringConstant); - return GetAnchorPointParentOriginConstant(stringConstant, vector3); + if(property.Get(stringConstant)) + { + return GetAnchorPointParentOriginConstant(stringConstant, vector3); + } + else + { + float value = 0.0f; + if(property.Get(value)) + { + vector3.x = vector3.y = vector3.z = value; + return true; + } + } } return false; } +void DetermineVector3ValueAndSet(const Property::Value& property, Actor& actor, void (Actor::*member)(const Vector3&)) +{ + Vector3 value; + if(GetVector3Value(property, value)) + { + (actor.*member)(value); + } +} + +template +void CheckValidAndSet(const Property::Value& property, Actor& actor, void (Actor::*member)(ParameterType)) +{ + ParameterType value; + if(property.Get(value)) + { + (actor.*member)(value); + } +} + +template +void CheckValidAndSet(const Property::Value& property, Actor& actor, void (Actor::*member)(const ParameterType&)) +{ + ParameterType value; + if(property.Get(value)) + { + (actor.*member)(value); + } +} + +template +void CheckValidAndSet(const Property::Value& property, Function function) +{ + ParameterType value; + if(property.Get(value)) + { + function(value); + } +} } // unnamed namespace void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property::Index index, const Property::Value& property) @@ -137,11 +184,7 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property { case Dali::Actor::Property::PARENT_ORIGIN: { - Vector3 parentOrigin; - if(GetVector3Value(property, parentOrigin)) - { - actor.SetParentOrigin(parentOrigin); - } + DetermineVector3ValueAndSet(property, actor, &Actor::SetParentOrigin); break; } @@ -168,11 +211,7 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::ANCHOR_POINT: { - Vector3 anchorPoint; - if(GetVector3Value(property, anchorPoint)) - { - actor.SetAnchorPoint(anchorPoint); - } + DetermineVector3ValueAndSet(property, actor, &Actor::SetAnchorPoint); break; } @@ -199,11 +238,7 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::SIZE: { - Vector3 size; - if(property.Get(size)) - { - actor.SetSize(size); - } + DetermineVector3ValueAndSet(property, actor, &Actor::SetSize); break; } @@ -227,11 +262,7 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::POSITION: { - Vector3 position; - if(property.Get(position)) - { - actor.SetPosition(position); - } + DetermineVector3ValueAndSet(property, actor, &Actor::SetPosition); break; } @@ -261,16 +292,7 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::SCALE: { - Property::Type type = property.GetType(); - if(type == Property::FLOAT) - { - float scale = property.Get(); - actor.SetScale(scale, scale, scale); - } - else if(type == Property::VECTOR3) - { - actor.SetScale(property.Get()); - } + DetermineVector3ValueAndSet(property, actor, &Actor::SetScale); break; } @@ -300,12 +322,11 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::COLOR: { - Vector4 color; - if(property.Get(color)) - { - color.a = (property.GetType() == Property::VECTOR4) ? color.a : 1.0f; - actor.SetColor(color); - } + CheckValidAndSet(property, + [&property, &actor](Vector4& color) { + color.a = (property.GetType() == Property::VECTOR4) ? color.a : 1.0f; + actor.SetColor(color); + }); break; } @@ -330,11 +351,7 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::COLOR_ALPHA: case Dali::Actor::Property::OPACITY: { - float value; - if(property.Get(value)) - { - actor.SetOpacity(value); - } + CheckValidAndSet(property, actor, &Actor::SetOpacity); break; } @@ -523,128 +540,83 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION: { - bool value = false; - if(property.Get(value)) - { - actor.SetInheritLayoutDirection(value); - } + CheckValidAndSet(property, actor, &Actor::SetInheritLayoutDirection); break; } case Dali::Actor::Property::KEYBOARD_FOCUSABLE: { - bool value = false; - if(property.Get(value)) - { - actor.SetKeyboardFocusable(value); - } + CheckValidAndSet(property, actor, &Actor::SetKeyboardFocusable); break; } case Dali::Actor::Property::UPDATE_AREA_HINT: { - actor.SetUpdateAreaHint(property.Get()); + CheckValidAndSet(property, actor, &Actor::SetUpdateAreaHint); break; } case Dali::DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START: { - bool boolValue = false; - if(property.Get(boolValue)) - { - actor.mCaptureAllTouchAfterStart = boolValue; - } + CheckValidAndSet(property, [&actor](bool value) { actor.mCaptureAllTouchAfterStart = value; }); break; } case Dali::DevelActor::Property::TOUCH_AREA_OFFSET: { - Rect rectValue; - if(property.Get(rectValue)) - { - actor.SetTouchAreaOffset(rectValue); - } + CheckValidAndSet(property, actor, &Actor::SetTouchAreaOffset); break; } case Dali::DevelActor::Property::BLEND_EQUATION: { - int value; - if(property.Get(value)) - { - actor.SetBlendEquation(static_cast(value)); - } + CheckValidAndSet(property, actor, &Actor::SetBlendEquation); break; } case Dali::DevelActor::Property::TOUCH_FOCUSABLE: { - bool value = false; - if(property.Get(value)) - { - actor.SetTouchFocusable(value); - } + CheckValidAndSet(property, actor, &Actor::SetTouchFocusable); break; } case Dali::DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN: { - bool value = false; - if(property.Get(value)) - { - actor.SetKeyboardFocusableChildren(value); - } + CheckValidAndSet(property, actor, &Actor::SetKeyboardFocusableChildren); break; } case Dali::DevelActor::Property::USER_INTERACTION_ENABLED: { - bool value = false; - if(property.Get(value)) - { - actor.SetUserInteractionEnabled(value); - } + CheckValidAndSet(property, actor, &Actor::SetUserInteractionEnabled); break; } case Dali::DevelActor::Property::ALLOW_ONLY_OWN_TOUCH: { - bool boolValue = false; - if(property.Get(boolValue)) - { - actor.mAllowOnlyOwnTouch = boolValue; - } + CheckValidAndSet(property, [&actor](bool value) { actor.mAllowOnlyOwnTouch = value; }); break; } case Dali::DevelActor::Property::USE_TEXTURE_UPDATE_AREA: { - bool boolValue = false; - if(property.Get(boolValue)) - { - actor.mUseTextureUpdateArea = boolValue; - UseTextureUpdateAreaMessage(actor.GetEventThreadServices(), actor.GetNode(), boolValue); - } + CheckValidAndSet(property, + [&actor](bool value) { + actor.mUseTextureUpdateArea = value; + UseTextureUpdateAreaMessage(actor.GetEventThreadServices(), actor.GetNode(), value); + }); break; } case Dali::DevelActor::Property::DISPATCH_TOUCH_MOTION: { - bool boolValue = false; - if(property.Get(boolValue)) - { - actor.mDispatchTouchMotion = boolValue; - } + CheckValidAndSet(property, [&actor](bool value) { actor.mDispatchTouchMotion = value; }); break; } case Dali::DevelActor::Property::DISPATCH_HOVER_MOTION: { - bool boolValue = false; - if(property.Get(boolValue)) - { - actor.mDispatchHoverMotion = boolValue; - } + CheckValidAndSet(property, [&actor](bool value) { actor.mDispatchHoverMotion = value; }); break; } -- 2.7.4