Merge "Added Rotation and Flip enums for common use." into tizen
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / PlayerDisplaySettings.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Diagnostics;
19 using Native = Interop.Display;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Provides a means to configure display settings for video <see cref="Player"/>.
25     /// </summary>
26     public class PlayerDisplaySettings
27     {
28         internal PlayerDisplaySettings(Player player)
29         {
30             Debug.Assert(player != null);
31
32             Player = player;
33         }
34
35         private Player Player
36         {
37             get;
38         }
39
40         private PlayerDisplayMode _displayMode = PlayerDisplayMode.LetterBox;
41
42         /// <summary>
43         /// Gets or sets the <see cref="PlayerDisplayMode"/>.
44         /// </summary>
45         /// <exception cref="InvalidOperationException">
46         ///     The display is not assigned.\n
47         ///     -or-\n
48         ///     Operation failed; internal error.
49         /// </exception>
50         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
51         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
52         public PlayerDisplayMode Mode
53         {
54             get
55             {
56                 return _displayMode;
57             }
58             set
59             {
60                 if (_displayMode == value)
61                 {
62                     return;
63                 }
64
65                 ValidationUtil.ValidateEnum(typeof(PlayerDisplayMode), value);
66
67                 Native.SetMode(Player.Handle, value).
68                     ThrowIfFailed("Failed to set display mode");
69
70                 _displayMode = value;
71             }
72         }
73
74         private bool _isVisible = true;
75
76         /// <summary>
77         /// Gets or sets the value indicating whether the display is visible.
78         /// </summary>
79         /// <value>true if the display is visible; otherwise false.</value>
80         /// <exception cref="InvalidOperationException">
81         ///     The display is not assigned.\n
82         ///     -or-\n
83         ///     Operation failed; internal error.
84         /// </exception>
85         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
86         public bool IsVisible
87         {
88             get
89             {
90                 return _isVisible;
91             }
92             set
93             {
94                 if (_isVisible == value)
95                 {
96                     return;
97                 }
98
99                 Native.SetVisible(Player.Handle, value).
100                     ThrowIfFailed("Failed to set the visible state of the display");
101
102                 _isVisible = value;
103             }
104         }
105
106         private Rotation _rotation = Rotation.Rotate0;
107
108         /// <summary>
109         /// Gets or sets the rotation of the display.
110         /// </summary>
111         /// <value><see cref="PlayerDisplayRotation.RotationNone"/>,
112         ///     <see cref="PlayerDisplayRotation.Rotation90"/>,
113         ///     <see cref="PlayerDisplayRotation.Rotation180"/>,
114         ///     <see cref="PlayerDisplayRotation.Rotation270"/></value>
115         /// <exception cref="InvalidOperationException">
116         ///     The display is not assigned.\n
117         ///     -or-\n
118         ///     Operation failed; internal error.
119         /// </exception>
120         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
121         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
122         public Rotation Rotation
123         {
124             get
125             {
126                 return _rotation;
127             }
128             set
129             {
130                 if (_rotation == value)
131                 {
132                     return;
133                 }
134
135                 ValidationUtil.ValidateEnum(typeof(Rotation), value);
136
137                 Native.SetRotation(Player.Handle, value).
138                     ThrowIfFailed("Failed to set the rotation state of the display");
139
140                 _rotation = value;
141             }
142         }
143
144         /// <summary>
145         /// Sets the roi(region of interest).
146         /// </summary>
147         /// <param name="roi">The region.</param>
148         /// <remarks>
149         /// To set roi, <see cref="Mode"/> must be set to <see cref="PlayerDisplayMode.Roi"/> first.
150         /// </remarks>
151         /// <exception cref="InvalidOperationException">
152         ///     The display is not assigned.\n
153         ///     -or-\n
154         ///     Operation failed; internal error.\n
155         ///     -or-\n
156         ///     <see cref="Mode"/> is not set to <see cref="PlayerDisplayMode.Roi"/>
157         /// </exception>
158         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
159         /// <exception cref="ArgumentOutOfRangeException">width or height is less than or equal to zero.</exception>
160         public void SetRoi(Rectangle roi)
161         {
162             if (_displayMode != PlayerDisplayMode.Roi)
163             {
164                 throw new InvalidOperationException("Mode is not set to Roi");
165             }
166
167             if (roi.Width <= 0)
168             {
169                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Width,
170                     $"The width of the roi can't be less than or equal to zero.");
171             }
172             if (roi.Height <= 0)
173             {
174                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Height,
175                     $"The height of the roi can't be less than or equal to zero.");
176             }
177
178             Native.SetRoi(Player.Handle, roi.X, roi.Y, roi.Width, roi.Height).
179                 ThrowIfFailed("Failed to set the roi");
180         }
181     }
182 }