5352afed74b8a4d7c51219f77234302ebb15b94a
[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   /**
141    *
142    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
143    */
144   virtual void OnControlSizeSet( const Vector3& targetSize );
145
146 private:
147
148
149   /**
150    * Constructor.
151    * It initializes View members.
152    * It initializes orientations as follows: portrait 0, landscape 90, portrait inverse 180, landscape inverse 270.
153    * @param fullscreen If true, the view's size is going to be set with the Dali::Stage size. Otherwise a size must be provided.
154    */
155   View(bool fullscreen);
156
157   /**
158    * A reference counted object may only be deleted by calling Unreference()
159    */
160   virtual ~View();
161
162   /**
163    * Return an orientation for the given angle in degrees.
164    * @param degree angle in degrees.
165    * @return An internal orientation.
166    */
167   View::Orientation DegreeToViewOrientation( Degree degree );
168
169   /**
170    * Find a layer in the layer container. Non const method
171    */
172   LayerIt FindLayer( Layer layer );
173
174 private:
175   int            mOrientation;            ///< Stores the given orientation in degrees.
176   bool           mFullScreen;             ///< Stores if the view is fullscreen or not.
177   LayerContainer mContentLayers;          ///< Layer container.
178   unsigned int   mNextLayerIndex;         ///< Next index to be used when a layer is added.
179   Layer          mBackgroundLayer;        ///< The background layer.
180   Animation      mRotateAnimation;        ///< The animation which rotates the view (and all layers added to it)
181   float          mOrientationFunction[4]; ///< The orientation function used to transform from degrees to the internal orientation.
182   bool           mAutoRotateEnabled;      ///< Whether the view rotates if the OrientationChanged method is called.
183   Vector3        mViewSize;               ///< The Control Size
184
185   Toolkit::View::OrientationAnimationStartedSignalType mOrientationAnimationStartedSignal;
186 };
187
188 } // namespace Internal
189
190
191 // Helpers for public-api forwarding methods
192
193 inline Toolkit::Internal::View& GetImpl( Toolkit::View& view )
194 {
195   DALI_ASSERT_ALWAYS( view );
196
197   Dali::RefObject& handle = view.GetImplementation();
198
199   return static_cast<Toolkit::Internal::View&>( handle );
200 }
201
202 inline const Toolkit::Internal::View& GetImpl( const Toolkit::View& view )
203 {
204   DALI_ASSERT_ALWAYS( view );
205
206   const Dali::RefObject& handle = view.GetImplementation();
207
208   return static_cast<const Toolkit::Internal::View&>( handle );
209 }
210
211 } // namespace Toolkit
212
213 } // namespace Dali
214
215 #endif // __DALI_TOOLKIT_INTERNAL_VIEW_H__