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