2 * Copyright (c) 2014 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/proxy-object.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>
35 using Dali::Internal::SceneGraph::UpdateManager;
43 PropertyNotificationPtr PropertyNotification::New(Property& target,
45 const Dali::PropertyCondition& condition)
47 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
49 UpdateManager& updateManager = tls.GetUpdateManager();
51 PropertyNotificationManager& propertyNotificationManager = Stage::GetCurrent()->GetPropertyNotificationManager();
53 PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
54 propertyNotificationManager,
59 return propertyNotification;
62 PropertyNotification::PropertyNotification(UpdateManager& updateManager,
63 PropertyNotificationManager& propertyNotificationManager,
66 const Dali::PropertyCondition& condition)
67 : mUpdateManager(updateManager),
68 mPropertyNotification(NULL),
69 mPropertyNotificationManager(propertyNotificationManager),
70 mProxyPropertyIndex(target.propertyIndex),
71 mPropertyType(Property::NONE),
72 mComponentIndex(componentIndex),
73 mCondition(condition),
74 mNotifyMode(Dali::PropertyNotification::NotifyOnTrue),
77 // Set condition arguments (as simple vector of floats)
78 PropertyCondition::ArgumentContainer arguments = GetImplementation(condition).arguments;
79 PropertyCondition::ArgumentConstIter iter = arguments.begin();
81 while( iter != arguments.end() )
83 const Property::Value& value = *iter;
85 value.Get(floatValue);
87 mRawConditionArgs.PushBack( floatValue );
91 // Observe target proxy and create/destroy notification scene object accordingly.
92 mProxy = dynamic_cast<ProxyObject*>( &GetImplementation(target.object) );
95 mPropertyType = mProxy->GetPropertyType(mProxyPropertyIndex);
97 int internalComponentIndex = mProxy->GetPropertyComponentIndex(mProxyPropertyIndex);
98 if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
100 // override the one passed in
101 mComponentIndex = internalComponentIndex;
103 if(mComponentIndex != Property::INVALID_COMPONENT_INDEX)
105 Property::Type type = mProxy->GetPropertyType(mProxyPropertyIndex);
106 if( type == Property::VECTOR2
107 || type == Property::VECTOR3
108 || type == Property::VECTOR4 )
110 mPropertyType = Property::FLOAT;
114 // Check if target scene-object already present, and if so create our notification
116 const SceneGraph::PropertyOwner* object = mProxy->GetSceneObject();
123 // Connect to the property notification manager
124 mPropertyNotificationManager.PropertyNotificationCreated( *this );
127 PropertyNotification::~PropertyNotification()
131 // Guard to disallow use of PropertyNotificationManager after Core has been destroyed
132 if ( Stage::IsInstalled() )
134 // Disconnect from the property notification manager
135 mPropertyNotificationManager.PropertyNotificationDestroyed( *this );
139 Dali::PropertyNotifySignalV2& PropertyNotification::NotifySignal()
141 return mNotifySignal;
144 void PropertyNotification::EmitSignalNotify()
146 Dali::PropertyNotification source(this);
148 mNotifySignal.Emit( source );
151 void PropertyNotification::Enable()
156 void PropertyNotification::Disable()
158 // Guard to allow handle destruction after Core has been destroyed
159 if ( Stage::IsInstalled() )
161 // Stop scene-graph from monitoring the target's properties.
162 DestroySceneObject();
166 void PropertyNotification::SetNotifyResult( bool result )
168 mNotifyResult = result;
171 const Dali::PropertyCondition& PropertyNotification::GetCondition() const
176 Dali::Handle PropertyNotification::GetTarget() const
178 Dali::Handle handle(mProxy);
183 Property::Index PropertyNotification::GetTargetProperty() const
185 return mProxyPropertyIndex;
188 void PropertyNotification::SetNotifyMode( NotifyMode mode )
191 if( mPropertyNotification )
193 PropertyNotificationSetNotifyModeMessage( mUpdateManager, mPropertyNotification, mode );
197 PropertyNotification::NotifyMode PropertyNotification::GetNotifyMode()
202 bool PropertyNotification::GetNotifyResult() const
204 return mNotifyResult;
207 bool PropertyNotification::CompareSceneObject( const SceneGraph::PropertyNotification* sceneObject )
209 return sceneObject && sceneObject == mPropertyNotification;
212 void PropertyNotification::CreateSceneObject()
214 DALI_ASSERT_DEBUG( mPropertyNotification == NULL );
216 // Create a new PropertyNotification, temporarily owned
217 SceneGraph::PropertyNotification* propertyNotification = SceneGraph::PropertyNotification::New( *mProxy,
221 GetImplementation(mCondition).type,
224 // Keep a const pointer to the PropertyNotification.
225 mPropertyNotification = propertyNotification;
227 // Transfer scene object ownership to the update manager through a message
228 AddPropertyNotificationMessage( mUpdateManager, propertyNotification );
231 void PropertyNotification::DestroySceneObject()
233 if ( mPropertyNotification != NULL )
235 // Remove PropertyNotification using a message to the update manager
236 RemovePropertyNotificationMessage( mUpdateManager, *mPropertyNotification );
237 mPropertyNotification = NULL;
241 } // namespace Internal