2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/common/property-notification-impl.h>
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/public-api/math/vector2.h>
23 #include <dali/public-api/math/radian.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/internal/event/common/property-notification-manager.h>
26 #include <dali/internal/event/common/proxy-object.h>
27 #include <dali/internal/event/common/stage-impl.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/update/common/scene-graph-property-notification.h>
30 #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 = Stage::GetCurrent()->GetPropertyNotificationManager();
52 PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
53 propertyNotificationManager,
58 return propertyNotification;
61 PropertyNotification::PropertyNotification(UpdateManager& updateManager,
62 PropertyNotificationManager& propertyNotificationManager,
65 const Dali::PropertyCondition& condition)
66 : mUpdateManager(updateManager),
67 mPropertyNotification(NULL),
68 mPropertyNotificationManager(propertyNotificationManager),
69 mProxyPropertyIndex(target.propertyIndex),
70 mPropertyType(Property::NONE),
71 mComponentIndex(componentIndex),
72 mCondition(condition),
73 mNotifyMode(Dali::PropertyNotification::NotifyOnTrue),
76 // Set condition arguments (as simple vector of floats)
77 PropertyCondition::ArgumentContainer arguments = GetImplementation(condition).arguments;
78 PropertyCondition::ArgumentConstIter iter = arguments.begin();
80 while( iter != arguments.end() )
82 const Property::Value& value = *iter;
84 value.Get(floatValue);
86 mRawConditionArgs.PushBack( floatValue );
90 // Observe target proxy and create/destroy notification scene object accordingly.
91 mProxy = dynamic_cast<ProxyObject*>( &GetImplementation(target.object) );
94 mPropertyType = mProxy->GetPropertyType(mProxyPropertyIndex);
96 int internalComponentIndex = mProxy->GetPropertyComponentIndex(mProxyPropertyIndex);
97 if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
99 // override the one passed in
100 mComponentIndex = internalComponentIndex;
102 if(mComponentIndex != Property::INVALID_COMPONENT_INDEX)
104 Property::Type type = mProxy->GetPropertyType(mProxyPropertyIndex);
105 if( type == Property::VECTOR2
106 || type == Property::VECTOR3
107 || type == Property::VECTOR4 )
109 mPropertyType = Property::FLOAT;
113 // Check if target scene-object already present, and if so create our notification
115 const SceneGraph::PropertyOwner* object = mProxy->GetSceneObject();
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::PropertyNotifySignalV2& 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(mProxy);
182 Property::Index PropertyNotification::GetTargetProperty() const
184 return mProxyPropertyIndex;
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 DALI_ASSERT_DEBUG( mPropertyNotification == NULL );
215 // Create a new PropertyNotification, temporarily owned
216 SceneGraph::PropertyNotification* propertyNotification = SceneGraph::PropertyNotification::New( *mProxy,
220 GetImplementation(mCondition).type,
223 // Keep a const pointer to the PropertyNotification.
224 mPropertyNotification = propertyNotification;
226 // Transfer scene object ownership to the update manager through a message
227 AddPropertyNotificationMessage( mUpdateManager, propertyNotification );
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