Merge "Fix Ime Rotation" into tizen_2.1
[platform/framework/native/uifw.git] / inc / FUiCtrlOverlayPanel.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiCtrlOverlayPanel.h
20  * @brief       This is the header file for the %OverlayPanel class.
21  *
22  * This header file contains the declarations of the %OverlayPanel class.
23  */
24
25 #ifndef _FUI_CTRL_OVERLAY_PANEL_H_
26 #define _FUI_CTRL_OVERLAY_PANEL_H_
27
28 #include <FBaseTypes.h>
29 #include <FGrpCanvas.h>
30 #include <FUiCtrlPanel.h>
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 /**
36  * @enum OverlayPanelEvaluationOption
37  *
38  * Defines the option for evaluating the bounds of an overlay panel.
39  *
40  * @since               2.1
41  */
42 enum OverlayPanelEvaluationOption
43 {
44         OVERLAY_PANEL_EVAL_OPT_GREATER_THAN,    /**< The option evaluating the overlay panel bounds and finding the minimum bounds greater than the input bounds */
45         OVERLAY_PANEL_EVAL_OPT_LESS_THAN        /**< The option evaluating the overlay panel bounds and finding the maximum bounds smaller than input bounds */
46 };
47
48 /**
49  * @class       OverlayPanel
50  * @brief       This class is an implementation of %OverlayPanel.
51  *
52  * @since               2.1
53  *
54  * @remarks     The %OverlayPanel control can only be attached to a %Form control by using Tizen::Ui::Container::AddControl method, because of its native
55  *                      characteristics. Since %OverlayPanel inherits a Panel control, it can be used as a container if needed.
56  *
57  * The %OverlayPanel class is an implementation of the %OverlayPanel control.
58  * The %OverlayPanel is a special type of panel which is used to specify area where the developer
59  * can playback video or camera preview. It is called an overlay because it is possible to overlay
60  * other graphics and controls on top of the panel.
61  * The %OverlayPanel consists of two layers, the foreground panel and background buffer which supports
62  * H/W accelerated rendering. Due to the hardware accelerated nature, there is a limitation with an
63  * %OverlayPanel. The Form that houses an %OverlayPanel can only have a black, opaque background.
64  * The overlay panel can manipulate the rotation and the size of input buffer.
65  *
66  * Example: Please refer to the camera preview example of %Tizen::Media::Camera
67  *
68  * @code
69 //Sample code for OverlayPanelSampleForm.h
70 #include <FBase.h>
71 #include <FMedia.h>
72 #include <FUi.h>
73
74 class OverlayPanelSampleForm
75         : public Tizen::Ui::Controls::Form
76         , public Tizen::Ui::IActionEventListener
77         , public Tizen::Media::IPlayerEventListener
78 {
79 public:
80         OverlayPanelSampleForm(void);
81         virtual ~OverlayPanelSampleForm(void);
82
83         bool Initialize(void);
84         virtual result OnInitializing(void);
85         virtual result OnTerminating(void);
86         virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
87
88         // IPlayerEventListener
89         virtual void OnPlayerOpened(result r);
90         virtual void OnPlayerEndOfClip(void);
91         virtual void OnPlayerSeekCompleted(result r);
92         virtual void OnPlayerBuffering(int percent);
93         virtual void OnPlayerErrorOccurred(const Tizen::Media::PlayerErrorReason r);
94         virtual void OnPlayerInterrupted(void);
95         virtual void OnPlayerReleased(void);
96
97 private:
98         static const int ID_BUTTON_OK = 101;
99
100         Tizen::Media::Player* __pPlayer;
101         Tizen::Ui::Controls::OverlayPanel* __pOverlayPanel;
102 };
103  *      @endcode
104  *
105  *      @code
106 //Sample code for OverlayPanelSampleForm.cpp
107 #include <FApp.h>
108 #include "OverlayPanelSampleForm.h"
109
110 using namespace Tizen::App;
111 using namespace Tizen::Base;
112 using namespace Tizen::Graphics;
113 using namespace Tizen::Media;
114 using namespace Tizen::Ui::Controls;
115
116 OverlayPanelSampleForm::OverlayPanelSampleForm(void)
117 {
118 }
119
120 OverlayPanelSampleForm::~OverlayPanelSampleForm(void)
121 {
122 }
123
124 bool
125 OverlayPanelSampleForm::Initialize(void)
126 {
127         Construct(FORM_STYLE_NORMAL);
128         return true;
129 }
130
131 result
132 OverlayPanelSampleForm::OnInitializing(void)
133 {
134         // Set bounds of overlay panel
135         Rectangle overlayPanelBounds(10, 10, GetClientAreaBounds().width - 20, 500);
136
137         // Evaluate bounds
138         bool isModifiedBounds = false;
139         result r = OverlayPanel::EvaluateBounds(OVERLAY_PANEL_EVAL_OPT_GREATER_THAN, overlayPanelBounds, isModifiedBounds);
140
141         // Creates an instance of overlay panel
142         __pOverlayPanel = new OverlayPanel();
143         __pOverlayPanel->Construct(overlayPanelBounds);
144         AddControl(__pOverlayPanel);
145
146         // Gets a background buffer info
147         BufferInfo bufferinfo;
148         __pOverlayPanel->GetBackgroundBufferInfo(bufferinfo);
149
150         // Gets a video file path (/res/video.mp4)
151         String videoFilePath = App::GetInstance()->GetAppResourcePath() + L"video.mp4";
152
153         // Creates an instance of Player
154         __pPlayer = new Player();
155         __pPlayer->Construct(*this, &bufferinfo);
156         __pPlayer->OpenFile(videoFilePath);
157         __pPlayer->Play();
158
159         // Creates an instance of Button
160         Button *pButton = new Button();
161         pButton->Construct(Rectangle(10, 10, 300, 100));
162         pButton->SetText(L"Resize & Rotate");
163         pButton->SetActionId(ID_BUTTON_OK);
164         pButton->AddActionEventListener(*this);
165         __pOverlayPanel->AddControl(pButton);
166
167         return r;
168 }
169
170 result
171 OverlayPanelSampleForm::OnTerminating(void)
172 {
173         result r = E_SUCCESS;
174
175         // Deallocates controls
176         if (__pPlayer)
177         {
178                 __pPlayer->Close();
179                 delete __pPlayer;
180         }
181
182         return r;
183 }
184
185 void
186 OverlayPanelSampleForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
187 {
188         switch(actionId)
189         {
190         case ID_BUTTON_OK:
191                 {
192                         //Modify renderer size & Rotate renderer
193                         __pOverlayPanel->SetRenderSize(Dimension(400, 400));
194                         __pOverlayPanel->SetRendererRotation(OverlayPanel::ROTATION_270);
195                 }
196                 break;
197         default:
198                 break;
199         }
200 }
201
202 // IPlayerEventListener implementation
203 void
204 OverlayPanelSampleForm::OnPlayerOpened(result r)
205 {
206         // ....
207 }
208
209 void
210 OverlayPanelSampleForm::OnPlayerEndOfClip(void)
211 {
212         // ....
213 }
214
215 void
216 OverlayPanelSampleForm::OnPlayerSeekCompleted(result r)
217 {
218         // ....
219 }
220
221 void
222 OverlayPanelSampleForm::OnPlayerBuffering(int percent)
223 {
224         // ....
225 }
226
227 void
228 OverlayPanelSampleForm::OnPlayerErrorOccurred(const PlayerErrorReason r)
229 {
230         // ....
231 }
232
233 void
234 OverlayPanelSampleForm::OnPlayerInterrupted(void)
235 {
236         // ....
237 }
238
239 void
240 OverlayPanelSampleForm::OnPlayerReleased(void)
241 {
242         // ....
243 }
244  * @endcode
245  */
246
247 class _OSP_EXPORT_ OverlayPanel
248         : public Tizen::Ui::Controls::Panel
249 {
250 public:
251         /**
252          * @enum   Rotation
253          *
254          * Defines the various rotation options.
255          *
256          * @since               2.1
257          */
258         enum Rotation
259         {
260                 ROTATION_NONE,          /**<  No rotation*/
261                 ROTATION_90,            /**<  The 90 degree rotation */
262                 ROTATION_180,           /**< The 180 degree rotation */
263                 ROTATION_270,           /**< The 270 degree rotation */
264                 ROTATION_NONE_LR,       /**< The horizontal mirroring */
265                 ROTATION_NONE_UD,       /**< The vertical mirroring */
266                 ROTATION_90_LR,         /**< The 90 degree rotation with horizontal mirroring */
267                 ROTATION_90_UD,         /**< The 90 degree rotation with vertical mirroring */
268                 ROTATION_180_LR,        /**< The 180 degree rotation with horizontal mirroring */
269                 ROTATION_180_UD,        /**< The 180 degree rotation with vertical mirroring */
270                 ROTATION_270_LR,        /**< The 270 degree rotation with horizontal mirroring */
271                 ROTATION_270_UD,        /**< The 270 degree rotation with vertical mirroring */
272                 ROTATION_MAX
273         };
274
275         /**
276          * @enum  BufferPixelFormat
277          *
278          * Defines the pixel formats.
279          *
280          * @since               2.1
281          */
282         enum BufferPixelFormat
283         {
284                 BUFFER_PIXEL_FORMAT_ARGB8888,                   /**< The ARGB8888 pixel format */
285                 BUFFER_PIXEL_FORMAT_RGB565,                     /**< The RGB565 pixel format */
286                 BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR,    /**< The 8 bit Y plane followed by 8 bit 2 X 2 subsampled U and V planes */
287                 BUFFER_PIXEL_FORMAT_NV12,                               /**< The NV12 pixel format */
288                 BUFFER_PIXEL_FORMAT_UYVY                                /**< The UYVY pixel format */
289         };
290
291         /**
292          * This is the default constructor for this class.
293          * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
294          *
295          * @since               2.1
296          */
297         OverlayPanel(void);
298
299         /**
300          * This destructor overrides Tizen::Base::Object::~Object().
301          *
302          * @since               2.1
303          */
304         virtual ~OverlayPanel(void);
305
306         /**
307          * Initializes this instance of %OverlayPanel at the specified rectangle.
308          *
309          * @since               2.1
310          *
311          * @return              An error code
312          * @param[in]           rect                            The location and size of the %OverlayPanel control @n
313          *                                                              The maximum size is equal to screen size. for example 720 x 1280 on a HD screen, or 480 x 800 on a WVGA screen. @n
314          * @exception           E_SUCCESS               The method is successful.
315          * @exception   E_INVALID_ARG   A specified input parameter @c is invalid.
316          * @exception           E_SYSTEM                A system error has occurred.
317          * @remarks             The size of the control must be within the range defined by the minimum size and the maximum size.
318          *                              To guarantee the size of the render buffer equal to the size of the %OverlayPanel after constructed, checks bounds of @c rect using EvaluateBounds() method before calling this method.
319          * @remarks             Do not use %OverlayPanel in combination with %OverlayRegion. If used, %OverlayPanel may not work as expected.
320          * @see                 %Tizen::Ui::Container
321          */
322         result Construct(const Tizen::Graphics::Rectangle& rect);
323
324         /**
325          * Initializes this instance of %OverlayPanel at the specified rectangle.
326          *
327          * @since               2.1
328          *
329          * @return              An error code
330          * @param[in]           rect                            The location and size of the %OverlayPanel control @n
331          *                                                              The maximum size is equal to screen size. for example 720 x 1280 on a HD screen, or 480 x 800 on a WVGA screen. @n
332          * @exception           E_SUCCESS               The method is successful.
333          * @exception   E_INVALID_ARG   A specified input parameter @c is invalid.
334          * @exception           E_SYSTEM                A system error has occurred.
335          * @remarks             The size of the control must be within the range defined by the minimum size and the maximum size.
336          *                              To guarantee the size of the render buffer equal to the size of the %OverlayPanel after constructed, checks bounds of @c rect using EvaluateBounds() method before calling this method.
337          * @remarks             Do not use %OverlayPanel in combination with %OverlayRegion. If used, %OverlayPanel may not work as expected.
338          * @see                 %Tizen::Ui::Container
339          */
340         result Construct(const Tizen::Graphics::FloatRectangle& rect);
341
342         /**
343          * Sets the rotation of the input buffer. @n
344          *
345          * @since               2.1
346          *
347          * @param[in]   rotation        The rotation
348          */
349         void SetRendererRotation(OverlayPanel::Rotation rotation);
350
351         /**
352          * @if OSPDEPREC
353          * Changes the size of the displayed renderer.
354          *
355          * @brief <i> [Deprecated]  </i>
356          * @deprecated  This method is deprecated. Instead of using this class, use the %OverlayRegion class, that supports video playback and camera preview.
357          * @since                       2.0
358          *
359          * @param[in]   dim     The dimension of the window to draw
360          *
361          * @endif
362          */
363         void SetRendererSize(Tizen::Graphics::Dimension& dim);
364
365         /**
366          * Changes the size of the displayed renderer.
367          *
368          * @since               2.1
369          *
370          * @return      An error code
371          * @param[in]   dim     The dimension of the window to draw
372          * @exception E_SUCCESS                 The method is successful.
373          * @exception E_INVALID_ARG             A specified input parameter is invalid.
374          * @exception E_INVALID_OPERATION       The current state of the instance prohibits the execution of the specified operation.
375          * @remarks     A OverlayPanel becomes displayable only after it has been added to a form.
376          *                      If you want to resize window to draw render buffer, calls this function after the OverlayPanel is added to a %Form control
377          * @code
378          *      OverlayPanel* pOverlayPanel = new OverlayPanel();
379          *      pOverlayPanel->Construct(Rectangle(100, 250, 300, 300));
380          *      AddControl(pOverlayPanel);
381          *
382          *      //...
383          *      result r = pOverlayPanel->SetRenderSize(Dimesion(300, 200));
384          *      //...
385            * @endcode
386          */
387         result SetRenderSize(const Tizen::Graphics::Dimension& dim);
388
389         /**
390          * Changes the size of the displayed renderer.
391          *
392          * @since               2.1
393          *
394          * @return      An error code
395          * @param[in]   dim     The dimension of the window to draw
396          * @exception E_SUCCESS                 The method is successful.
397          * @exception E_INVALID_ARG             A specified input parameter is invalid.
398          * @exception E_INVALID_OPERATION       The current state of the instance prohibits the execution of the specified operation.
399          * @remarks     A OverlayPanel becomes displayable only after it has been added to a form. 
400          *                      If you want to resize window to draw render buffer, calls this function after the OverlayPanel is added to a %Form control
401          * @code
402          *      OverlayPanel* pOverlayPanel = new OverlayPanel();
403          *      pOverlayPanel->Construct(FloatRectangle(100.0, 250.0, 300.0, 300.0));
404          *      AddControl(pOverlayPanel);
405          *
406          *      //...
407          *      result r = pOverlayPanel->SetRenderSize(FloatDimesion(300.0, 200.0));
408          *      //...
409            * @endcode
410          */
411         result SetRenderSize(const Tizen::Graphics::FloatDimension& dim);
412
413         /**
414          * Sets the input buffer.
415          *
416          * @since               2.1
417          *
418          * @param[in]           destDim                                 The dimension of the window to be drawn
419          * @param[in]           srcBuffer                                       The source buffer
420          * @param[in]           srcDim                                  The source dimension
421          * @param[in]           srcFormat                               The pixel format of buffer data
422          * @exception           E_SUCCESS                               The method is successful.
423          * @exception           E_INVALID_ARG                   A specified input parameter is invalid.
424          * @exception           E_SYSTEM                                A system error has occurred.
425          * @exception           E_UNSUPPORTED_FORMAT    The specified pixel format is not supported.
426          * @remarks             Control::Invalidate() methods must be called to properly display the input buffer.
427          */
428         result SetInputBuffer(const Tizen::Graphics::Dimension& destDim, const Tizen::Base::ByteBuffer& srcBuffer, const Tizen::Graphics::Dimension& srcDim, BufferPixelFormat srcFormat);
429
430         /**
431          * Sets the input buffer.
432          *
433          * @since               2.1
434          *
435          * @param[in]           destDim                                 The dimension of the window to be drawn
436          * @param[in]           srcBuffer                                       The source buffer
437          * @param[in]           srcDim                                  The source dimension
438          * @param[in]           srcFormat                               The pixel format of buffer data
439          * @exception           E_SUCCESS                               The method is successful.
440          * @exception           E_INVALID_ARG                   A specified input parameter is invalid.
441          * @exception           E_SYSTEM                                A system error has occurred.
442          * @exception           E_UNSUPPORTED_FORMAT    The specified pixel format is not supported.
443          * @remarks             Control::Invalidate() methods must be called to properly display the input buffer.
444          */
445         result SetInputBuffer(const Tizen::Graphics::FloatDimension& destDim, const Tizen::Base::ByteBuffer& srcBuffer, const Tizen::Graphics::Dimension& srcDim, BufferPixelFormat srcFormat);
446
447         /**
448          * Gets the information of the background buffer.
449          *
450          * @since               2.1
451          *
452          * @return              An error code
453          * @param[out]  info                                    The information of the background buffer
454          * @exception           E_SUCCESS                       The method is successful.
455          * @exception           E_OPERATION_FAILED      The operation has failed.
456          * @remarks             Currently, this method provides buffer information except the pointer of the RGB color buffer. @n
457          *                              Therefore, info.pPixels is always assigned @c null.
458          */
459         result GetBackgroundBufferInfo(Tizen::Graphics::BufferInfo& info) const;
460
461         /**
462          * @if OSPDEPREC
463          * Sets the aspect ratio of the renderer.
464          *
465          * @brief <i> [Deprecated]  </i>
466          * @deprecated  This method is deprecated because the renderer aspect ratio is not guaranteed any more.
467          * @since                       2.0
468          *
469          * @param[in]   fix     Set to @c true if the renderer will display the aspect ratio of the input buffer even if the renderer and input data have
470          *                              different aspect ratios, @n
471          *                              else @c false
472          * @remarks             This method has no effects for hardware accelerated GL backend.
473          * @endif
474          */
475         void SetRendererAspectRatio(bool fix);
476
477         /**
478          * @if OSPDEPREC
479          * Gets the masking color of this control.
480          *
481          * @brief <i> [Deprecated]  </i>
482          * @deprecated  This method is deprecated because masking color does not exist on OverlayPanel any more.
483          * @remarks             Do not call this method. It is not supported.
484          * @since                       2.0
485          *
486          * @return              Always returns Tizen::Graphics::Color(0x00000000)
487          * @endif
488          */
489         Tizen::Graphics::Color GetMaskingColor(void) const;
490
491         /**
492          * Evaluates and returns the valid position and size that are closest to the specified bounds.
493          *
494          * @since               2.1
495          *
496          * @return              An error code
497          * @param[in]           option                          The option for evaluating the bounds of the overlay panel
498          * @param[in, out]      rect                                    An instance of %Tizen::Graphics::Rectangle that represents the validated bounds of %OverlayPanel @n
499          *                                                                      The width and height of the input rectangle must be greater than @c 0.
500          * @param[out]  modified                                A boolean flag that indicates whether the specified @c rectangle is modified
501          * @exception           E_SUCCESS                       The method is successful.
502          * @exception           E_INVALID_ARG                   The specified input parameter @c is invalid.
503          * @exception           E_UNSUPPORTED_OPTION    The specified input parameter @c is not supported.
504          * @exception           E_OPERATION_FAILED              The operation has failed.
505          * @remarks             Due to the hardware accelerated rendering, there are limitations for an overlay panel. @n
506          *                              The hardware capability for an overlay region is checked by using the GetWidthUnit(), GetHeightUnit() and GetMaxCount(). @n
507          *                              If the application runs on multi-screen resolutions, the specified bounds may not meet the hardware limitations of the overlay panel.
508          *                              In such cases, Construct() will return E_INVALID_ARG. @n
509          *                              To prevent this kind of problem, the application must use the OverlayPanel::EvaluateBounds() method to get a validated bounds
510          * @remarks             The specific error code can be accessed using the GetLastResult() method.
511          */
512         static result EvaluateBounds(OverlayPanelEvaluationOption option, Tizen::Graphics::Rectangle& rect, bool& modified);
513
514         /**
515          * Evaluates and returns the valid position and size that are closest to the specified bounds.
516          *
517          * @since               2.1
518          *
519          * @return              An error code
520          * @param[in]           option                          The option for evaluating the bounds of the overlay panel
521          * @param[in, out]      rect                                    An instance of %Tizen::Graphics::FloatRectangle that represents the validated bounds of %OverlayPanel @n
522          *                                                                      The width and height of the input float rectangle must be greater than @c 0.
523          * @param[out]  modified                                A boolean flag that indicates whether the specified @c rectangle is modified
524          * @exception           E_SUCCESS                       The method is successful.
525          * @exception           E_INVALID_ARG                   The specified input parameter @c is invalid.
526          * @exception           E_UNSUPPORTED_OPTION    The specified input parameter @c is not supported.
527          * @exception           E_OPERATION_FAILED              The operation has failed.
528          * @remarks             Due to the hardware accelerated rendering, there are limitations for an overlay panel. @n
529          *                              The hardware capability for an overlay region is checked by using the GetWidthUnit(), GetHeightUnit() and GetMaxCount(). @n
530          *                              If the application runs on multi-screen resolutions, the specified bounds may not meet the hardware limitations of the overlay panel.
531          *                              In such cases, Construct() will return E_INVALID_ARG. @n
532          *                              To prevent this kind of problem, the application must use the OverlayPanel::EvaluateBounds() method to get a validated bounds
533          * @remarks             The specific error code can be accessed using the GetLastResult() method.
534          */
535         static result EvaluateBounds(OverlayPanelEvaluationOption option, Tizen::Graphics::FloatRectangle& rect, bool& modified);
536
537         /**
538          * Gets the BufferPixelFormat list for the %OverlayPanel class. @n
539          * Each list item has a Tizen::UI::Controls::OverlayPanel::BufferPixelFormat value.
540          *
541          * @since               2.1
542          *
543          * @return              A list of the pixel formats supported by the %OverlayPanel class, @n
544          *                              else @c null if no pixel format is supported or an exception occurs
545          * @remark              The specific error code can be accessed using the GetLastResult() method. @n
546          *                              The return value and each item in the list must be deleted by the caller. @n
547          *                              The format list can vary depending on the device. After checking the supported formats using this API, it's better to use a proper pixel format. @n
548          */
549         static Tizen::Base::Collection::IListT<BufferPixelFormat>* GetSupportedBufferPixelFormatListN(void);
550
551         /**
552          * Gets the width unit. @n
553          * Only a multiple of this value can be allowed as the width of an overlay panel.
554          *
555          * @since               2.1
556          *
557          * @return      The value of width
558          */
559         static int GetWidthUnit(void);
560
561         /**
562          * Gets the height unit. @n
563          * Only a multiple of this value can be allowed as the height of an overlay panel.
564          *
565          * @since               2.1
566          *
567          * @return      The value of the height
568          */
569         static int GetHeightUnit(void);
570
571         /**
572          * Gets the maximum count of overlay panel that can be used simultaneously per application.
573          *
574          * @since               2.1
575          *
576          * @return      The maximum count of overlay panel that can be used simultaneously per application
577          */
578         static int GetMaxCount(void);
579
580 private:
581         //
582         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
583         //
584         OverlayPanel(const OverlayPanel& rhs);
585
586         //
587         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
588         //
589         OverlayPanel& operator =(const OverlayPanel& rhs);
590 }; // OverlayPanel
591
592 }}} // Tizen::Ui::Controls
593
594 #endif // _FUI_CTRL_OVERLAY_PANEL_H_
595