1 #ifndef DALI_INTERNAL_ACTOR_OBSERVER_H
2 #define DALI_INTERNAL_ACTOR_OBSERVER_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/signals/callback.h>
23 #include <dali/internal/event/common/object-impl.h>
34 * Stores an actor pointer and connects/disconnects to any required signals appropriately when set/unset.
36 struct ActorObserver : public Object::Observer
40 // Construction & Destruction
48 * Constructor with a callback which is called when the observed actor is removed from the scene.
50 * The callback should have the following signature:
52 * void MyCallback( Actor* actor );
54 * Where actor is a pointer to the object that has been removed from the scene.
56 * @param[in] callback The callback to connect to.
58 * @note Ownership of callback is passed onto this class.
60 ActorObserver( CallbackBase* callback );
63 * Non virtual destructor
65 ~ActorObserver() override;
72 * @param[in] other The object to move the data from
74 * @note The other's actor is appropriately disconnected.
75 * @note Ownership of callback is passed onto this class.
77 ActorObserver( ActorObserver&& other );
80 * Move assignment operator.
82 * @param[in] other The object to move the data from
84 * @note The other's actor is appropriately disconnected.
85 * @note Ownership of callback is passed onto this class.
87 ActorObserver& operator=( ActorObserver&& other );
91 ActorObserver( const ActorObserver& ) = delete; ///< Deleted copy constructor.
92 ActorObserver& operator=( const ActorObserver& ) = delete; ///< Deleted copy assignment operator.
97 * Return the stored Actor pointer.
98 * @return The Actor pointer.
99 * @note Returns nullptr while the observed actor is not on the scene.
101 Actor* GetActor() const;
104 * Assignment operator.
105 * This disconnects the required signals from the currently set actor and connects to the required
106 * signals for the the actor specified (if set).
108 void SetActor( Actor* actor );
111 * Resets the set actor and disconnects any connected signals.
118 * This will be called if an actor is added to the scene.
119 * @param[in] object The object object.
120 * @see Object::Observer::SceneObjectAdded()
122 void SceneObjectAdded( Object& object ) override;
125 * This will be called when the actor is removed from the scene.
126 * @param[in] object The object object.
127 * @see Object::Observer::SceneObjectRemoved()
129 void SceneObjectRemoved( Object& object ) override;
132 * This will be called when the actor is destroyed. We should clear the actor.
133 * No need to stop observing as the object is being destroyed anyway.
134 * @see Object::Observer::ObjectDestroyed()
136 void ObjectDestroyed( Object& object ) override;
139 Actor* mActor; ///< Raw pointer to an Actor.
140 bool mActorDisconnected; ///< Indicates whether the actor has been disconnected from the scene
141 CallbackBase* mRemoveCallback; ///< Callback to call when the observed actor is removed from the scene
144 } // namespace Internal
148 #endif // DALI_INTERNAL_ACTOR_OBSERVER_H