0ac5c73ceeb5488e01e501b63fa6debfbe565049
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / fade-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_FADE_H
2 #define DALI_TOOLKIT_INTERNAL_FADE_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/transition/transition-base-impl.h>
23 #include <dali-toolkit/public-api/controls/control.h>
24 #include <dali-toolkit/public-api/transition/fade.h>
25
26 // EXTERNAL INCLUDES
27 #include <dali/public-api/object/weak-handle.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35 using FadePtr = IntrusivePtr<Fade>;
36
37 class Fade : public TransitionBase
38 {
39 public:
40   /**
41    * @brief Create a new Fade object.
42    * @param[in] control A control of this transition.
43    * @param[in] opacity opacity value the control Opacity property will be changed from/to.
44    * @param[in] timePeriod The duration of the animation.
45    * @return A smart-pointer to the newly allocated Fade.
46    */
47   static FadePtr New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod);
48
49 protected:
50   /**
51    * @copydoc Dali::Toolkit::Fade::OnPlay()
52    */
53   void OnPlay() override;
54
55 protected:
56   /**
57    * @brief Construct a new Fade.
58    */
59   Fade(Dali::Toolkit::Control control,
60        float                  opacity,
61        TimePeriod             timePeriod);
62
63   /**
64    * @brief A reference counted object may only be deleted by calling Unreference()
65    */
66   ~Fade() override;
67
68 private:
69   // Undefined
70   Fade(const Fade&);
71
72   // Undefined
73   Fade& operator=(const Fade& rhs);
74
75 private:
76   WeakHandle<Dali::Toolkit::Control> mTargetControl;
77   float mOpacity;
78 };
79
80 } // namespace Internal
81
82 // Helpers for public-api forwarding methods
83
84 inline Internal::Fade& GetImplementation(Dali::Toolkit::Fade& fade)
85 {
86   DALI_ASSERT_ALWAYS(fade && "Fade handle is empty");
87
88   BaseObject& handle = fade.GetBaseObject();
89
90   return static_cast<Internal::Fade&>(handle);
91 }
92
93 inline const Internal::Fade& GetImplementation(const Dali::Toolkit::Fade& fade)
94 {
95   DALI_ASSERT_ALWAYS(fade && "Fade handle is empty");
96
97   const BaseObject& handle = fade.GetBaseObject();
98
99   return static_cast<const Internal::Fade&>(handle);
100 }
101
102 } // namespace Toolkit
103
104 } // namespace Dali
105
106 #endif // DALI_TOOLKIT_INTERNAL_FADE_H