X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Factors%2Factor-impl.cpp;h=decf85af6970808b9a01422c51a37bea3b2803da;hb=a42d8f30cafd2c74a3146607f13ab6aa7ca0c3f6;hp=2eabd0cd7a97d211362e3f98a793a04e9932e0ae;hpb=36abf4a5826a00be95721dc8750540911bdb88f9;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 2eabd0c..decf85a 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.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. @@ -37,12 +37,12 @@ #include +#include #include #include #include #include #include -#include #include #include #include @@ -51,7 +51,9 @@ #include #include #include +#include #include +#include #include using Dali::Internal::SceneGraph::AnimatableProperty; @@ -144,8 +146,10 @@ DALI_PROPERTY("keyboardFocusable", BOOLEAN, true, false, false, Dali::Actor::Pro DALI_PROPERTY("siblingOrder", INTEGER, true, false, false, Dali::DevelActor::Property::SIBLING_ORDER) DALI_PROPERTY("updateSizeHint", VECTOR2, true, false, false, Dali::DevelActor::Property::UPDATE_SIZE_HINT) DALI_PROPERTY("captureAllTouchAfterStart", BOOLEAN, true, false, false, Dali::DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START) -DALI_PROPERTY("touchArea", VECTOR2, true, false, false, Dali::DevelActor::Property::TOUCH_AREA) +DALI_PROPERTY("touchAreaOffset", RECTANGLE, true, false, false, Dali::DevelActor::Property::TOUCH_AREA_OFFSET) DALI_PROPERTY("blendEquation", INTEGER, true, false, false, Dali::DevelActor::Property::BLEND_EQUATION) +DALI_PROPERTY("touchFocusable", BOOLEAN, true, false, false, Dali::DevelActor::Property::TOUCH_FOCUSABLE) +DALI_PROPERTY("keyboardFocusableChildren", BOOLEAN, true, false, false, Dali::DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN) DALI_PROPERTY_TABLE_END(DEFAULT_ACTOR_PROPERTY_START_INDEX, ActorDefaultProperties) // Signals @@ -252,60 +256,6 @@ void EmitSignal(Actor& actor, Signal& signal, Param... params) } } -bool ScreenToLocalInternal( - const Matrix& viewMatrix, - const Matrix& projectionMatrix, - const Matrix& worldMatrix, - const Viewport& viewport, - const Vector3& currentSize, - float& localX, - float& localY, - float screenX, - float screenY) -{ - // Get the ModelView matrix - Matrix modelView; - Matrix::Multiply(modelView, worldMatrix, viewMatrix); - - // Calculate the inverted ModelViewProjection matrix; this will be used for 2 unprojects - Matrix invertedMvp(false /*don't init*/); - Matrix::Multiply(invertedMvp, modelView, projectionMatrix); - bool success = invertedMvp.Invert(); - - // Convert to GL coordinates - Vector4 screenPos(screenX - static_cast(viewport.x), static_cast(viewport.height) - screenY - static_cast(viewport.y), 0.f, 1.f); - - Vector4 nearPos; - if(success) - { - success = Unproject(screenPos, invertedMvp, static_cast(viewport.width), static_cast(viewport.height), nearPos); - } - - Vector4 farPos; - if(success) - { - screenPos.z = 1.0f; - success = Unproject(screenPos, invertedMvp, static_cast(viewport.width), static_cast(viewport.height), farPos); - } - - if(success) - { - Vector4 local; - if(XyPlaneIntersect(nearPos, farPos, local)) - { - Vector3 size = currentSize; - localX = local.x + size.x * 0.5f; - localY = local.y + size.y * 0.5f; - } - else - { - success = false; - } - } - - return success; -} - } // unnamed namespace ActorPtr Actor::New() @@ -333,12 +283,12 @@ const SceneGraph::Node* Actor::CreateNode() return node; } -void Actor::SetName(const std::string& name) +void Actor::SetName(std::string_view name) { - mName = name; + mName = ConstString(name); // ATTENTION: string for debug purposes is not thread safe. - DALI_LOG_SET_OBJECT_STRING(const_cast(&GetNode()), name); + DALI_LOG_SET_OBJECT_STRING(const_cast(&GetNode()), mName.GetCString()); } uint32_t Actor::GetId() const @@ -800,12 +750,12 @@ void Actor::SetSizeInternal(const Vector3& size) // check that we have a node AND the new size width, height or depth is at least a little bit different from the old one Vector3 currentSize = GetCurrentSize(); - if( ( fabsf( mTargetSize.width - size.width ) > Math::MACHINE_EPSILON_1 )|| - ( fabsf( mTargetSize.height- size.height ) > Math::MACHINE_EPSILON_1 )|| - ( fabsf( mTargetSize.depth - size.depth ) > Math::MACHINE_EPSILON_1 )|| - ( fabsf( mTargetSize.width - currentSize.width ) > Math::MACHINE_EPSILON_1 )|| - ( fabsf( mTargetSize.height- currentSize.height ) > Math::MACHINE_EPSILON_1 )|| - ( fabsf( mTargetSize.depth - currentSize.depth ) > Math::MACHINE_EPSILON_1 ) ) + if((fabsf(mTargetSize.width - size.width) > Math::MACHINE_EPSILON_1) || + (fabsf(mTargetSize.height - size.height) > Math::MACHINE_EPSILON_1) || + (fabsf(mTargetSize.depth - size.depth) > Math::MACHINE_EPSILON_1) || + (fabsf(mTargetSize.width - currentSize.width) > Math::MACHINE_EPSILON_1) || + (fabsf(mTargetSize.height - currentSize.height) > Math::MACHINE_EPSILON_1) || + (fabsf(mTargetSize.depth - currentSize.depth) > Math::MACHINE_EPSILON_1)) { mTargetSize = size; @@ -1036,7 +986,7 @@ uint32_t Actor::AddRenderer(Renderer& renderer) uint32_t index = static_cast(mRenderers->size()); // 4,294,967,295 renderers per actor RendererPtr rendererPtr = RendererPtr(&renderer); mRenderers->push_back(rendererPtr); - AttachRendererMessage(GetEventThreadServices(), GetNode(), renderer.GetRendererSceneObject()); + AttachRendererMessage(GetEventThreadServices().GetUpdateManager(), GetNode(), renderer.GetRendererSceneObject()); return index; } @@ -1116,6 +1066,16 @@ DevelBlendEquation::Type Actor::GetBlendEquation() const return mBlendEquation; } +void Actor::SetTransparent(bool transparent) +{ + SetTransparentMessage(GetEventThreadServices(), GetNode(), transparent); +} + +bool Actor::IsTransparent() const +{ + return GetNode().IsTransparent(); +} + void Actor::SetDrawMode(DrawMode::Type drawMode) { // this flag is not animatable so keep the value @@ -1127,54 +1087,17 @@ void Actor::SetDrawMode(DrawMode::Type drawMode) bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const { - // only valid when on-stage - if(mScene && OnScene()) - { - const RenderTaskList& taskList = mScene->GetRenderTaskList(); - - Vector2 converted(screenX, screenY); - - // do a reverse traversal of all lists (as the default onscreen one is typically the last one) - uint32_t taskCount = taskList.GetTaskCount(); - for(uint32_t i = taskCount; i > 0; --i) - { - RenderTaskPtr task = taskList.GetTask(i - 1); - if(ScreenToLocal(*task, localX, localY, screenX, screenY)) - { - // found a task where this conversion was ok so return - return true; - } - } - } - return false; + return mScene && OnScene() && ConvertScreenToLocalRenderTaskList(mScene->GetRenderTaskList(), GetNode().GetWorldMatrix(0), GetCurrentSize(), localX, localY, screenX, screenY); } bool Actor::ScreenToLocal(const RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const { - bool retval = false; - // only valid when on-stage - if(OnScene()) - { - CameraActor* camera = renderTask.GetCameraActor(); - if(camera) - { - Viewport viewport; - renderTask.GetViewport(viewport); - - // need to translate coordinates to render tasks coordinate space - Vector2 converted(screenX, screenY); - if(renderTask.TranslateCoordinates(converted)) - { - retval = ScreenToLocal(camera->GetViewMatrix(), camera->GetProjectionMatrix(), viewport, localX, localY, converted.x, converted.y); - } - } - } - return retval; + return OnScene() && ConvertScreenToLocalRenderTask(renderTask, GetNode().GetWorldMatrix(0), GetCurrentSize(), localX, localY, screenX, screenY); } bool Actor::ScreenToLocal(const Matrix& viewMatrix, const Matrix& projectionMatrix, const Viewport& viewport, float& localX, float& localY, float screenX, float screenY) const { - return OnScene() && ScreenToLocalInternal(viewMatrix, projectionMatrix, GetNode().GetWorldMatrix(0), viewport, GetCurrentSize(), localX, localY, screenX, screenY); + return OnScene() && ConvertScreenToLocal(viewMatrix, projectionMatrix, GetNode().GetWorldMatrix(0), GetCurrentSize(), viewport, localX, localY, screenX, screenY); } ActorGestureData& Actor::GetGestureData() @@ -1319,7 +1242,7 @@ Actor::Actor(DerivedType derivedType, const SceneGraph::Node& node) mTargetPosition(Vector3::ZERO), mTargetScale(Vector3::ONE), mAnimatedSize(Vector3::ZERO), - mTouchArea(Vector2::ZERO), + mTouchAreaOffset(0, 0, 0, 0), mName(), mSortedDepth(0u), mDepth(0u), @@ -1330,6 +1253,8 @@ Actor::Actor(DerivedType derivedType, const SceneGraph::Node& node) mSensitive(true), mLeaveRequired(false), mKeyboardFocusable(false), + mKeyboardFocusableChildren(true), + mTouchFocusable(false), mOnSceneSignalled(false), mInsideOnSizeSet(false), mInheritPosition(true), @@ -1339,12 +1264,13 @@ Actor::Actor(DerivedType derivedType, const SceneGraph::Node& node) mVisible(true), mInheritLayoutDirection(true), mCaptureAllTouchAfterStart(false), + mIsBlendEquationSet(false), + mNeedGesturePropagation(false), mLayoutDirection(LayoutDirection::LEFT_TO_RIGHT), mDrawMode(DrawMode::NORMAL), mColorMode(Node::DEFAULT_COLOR_MODE), mClippingMode(ClippingMode::DISABLED), - mBlendEquation(DevelBlendEquation::ADD), - mIsBlendEquationSet(false) + mBlendEquation(DevelBlendEquation::ADD) { } @@ -1385,14 +1311,31 @@ Actor::~Actor() delete mRelayoutData; } -void Actor::Add(Actor& child) +void Actor::Add(Actor& child, bool notify) { - mParentImpl.Add(child); + mParentImpl.Add(child, notify); } -void Actor::Remove(Actor& child) +void Actor::Remove(Actor& child, bool notify) { - mParentImpl.Remove(child); + mParentImpl.Remove(child, notify); +} + +void Actor::SwitchParent(Actor& newParent) +{ + if(this == &newParent) + { + DALI_LOG_ERROR("Cannot add actor to itself"); + return; + } + + if(!this->OnScene() || !newParent.OnScene()) + { + DALI_LOG_ERROR("Both of current parent and new parent must be on Scene"); + return; + } + + newParent.Add(*this, false); } uint32_t Actor::GetChildCount() const @@ -1410,7 +1353,7 @@ ActorContainer& Actor::GetChildrenInternal() return mParentImpl.GetChildrenInternal(); } -ActorPtr Actor::FindChildByName(const std::string& actorName) +ActorPtr Actor::FindChildByName(ConstString actorName) { return mParentImpl.FindChildByName(actorName); } @@ -1425,7 +1368,7 @@ void Actor::UnparentChildren() mParentImpl.UnparentChildren(); } -void Actor::ConnectToScene(uint32_t parentDepth) +void Actor::ConnectToScene(uint32_t parentDepth, bool notify) { // This container is used instead of walking the Actor hierarchy. // It protects us when the Actor hierarchy is modified during OnSceneConnectionExternal callbacks. @@ -1442,7 +1385,7 @@ void Actor::ConnectToScene(uint32_t parentDepth) // Notify applications about the newly connected actors. for(const auto& actor : connectionList) { - actor->NotifyStageConnection(); + actor->NotifyStageConnection(notify); } RelayoutRequest(); @@ -1494,19 +1437,22 @@ void Actor::ConnectToSceneGraph() OnSceneObjectAdd(); } -void Actor::NotifyStageConnection() +void Actor::NotifyStageConnection(bool notify) { // Actors can be removed (in a callback), before the on-stage stage is reported. // The actor may also have been reparented, in which case mOnSceneSignalled will be true. if(OnScene() && !mOnSceneSignalled) { - // Notification for external (CustomActor) derived classes - OnSceneConnectionExternal(mDepth); - - if(!mOnSceneSignal.Empty()) + if(notify) { - Dali::Actor handle(this); - mOnSceneSignal.Emit(handle); + // Notification for external (CustomActor) derived classes + OnSceneConnectionExternal(mDepth); + + if(!mOnSceneSignal.Empty()) + { + Dali::Actor handle(this); + mOnSceneSignal.Emit(handle); + } } // Guard against Remove during callbacks @@ -1517,7 +1463,7 @@ void Actor::NotifyStageConnection() } } -void Actor::DisconnectFromStage() +void Actor::DisconnectFromStage(bool notify) { // This container is used instead of walking the Actor hierachy. // It protects us when the Actor hierachy is modified during OnSceneDisconnectionExternal callbacks. @@ -1534,7 +1480,7 @@ void Actor::DisconnectFromStage() // Notify applications about the newly disconnected actors. for(const auto& actor : disconnectionList) { - actor->NotifyStageDisconnection(); + actor->NotifyStageDisconnection(notify); } } @@ -1571,20 +1517,23 @@ void Actor::DisconnectFromSceneGraph() OnSceneObjectRemove(); } -void Actor::NotifyStageDisconnection() +void Actor::NotifyStageDisconnection(bool notify) { // Actors can be added (in a callback), before the off-stage state is reported. // Also if the actor was added & removed before mOnSceneSignalled was set, then we don't notify here. // only do this step if there is a stage, i.e. Core is not being shut down if(EventThreadServices::IsCoreRunning() && !OnScene() && mOnSceneSignalled) { - // Notification for external (CustomeActor) derived classes - OnSceneDisconnectionExternal(); - - if(!mOffSceneSignal.Empty()) + if(notify) { - Dali::Actor handle(this); - mOffSceneSignal.Emit(handle); + // Notification for external (CustomeActor) derived classes + OnSceneDisconnectionExternal(); + + if(!mOffSceneSignal.Empty()) + { + Dali::Actor handle(this); + mOffSceneSignal.Emit(handle); + } } // Guard against Add during callbacks @@ -1727,6 +1676,11 @@ int32_t Actor::GetPropertyComponentIndex(Property::Index index) const return componentIndex; } +const SceneGraph::Node& Actor::GetNode() const +{ + return *static_cast(mUpdateObject); +} + void Actor::Raise() { if(mParent) @@ -1799,7 +1753,7 @@ void Actor::LowerBelow(Internal::Actor& target) } } -void Actor::SetParent(ActorParent* parent) +void Actor::SetParent(ActorParent* parent, bool notify) { if(parent) { @@ -1813,7 +1767,7 @@ void Actor::SetParent(ActorParent* parent) parentActor->OnScene()) { // Instruct each actor to create a corresponding node in the scene graph - ConnectToScene(parentActor->GetHierarchyDepth()); + ConnectToScene(parentActor->GetHierarchyDepth(), notify); } // Resolve the name and index for the child properties if any @@ -1832,7 +1786,7 @@ void Actor::SetParent(ActorParent* parent) DisconnectNodeMessage(GetEventThreadServices().GetUpdateManager(), GetNode()); // Instruct each actor to discard pointers to the scene-graph - DisconnectFromStage(); + DisconnectFromStage(notify); } mScene = nullptr; @@ -1871,6 +1825,16 @@ Rect<> Actor::CalculateScreenExtents() const return {position.x, position.y, size.x, size.y}; } +void Actor::SetNeedGesturePropagation(bool propagation) +{ + mNeedGesturePropagation = propagation; +} + +bool Actor::NeedGesturePropagation() +{ + return mNeedGesturePropagation; +} + bool Actor::GetCachedPropertyValue(Property::Index index, Property::Value& value) const { return PropertyHandler::GetCachedPropertyValue(*this, index, value);