2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/property-notification-impl.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/math/radian.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/common/property-notification-manager.h>
28 #include <dali/internal/event/common/object-impl.h>
29 #include <dali/internal/event/common/stage-impl.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/internal/update/common/scene-graph-property-notification.h>
32 #include <dali/internal/event/common/thread-local-storage.h>
34 using Dali::Internal::SceneGraph::UpdateManager;
42 PropertyNotificationPtr PropertyNotification::New(Property& target,
44 const Dali::PropertyCondition& condition)
46 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
48 UpdateManager& updateManager = tls.GetUpdateManager();
50 PropertyNotificationManager& propertyNotificationManager = tls.GetPropertyNotificationManager();
51 PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
52 propertyNotificationManager,
56 return propertyNotification;
59 PropertyNotification::PropertyNotification( UpdateManager& updateManager,
60 PropertyNotificationManager& propertyNotificationManager,
63 const Dali::PropertyCondition& condition )
64 : mUpdateManager( updateManager ),
65 mPropertyNotification( NULL ),
66 mPropertyNotificationManager( propertyNotificationManager ),
67 mObjectPropertyIndex( target.propertyIndex ),
68 mPropertyType( Property::NONE ),
69 mComponentIndex( componentIndex ),
70 mCondition( condition ),
71 mNotifyMode( Dali::PropertyNotification::NotifyOnTrue ),
72 mNotifyResult( false ),
75 const Internal::PropertyCondition& conditionImpl = GetImplementation( condition );
77 Dali::Vector<float>::SizeType count = conditionImpl.arguments.Count();
78 for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
80 mRawConditionArgs.PushBack( conditionImpl.arguments[ index ] );
83 // Observe target object and create/destroy notification scene object accordingly.
84 mObject = dynamic_cast<Object*>( &GetImplementation(target.object) );
87 mPropertyType = mObject->GetPropertyType(mObjectPropertyIndex);
89 int internalComponentIndex = mObject->GetPropertyComponentIndex(mObjectPropertyIndex);
90 if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
92 // override the one passed in
93 mComponentIndex = internalComponentIndex;
95 if(mComponentIndex != Property::INVALID_COMPONENT_INDEX)
97 Property::Type type = mObject->GetPropertyType(mObjectPropertyIndex);
98 if( type == Property::VECTOR2
99 || type == Property::VECTOR3
100 || type == Property::VECTOR4 )
102 mPropertyType = Property::FLOAT;
106 // In Size Property case, swapping components occurs sometimes.
107 // To cover swapping components, previous and current components should be compared.
108 if( mObjectPropertyIndex == Dali::Actor::Property::SIZE
109 && mObject->GetPropertyType(mObjectPropertyIndex) == Property::VECTOR3 )
112 for( int i = 0; i < 3; ++i )
114 mRawConditionArgs.PushBack( 0.0f );
118 // all objects always have scene object
122 // Connect to the property notification manager
123 mPropertyNotificationManager.PropertyNotificationCreated( *this );
126 PropertyNotification::~PropertyNotification()
130 // Guard to disallow use of PropertyNotificationManager after Core has been destroyed
131 if ( Stage::IsInstalled() )
133 // Disconnect from the property notification manager
134 mPropertyNotificationManager.PropertyNotificationDestroyed( *this );
138 Dali::PropertyNotifySignalType& PropertyNotification::NotifySignal()
140 return mNotifySignal;
143 void PropertyNotification::EmitSignalNotify()
145 Dali::PropertyNotification source(this);
147 mNotifySignal.Emit( source );
150 void PropertyNotification::Enable()
155 void PropertyNotification::Disable()
157 // Guard to allow handle destruction after Core has been destroyed
158 if ( Stage::IsInstalled() )
160 // Stop scene-graph from monitoring the target's properties.
161 DestroySceneObject();
165 void PropertyNotification::SetNotifyResult( bool result )
167 mNotifyResult = result;
170 const Dali::PropertyCondition& PropertyNotification::GetCondition() const
175 Dali::Handle PropertyNotification::GetTarget() const
177 Dali::Handle handle(mObject);
182 Property::Index PropertyNotification::GetTargetProperty() const
184 return mObjectPropertyIndex;
187 void PropertyNotification::SetNotifyMode( NotifyMode mode )
190 if( mPropertyNotification )
192 PropertyNotificationSetNotifyModeMessage( mUpdateManager, mPropertyNotification, mode );
196 PropertyNotification::NotifyMode PropertyNotification::GetNotifyMode()
201 bool PropertyNotification::GetNotifyResult() const
203 return mNotifyResult;
206 bool PropertyNotification::CompareSceneObject( const SceneGraph::PropertyNotification* sceneObject )
208 return sceneObject && sceneObject == mPropertyNotification;
211 void PropertyNotification::CreateSceneObject()
213 // this method can be called from constructor and on stage connection
214 if( !mPropertyNotification )
216 // Create a new PropertyNotification, keep a const pointer to it
217 mPropertyNotification = SceneGraph::PropertyNotification::New( *mObject,
218 mObjectPropertyIndex,
221 GetImplementation( mCondition ).type,
225 OwnerPointer< SceneGraph::PropertyNotification > transferOwnership( const_cast<SceneGraph::PropertyNotification*>( mPropertyNotification ) );
226 AddPropertyNotificationMessage( mUpdateManager, transferOwnership );
230 void PropertyNotification::DestroySceneObject()
232 if ( mPropertyNotification != NULL )
234 // Remove PropertyNotification using a message to the update manager
235 RemovePropertyNotificationMessage( mUpdateManager, *mPropertyNotification );
236 mPropertyNotification = NULL;
240 } // namespace Internal