ea0a4c594b2bc16ce7d694db47bffbb85fd16ac5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / view / view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_VIEW_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
21 #include <dali/dali.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/public-api/controls/control-impl.h>
25 #include <dali-toolkit/public-api/controls/view/view.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 class View;
34
35 namespace Internal
36 {
37
38 /**
39  * View is a control to add layers and a background.
40  * @see Dali::Toolkit::View for more details.
41  */
42 class View : public ControlImpl
43 {
44 private:
45   typedef std::map<unsigned int,Layer> LayerContainer;
46   typedef std::map<unsigned int,Layer>::iterator LayerIt;
47   typedef std::map<unsigned int,Layer>::const_iterator LayerConstIt;
48
49   /**
50    * Orientation declaration used internally to rotate the view.
51    * The angles associated with each enum value could be changed with the SetOrientationFunction method.
52    */
53   enum Orientation
54   {
55     PORTRAIT,          ///< portrait orientation.
56     LANDSCAPE,         ///< landscape orientation.
57     PORTRAIT_INVERSE,  ///< portrait inverse orientation.
58     LANDSCAPE_INVERSE  ///< landscape inverse orientation.
59   };
60
61 public:
62
63   /**
64    * Create an initialized View.
65    * @param fullscreen If true, the view's size is going to be set with the Dali::Stage size. Otherwise a size must be provided.
66    * @return A handle to a newly allocated Dali resource.
67    */
68   static Toolkit::View New( bool fullscreen );
69
70   /**
71    * @copydoc Dali::Toolkit::View::GetContentLayer()
72    */
73   Layer GetContentLayer( unsigned int index ) const;
74
75   /**
76    * @copydoc Dali::Toolkit::View::AddContentLayer()
77    */
78   unsigned int AddContentLayer( Layer layer );
79
80   /**
81    * @copydoc Dali::Toolkit::View::RemoveContentLayer()
82    */
83   void RemoveContentLayer( Layer layer );
84
85   /**
86    * @copydoc Dali::Toolkit::View::GetBackgroundLayer()
87    */
88   Layer GetBackgroundLayer() const;
89
90   /**
91    * @copydoc Dali::Toolkit::View::SetBackground()
92    */
93   void SetBackground( ImageActor image );
94
95   /**
96    * @copydoc Dali::Toolkit::View::SetOrientationFunction()
97    */
98   void SetOrientationFunction( Degree portrait, Degree landscale, Degree portraitInverse, Degree landscapeInverse );
99
100   /**
101    * @copydoc Dali::Toolkit::View::OrientationChanged()
102    *
103    */
104   void OrientationChanged( Dali::Orientation orientation );
105
106   /**
107    * @copydoc Dali::Toolkit::View::SetAutoRotate()
108    *
109    */
110   void SetAutoRotate( bool enabled );
111
112 public:
113
114   /**
115    * @copydoc Dali::Toolkit::View::AnimationStartedSignalOrientation()
116    */
117   Toolkit::View::OrientationAnimationStartedSignalV2& OrientationAnimationStartedSignal();
118
119   /**
120    * Connects a callback function with the object's signals.
121    * @param[in] object The object providing the signal.
122    * @param[in] tracker Used to disconnect the signal.
123    * @param[in] signalName The signal to connect to.
124    * @param[in] functor A newly allocated FunctorDelegate.
125    * @return True if the signal was connected.
126    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
127    */
128   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
129
130 private: // From ControlImpl
131
132   /**
133    * @copydoc Toolkit::Control::OnInitialize()
134    */
135   virtual void OnInitialize();
136
137 private:
138
139
140   /**
141    * Constructor.
142    * It initializes View members.
143    * It initializes orientations as follows: portrait 0, landscape 90, portrait inverse 180, landscape inverse 270.
144    * @param fullscreen If true, the view's size is going to be set with the Dali::Stage size. Otherwise a size must be provided.
145    */
146   View(bool fullscreen);
147
148   /**
149    * A reference counted object may only be deleted by calling Unreference()
150    */
151   virtual ~View();
152
153   /**
154    * Return an orientation for the given angle in degrees.
155    * @param degree angle in degrees.
156    * @return An internal orientation.
157    */
158   View::Orientation DegreeToViewOrientation( Degree degree );
159
160   /**
161    * Find a layer in the layer container. Non const method
162    */
163   LayerIt FindLayer( Layer layer );
164
165 private:
166   int            mOrientation;            ///< Stores the given orientation in degrees.
167   bool           mFullScreen;             ///< Stores if the view is fullscreen or not.
168   LayerContainer mContentLayers;          ///< Layer container.
169   unsigned int   mNextLayerIndex;         ///< Next index to be used when a layer is added.
170   Layer          mBackgroundLayer;        ///< The background layer.
171   Animation      mRotateAnimation;        ///< The animation which rotates the view (and all layers added to it)
172   float          mOrientationFunction[4]; ///< The orientation function used to transform from degrees to the internal orientation.
173   bool           mAutoRotateEnabled;      ///< Whether the view rotates if the OrientationChanged method is called.
174
175   Toolkit::View::OrientationAnimationStartedSignalV2 mOrientationAnimationStartedSignalV2;
176 };
177
178 } // namespace Internal
179
180
181 // Helpers for public-api forwarding methods
182
183 inline Toolkit::Internal::View& GetImpl( Toolkit::View& view )
184 {
185   DALI_ASSERT_ALWAYS( view );
186
187   Dali::RefObject& handle = view.GetImplementation();
188
189   return static_cast<Toolkit::Internal::View&>( handle );
190 }
191
192 inline const Toolkit::Internal::View& GetImpl( const Toolkit::View& view )
193 {
194   DALI_ASSERT_ALWAYS( view );
195
196   const Dali::RefObject& handle = view.GetImplementation();
197
198   return static_cast<const Toolkit::Internal::View&>( handle );
199 }
200
201 } // namespace Toolkit
202
203 } // namespace Dali
204
205 #endif // __DALI_TOOLKIT_INTERNAL_VIEW_H__