License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / public-api / controls / view / view.h
1 #ifndef __DALI_TOOLKIT_VIEW_H__
2 #define __DALI_TOOLKIT_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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control.h>
23
24 namespace Dali DALI_IMPORT_API
25 {
26
27 namespace Internal DALI_INTERNAL
28 {
29 // Forward declarations
30 class CustomActor;
31 }
32
33 namespace Toolkit
34 {
35
36 namespace Internal DALI_INTERNAL
37 {
38 // Forward declarations
39 class View;
40 }
41
42 /**
43  * View provides a container where different Dali::Layer instances and a background could be added. It
44  * also provides a View::OrientationChanged() method which could be connected to the Dali::Orientation::SignalChange() signal.
45  * This method rotates all layers accordingly with the given orientation, it emits an OrientationAnimationStartsSignal signal just before the rotation animation starts.
46  *
47  * By default view anchor point and parent origin are centered, the size is full screen and is got directly from the Dali::Stage. However, by passing \e false to the
48  * Toolkit::View::New() method a custom size could be specified, and after initialization, anchor point and parent origin could be updated.
49  *
50  * If a background is set, a background layer will be created and dropped to the bottom.
51  *
52  * Use example (application is a Dali::Application object):
53  * \code{.cpp}
54  * Stage stage = Stage::GetCurrent();
55  *
56  * // Create default View. By default it gets the stage size.
57  * Toolkit::View view = Toolkit::View::New();
58  *
59  * // Add the view to the stage before setting the background.
60  * stage.Add( view );
61  *
62  * // Set background image. BACKGROUND_IMAGE is a string with the background image file path.
63  * Image backgroundImage = Image::New( BACKGROUND_IMAGE );
64  * ImageActor backgroundImageActor = ImageActor::New( backgroundImage );
65  * mView.SetBackground( backgroundImageActor );
66  *
67  * // Connects the orientation signal with the View::OrientationChanged method.
68  * application.GetOrientation().ChangedSignal().Connect( &view, &Toolkit::View::OrientationChanged );
69  *
70  * // Create a content layer.
71  * Layer contentLayer = Layer::New();
72  * contentLayer.SetAnchorPoint( AnchorPoint::CENTER );
73  * contentLayer.SetParentOrigin( ParentOrigin::CENTER );
74  * contentLayer.ApplyConstraint( ParentConstraint::Size::New( ParentSize() ) );
75  * view.AddContentLayer( contentLayer );
76  * \endcode
77  */
78 class View : public Control
79 {
80 public:
81   //Signal Names
82   static const char* const SIGNAL_ORIENTATION_ANIMATION_START;
83
84 public:
85
86   /**
87    * Create a View handle; this can be initialised with View::New()
88    * Calling member functions with an uninitialised handle is not allowed.
89    */
90   View();
91
92   /**
93    * Copy constructor. Creates another handle that points to the same real object
94    * @param handle to copy from
95    */
96   View( const View& handle );
97
98   /**
99    * Assignment operator. Changes this handle to point to another real object
100    */
101   View& operator=( const View& handle );
102
103   /**
104    * virtual Destructor.
105    */
106   virtual ~View();
107
108   /**
109    * Create an initialized View.
110    * @param fullscreen If true, the view's size is going to be set with the Dali::Stage size. Otherwise a size must be provided. By default fullscreen is set to true.
111    * @return A handle to a newly allocated Dali resource.
112    */
113   static View New( bool fullscreen = true );
114
115   /**
116    * Downcast an Object handle to View. If handle points to a View the
117    * downcast produces valid handle. If not the returned handle is left uninitialized.
118    * @param[in] handle Handle to an object
119    * @return handle to a View or an uninitialized handle
120    */
121   static View DownCast( BaseHandle handle );
122
123   /**
124    * Returns a content layer.
125    * @param index to the layer container.
126    * @return A Layer handle if it exists, otherwise it returns an uninitialized handle.
127    */
128   Layer GetContentLayer( unsigned int index ) const;
129
130   /**
131    * Adds a new layer in the view.
132    * @pre layer must be initialized.
133    * @param layer A Layer handle.
134    * @return the an index that can be used to access the layer stores in the view.
135    */
136   unsigned int AddContentLayer( Layer layer );
137
138   /**
139    * Removes a layer from the view.
140    * @param layer The layer to be removed.
141    */
142   void RemoveContentLayer( Layer layer );
143
144   /**
145    * Returns the background layer.
146    * @return the background layer or an empty handle if any background has been set before.
147    */
148   Layer GetBackgroundLayer() const;
149
150   /**
151    * Sets a background image.
152    *
153    * It creates a background layer the first time this method is called and it is dropped to the bottom.
154    * Any previous set background will be replaced by the new one.
155    *
156    * @pre View must be on stage before calling SetBackground.
157    * @param image An image actor.
158    */
159   void SetBackground( ImageActor image );
160
161   /**
162    * Sets the angle values for portrait, landscape, portrait inverse and landscape inverse.
163    *
164    * These angles are used to rotate the views.
165    * By default, orientation angles are initialized as follows: portrait 0, landscape 90, portrait inverse 180, landscape inverse 270.
166    *
167    * @param portrait angle in degrees.
168    * @param landscale angle in degrees.
169    * @param portraitInverse angle in degrees.
170    * @param landscapeInverse angle in degrees.
171    */
172   void SetOrientationFunction( Degree portrait, Degree landscale, Degree portraitInverse, Degree landscapeInverse );
173
174   /**
175    * It rotates all layers to the new given orientation.
176    *
177    * @param orientation The new orientation.
178    */
179   void OrientationChanged( Orientation orientation );
180
181   /**
182    * Enables or disables the view's rotation when device orientation changes.
183    * @param enabled Whether auto-rotate should be enabled or disabled. By default is enabled.
184    */
185   void SetAutoRotate( bool enabled );
186
187 public: //Signals
188
189   // Orientation change animation starts.
190   typedef SignalV2< void ( View, Animation&, const Orientation& ) > OrientationAnimationStartedSignalV2;
191
192   /**
193    * Signal emitted just before the rotate animation starts when the device orientation changes.
194    */
195   OrientationAnimationStartedSignalV2& OrientationAnimationStartedSignal();
196
197 public: // Not intended for application developers
198
199   /**
200    * Creates a handle using the Toolkit::Internal implementation.
201    * @param[in]  implementation  The Control implementation.
202    */
203   View( Internal::View& implementation );
204
205   /**
206    * Allows the creation of this Control from an Internal::CustomActor pointer.
207    * @param[in]  internal  A pointer to the internal CustomActor.
208    */
209   View( Dali::Internal::CustomActor* internal );
210 };
211
212
213 } // namespace Toolkit
214
215 } // namespace Dali
216
217 #endif // __DALI_TOOLKIT_VIEW_H__