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