From: Adeel Kazmi Date: Fri, 29 Sep 2023 14:38:46 +0000 (+0100) Subject: Reduce cylcomatic complexity of actor-property-handler.cpp X-Git-Tag: dali_2.2.47~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F73%2F299473%2F1;p=platform%2Fcore%2Fuifw%2Fdali-core.git Reduce cylcomatic complexity of actor-property-handler.cpp Change-Id: Id53496834d7a42c68d85c25f745d309780c36de1 --- diff --git a/dali/internal/event/actors/actor-property-handler.cpp b/dali/internal/event/actors/actor-property-handler.cpp index de99149..1792cc2 100644 --- a/dali/internal/event/actors/actor-property-handler.cpp +++ b/dali/internal/event/actors/actor-property-handler.cpp @@ -98,7 +98,7 @@ DALI_ENUM_TO_STRING_TABLE_BEGIN(LAYOUT_DIRECTION) DALI_ENUM_TO_STRING_WITH_SCOPE(LayoutDirection, RIGHT_TO_LEFT) DALI_ENUM_TO_STRING_TABLE_END(LAYOUT_DIRECTION) -bool GetAnchorPointConstant(const std::string& value, Vector3& anchor) +bool GetAnchorPointParentOriginConstant(const std::string& value, Vector3& anchor) { for(uint32_t i = 0; i < ANCHOR_CONSTANT_TABLE_COUNT; ++i) { @@ -112,10 +112,21 @@ bool GetAnchorPointConstant(const std::string& value, Vector3& anchor) return false; } -inline bool GetParentOriginConstant(const std::string& value, Vector3& parentOrigin) +bool GetVector3Value(const Property::Value& property, Vector3& vector3) { - // Values are the same so just use the same table as anchor-point - return GetAnchorPointConstant(value, parentOrigin); + Property::Type type = property.GetType(); + if(type == Property::VECTOR3) + { + property.Get(vector3); + return true; + } + else if(type == Property::STRING) + { + std::string stringConstant; + property.Get(stringConstant); + return GetAnchorPointParentOriginConstant(stringConstant, vector3); + } + return false; } } // unnamed namespace @@ -126,20 +137,10 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property { case Dali::Actor::Property::PARENT_ORIGIN: { - Property::Type type = property.GetType(); - if(type == Property::VECTOR3) + Vector3 parentOrigin; + if(GetVector3Value(property, parentOrigin)) { - actor.SetParentOrigin(property.Get()); - } - else if(type == Property::STRING) - { - std::string parentOriginString; - property.Get(parentOriginString); - Vector3 parentOrigin; - if(GetParentOriginConstant(parentOriginString, parentOrigin)) - { - actor.SetParentOrigin(parentOrigin); - } + actor.SetParentOrigin(parentOrigin); } break; } @@ -167,20 +168,10 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::ANCHOR_POINT: { - Property::Type type = property.GetType(); - if(type == Property::VECTOR3) - { - actor.SetAnchorPoint(property.Get()); - } - else if(type == Property::STRING) + Vector3 anchorPoint; + if(GetVector3Value(property, anchorPoint)) { - std::string anchorPointString; - property.Get(anchorPointString); - Vector3 anchor; - if(GetAnchorPointConstant(anchorPointString, anchor)) - { - actor.SetAnchorPoint(anchor); - } + actor.SetAnchorPoint(anchorPoint); } break; } @@ -208,14 +199,10 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::SIZE: { - Property::Type type = property.GetType(); - if(type == Property::VECTOR2) + Vector3 size; + if(property.Get(size)) { - actor.SetSize(property.Get()); - } - else if(type == Property::VECTOR3) - { - actor.SetSize(property.Get()); + actor.SetSize(size); } break; } @@ -240,15 +227,10 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::POSITION: { - Property::Type type = property.GetType(); - if(type == Property::VECTOR2) + Vector3 position; + if(property.Get(position)) { - Vector2 position = property.Get(); - actor.SetPosition(Vector3(position.x, position.y, 0.0f)); - } - else if(type == Property::VECTOR3) - { - actor.SetPosition(property.Get()); + actor.SetPosition(position); } break; } @@ -318,15 +300,11 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property case Dali::Actor::Property::COLOR: { - Property::Type type = property.GetType(); - if(type == Property::VECTOR3) - { - Vector3 color = property.Get(); - actor.SetColor(Vector4(color.r, color.g, color.b, 1.0f)); - } - else if(type == Property::VECTOR4) + Vector4 color; + if(property.Get(color)) { - actor.SetColor(property.Get()); + color.a = (property.GetType() == Property::VECTOR4) ? color.a : 1.0f; + actor.SetColor(color); } break; }