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