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/internal/event/actors/actor-impl.h>
26 #include <dali/internal/event/common/property-notification-manager.h>
27 #include <dali/internal/event/common/object-impl.h>
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/update/manager/update-manager.h>
30 #include <dali/internal/update/common/scene-graph-property-notification.h>
31 #include <dali/internal/event/common/thread-local-storage.h>
33 using Dali::Internal::SceneGraph::UpdateManager;
41 PropertyNotificationPtr PropertyNotification::New(Property& target,
43 const Dali::PropertyCondition& condition)
45 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
47 UpdateManager& updateManager = tls.GetUpdateManager();
49 PropertyNotificationManager& propertyNotificationManager = tls.GetPropertyNotificationManager();
50 PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
51 propertyNotificationManager,
55 return propertyNotification;
58 PropertyNotification::PropertyNotification( UpdateManager& updateManager,
59 PropertyNotificationManager& propertyNotificationManager,
62 const Dali::PropertyCondition& condition )
63 : mUpdateManager( updateManager ),
64 mPropertyNotification( NULL ),
65 mPropertyNotificationManager( propertyNotificationManager ),
66 mObjectPropertyIndex( target.propertyIndex ),
67 mPropertyType( Property::NONE ),
68 mComponentIndex( componentIndex ),
69 mCondition( condition ),
70 mNotifyMode( Dali::PropertyNotification::NotifyOnTrue ),
71 mNotifyResult( false )
73 const Internal::PropertyCondition& conditionImpl = GetImplementation( condition );
75 Dali::Vector<float>::SizeType count = conditionImpl.arguments.Count();
76 for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
78 mRawConditionArgs.PushBack( conditionImpl.arguments[ index ] );
81 // Observe target object and create/destroy notification scene object accordingly.
82 mObject = dynamic_cast<Object*>( &GetImplementation(target.object) );
85 mPropertyType = mObject->GetPropertyType(mObjectPropertyIndex);
87 int internalComponentIndex = mObject->GetPropertyComponentIndex(mObjectPropertyIndex);
88 if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
90 // override the one passed in
91 mComponentIndex = internalComponentIndex;
93 if(mComponentIndex != Property::INVALID_COMPONENT_INDEX)
95 Property::Type type = mObject->GetPropertyType(mObjectPropertyIndex);
96 if( type == Property::VECTOR2
97 || type == Property::VECTOR3
98 || type == Property::VECTOR4 )
100 mPropertyType = Property::FLOAT;
104 // all objects always have scene object
108 // Connect to the property notification manager
109 mPropertyNotificationManager.PropertyNotificationCreated( *this );
112 PropertyNotification::~PropertyNotification()
116 // Guard to disallow use of PropertyNotificationManager after Core has been destroyed
117 if ( Stage::IsInstalled() )
119 // Disconnect from the property notification manager
120 mPropertyNotificationManager.PropertyNotificationDestroyed( *this );
124 Dali::PropertyNotifySignalType& PropertyNotification::NotifySignal()
126 return mNotifySignal;
129 void PropertyNotification::EmitSignalNotify()
131 Dali::PropertyNotification source(this);
133 mNotifySignal.Emit( source );
136 void PropertyNotification::Enable()
141 void PropertyNotification::Disable()
143 // Guard to allow handle destruction after Core has been destroyed
144 if ( Stage::IsInstalled() )
146 // Stop scene-graph from monitoring the target's properties.
147 DestroySceneObject();
151 void PropertyNotification::SetNotifyResult( bool result )
153 mNotifyResult = result;
156 const Dali::PropertyCondition& PropertyNotification::GetCondition() const
161 Dali::Handle PropertyNotification::GetTarget() const
163 Dali::Handle handle(mObject);
168 Property::Index PropertyNotification::GetTargetProperty() const
170 return mObjectPropertyIndex;
173 void PropertyNotification::SetNotifyMode( NotifyMode mode )
176 if( mPropertyNotification )
178 PropertyNotificationSetNotifyModeMessage( mUpdateManager, mPropertyNotification, mode );
182 PropertyNotification::NotifyMode PropertyNotification::GetNotifyMode()
187 bool PropertyNotification::GetNotifyResult() const
189 return mNotifyResult;
192 bool PropertyNotification::CompareSceneObject( const SceneGraph::PropertyNotification* sceneObject )
194 return sceneObject && sceneObject == mPropertyNotification;
197 void PropertyNotification::CreateSceneObject()
199 // this method can be called from constructor and on stage connection
200 if( !mPropertyNotification )
202 // Create a new PropertyNotification, keep a const pointer to it
203 mPropertyNotification = SceneGraph::PropertyNotification::New( *mObject,
204 mObjectPropertyIndex,
207 GetImplementation( mCondition ).type,
210 OwnerPointer< SceneGraph::PropertyNotification > transferOwnership( const_cast<SceneGraph::PropertyNotification*>( mPropertyNotification ) );
211 AddPropertyNotificationMessage( mUpdateManager, transferOwnership );
215 void PropertyNotification::DestroySceneObject()
217 if ( mPropertyNotification != NULL )
219 // Remove PropertyNotification using a message to the update manager
220 RemovePropertyNotificationMessage( mUpdateManager, *mPropertyNotification );
221 mPropertyNotification = NULL;
225 } // namespace Internal