2 * Copyright (c) 2015 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 = Stage::GetCurrent()->GetPropertyNotificationManager();
51 PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
52 propertyNotificationManager,
57 return propertyNotification;
60 PropertyNotification::PropertyNotification( UpdateManager& updateManager,
61 PropertyNotificationManager& propertyNotificationManager,
64 const Dali::PropertyCondition& condition )
65 : mUpdateManager( updateManager ),
66 mPropertyNotification( NULL ),
67 mPropertyNotificationManager( propertyNotificationManager ),
68 mObjectPropertyIndex( target.propertyIndex ),
69 mPropertyType( Property::NONE ),
70 mComponentIndex( componentIndex ),
71 mCondition( condition ),
72 mNotifyMode( Dali::PropertyNotification::NotifyOnTrue ),
73 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 // Check if target scene-object already present, and if so create our notification
108 const SceneGraph::PropertyOwner* object = mObject->GetSceneObject();
115 // Connect to the property notification manager
116 mPropertyNotificationManager.PropertyNotificationCreated( *this );
119 PropertyNotification::~PropertyNotification()
123 // Guard to disallow use of PropertyNotificationManager after Core has been destroyed
124 if ( Stage::IsInstalled() )
126 // Disconnect from the property notification manager
127 mPropertyNotificationManager.PropertyNotificationDestroyed( *this );
131 Dali::PropertyNotifySignalType& PropertyNotification::NotifySignal()
133 return mNotifySignal;
136 void PropertyNotification::EmitSignalNotify()
138 Dali::PropertyNotification source(this);
140 mNotifySignal.Emit( source );
143 void PropertyNotification::Enable()
148 void PropertyNotification::Disable()
150 // Guard to allow handle destruction after Core has been destroyed
151 if ( Stage::IsInstalled() )
153 // Stop scene-graph from monitoring the target's properties.
154 DestroySceneObject();
158 void PropertyNotification::SetNotifyResult( bool result )
160 mNotifyResult = result;
163 const Dali::PropertyCondition& PropertyNotification::GetCondition() const
168 Dali::Handle PropertyNotification::GetTarget() const
170 Dali::Handle handle(mObject);
175 Property::Index PropertyNotification::GetTargetProperty() const
177 return mObjectPropertyIndex;
180 void PropertyNotification::SetNotifyMode( NotifyMode mode )
183 if( mPropertyNotification )
185 PropertyNotificationSetNotifyModeMessage( mUpdateManager, mPropertyNotification, mode );
189 PropertyNotification::NotifyMode PropertyNotification::GetNotifyMode()
194 bool PropertyNotification::GetNotifyResult() const
196 return mNotifyResult;
199 bool PropertyNotification::CompareSceneObject( const SceneGraph::PropertyNotification* sceneObject )
201 return sceneObject && sceneObject == mPropertyNotification;
204 void PropertyNotification::CreateSceneObject()
206 // this method can be called from constructor and on stage connection
207 if( !mPropertyNotification )
209 // Create a new PropertyNotification, temporarily owned
210 SceneGraph::PropertyNotification* propertyNotification = SceneGraph::PropertyNotification::New( *mObject,
211 mObjectPropertyIndex,
214 GetImplementation(mCondition).type,
217 // Keep a const pointer to the PropertyNotification.
218 mPropertyNotification = propertyNotification;
220 // Transfer scene object ownership to the update manager through a message
221 AddPropertyNotificationMessage( mUpdateManager, propertyNotification );
225 void PropertyNotification::DestroySceneObject()
227 if ( mPropertyNotification != NULL )
229 // Remove PropertyNotification using a message to the update manager
230 RemovePropertyNotificationMessage( mUpdateManager, *mPropertyNotification );
231 mPropertyNotification = NULL;
235 } // namespace Internal