959545d12e87a87039a085a36f4f25f0350f8366
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / PrimitiveVisual.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
18 namespace Tizen.NUI
19 {
20     /// <summary>
21     /// A class encapsulating the property map of the primetive visual.
22     /// </summary>
23     /// <since_tizen> 3 </since_tizen>
24     public class PrimitiveVisual : VisualMap
25     {
26         private PrimitiveVisualShapeType? _shape = null;
27         private Color _mixColorForPrimitiveVisual = null;
28         private int? _slices = null;
29         private int? _stacks = null;
30         private float? _scaleTopRadius = null;
31         private float? _scaleBottomRadius = null;
32         private float? _scaleHeight = null;
33         private float? _scaleRadius = null;
34         private Vector3 _scaleDimensions = null;
35         private float? _bevelPercentage = null;
36         private float? _bevelSmoothness = null;
37         private Vector3 _lightPosition = null;
38
39         /// <summary>
40         /// Constructor.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         public PrimitiveVisual() : base()
44         {
45         }
46
47         /// <summary>
48         /// Gets or sets the specific shape to render.<br />
49         /// If not specified, the default is PrimitiveVisualShapeType.Sphere.<br />
50         /// Optional.
51         /// </summary>
52         /// <since_tizen> 3 </since_tizen>
53         public PrimitiveVisualShapeType Shape
54         {
55             get
56             {
57                 return _shape ?? (PrimitiveVisualShapeType.Sphere);
58             }
59             set
60             {
61                 _shape = value;
62                 UpdateVisual();
63             }
64         }
65
66         /// <summary>
67         /// Gets or sets the color of the shape.<br />
68         /// If not specified, the default is Color (0.5, 0.5, 0.5, 1.0).<br />
69         /// Applies to all shapes.<br />
70         /// Optional.
71         /// </summary>
72         /// <since_tizen> 3 </since_tizen>
73         public new Color MixColor
74         {
75             get
76             {
77                 return _mixColorForPrimitiveVisual ?? (new Color(0.5f, 0.5f, 0.5f, 1.0f));
78             }
79             set
80             {
81                 _mixColorForPrimitiveVisual = value;
82                 UpdateVisual();
83             }
84         }
85
86         /// <summary>
87         /// Gets or sets the number of slices as you go around the shape.<br />
88         /// For spheres and conical frustrums, this determines how many divisions there are as you go around the object.<br />
89         /// If not specified, the default is 128.<br />
90         /// The range is from 1 to 255.<br />
91         /// Optional.
92         /// </summary>
93         /// <since_tizen> 3 </since_tizen>
94         public int Slices
95         {
96             get
97             {
98                 return _slices ?? (128);
99             }
100             set
101             {
102                 _slices = value;
103                 UpdateVisual();
104             }
105         }
106
107         /// <summary>
108         /// Gets or sets the number of stacks as you go down the shape.<br />
109         /// For spheres, 'stacks' determines how many layers there are as you go down the object.<br />
110         /// If not specified, the default is 128.<br />
111         /// The range is from 1 to 255.<br />
112         /// Optional.
113         /// </summary>
114         /// <since_tizen> 3 </since_tizen>
115         public int Stacks
116         {
117             get
118             {
119                 return _stacks ?? (128);
120             }
121             set
122             {
123                 _stacks = value;
124                 UpdateVisual();
125             }
126         }
127
128         /// <summary>
129         /// Gets or sets the scale of the radius of the top circle of a conical frustrum.<br />
130         /// If not specified, the default is 1.0f.<br />
131         /// Applies to: - PrimitiveVisualShapeType.ConicalFrustrum<br />
132         /// Only values greater than or equal to 0.0f are accepted.<br />
133         /// Optional.
134         /// </summary>
135         /// <since_tizen> 3 </since_tizen>
136         public float ScaleTopRadius
137         {
138             get
139             {
140                 return _scaleTopRadius ?? (1.0f);
141             }
142             set
143             {
144                 _scaleTopRadius = value;
145                 UpdateVisual();
146             }
147         }
148
149         /// <summary>
150         /// Gets or sets the scale of the radius of the bottom circle of a conical frustrum.<br />
151         /// If not specified, the default is 1.5f.<br />
152         /// Applies to:  - PrimitiveVisualShapeType.ConicalFrustrum<br />
153         ///              - PrimitiveVisualShapeType.Cone<br />
154         /// Only values greater than or equal to 0.0f are accepted.<br />
155         /// Optional.
156         /// </summary>
157         /// <since_tizen> 3 </since_tizen>
158         public float ScaleBottomRadius
159         {
160             get
161             {
162                 return _scaleBottomRadius ?? (1.5f);
163             }
164             set
165             {
166                 _scaleBottomRadius = value;
167                 UpdateVisual();
168             }
169         }
170
171         /// <summary>
172         /// Gets or sets the scale of the height of a conic.<br />
173         /// If not specified, the default is 3.0f.<br />
174         /// Applies to:<br />
175         ///      - PrimitiveVisualShapeType.ConicalFrustrum<br />
176         ///      - PrimitiveVisualShapeType.Cone<br />
177         ///      - PrimitiveVisualShapeType.Cylinder<br />
178         /// Only values greater than or equal to 0.0f are accepted.<br />
179         /// Optional.
180         /// </summary>
181         /// <since_tizen> 3 </since_tizen>
182         public float ScaleHeight
183         {
184             get
185             {
186                 return _scaleHeight ?? (3.0f);
187             }
188             set
189             {
190                 _scaleHeight = value;
191                 UpdateVisual();
192             }
193         }
194
195         /// <summary>
196         /// Gets or sets the scale of the radius of a cylinder.<br />
197         /// If not specified, the default is 1.0f.<br />
198         /// Applies to:<br />
199         ///      - PrimitiveVisualShapeType.Cylinder<br />
200         /// Only values greater than or equal to 0.0f are accepted.<br />
201         /// Optional.
202         /// </summary>
203         /// <since_tizen> 3 </since_tizen>
204         public float ScaleRadius
205         {
206             get
207             {
208                 return _scaleRadius ?? (1.0f);
209             }
210             set
211             {
212                 _scaleRadius = value;
213                 UpdateVisual();
214             }
215         }
216
217         /// <summary>
218         /// Gets or sets the dimensions of a cuboid. Scales in the same fashion as a 9-patch image.<br />
219         /// If not specified, the default is Vector3.One.<br />
220         /// Applies to:<br />
221         ///      - PrimitiveVisualShapeType.Cube<br />
222         ///      - PrimitiveVisualShapeType.Octahedron<br />
223         ///      - PrimitiveVisualShapeType.BevelledCube<br />
224         /// Each Vector3 parameter should be greater than or equal to 0.0f.<br />
225         /// Optional.
226         /// </summary>
227         /// <since_tizen> 3 </since_tizen>
228         public Vector3 ScaleDimensions
229         {
230             get
231             {
232                 return _scaleDimensions ?? (Vector3.One);
233             }
234             set
235             {
236                 _scaleDimensions = value;
237                 UpdateVisual();
238             }
239         }
240
241         /// <summary>
242         /// Gets or sets determines how bevelled the cuboid should be, based off the smallest dimension.<br />
243         /// Bevel percentage ranges from 0.0 to 1.0. It affects the ratio of the outer face widths to the width of the overall cube.<br />
244         /// If not specified, the default is 0.0f (no bevel).<br />
245         /// Applies to:<br />
246         ///      - PrimitiveVisualShapeType.BevelledCube<br />
247         /// The range is from 0.0f to 1.0f.<br />
248         /// Optional.
249         /// </summary>
250         /// <since_tizen> 3 </since_tizen>
251         public float BevelPercentage
252         {
253             get
254             {
255                 return _bevelPercentage ?? (0.0f);
256             }
257             set
258             {
259                 _bevelPercentage = value;
260                 UpdateVisual();
261             }
262         }
263
264         /// <summary>
265         /// Gets or sets descriptions of how smooth the bevelled edges should be.<br />
266         /// If not specified, the default is 0.0f (sharp edges).<br />
267         /// Applies to:<br />
268         ///      - PrimitiveVisualShapeType.BevelledCube<br />
269         /// The range is from 0.0f to 1.0f.<br />
270         /// Optional.
271         /// </summary>
272         /// <since_tizen> 3 </since_tizen>
273         public float BevelSmoothness
274         {
275             get
276             {
277                 return _bevelSmoothness ?? (0.0f);
278             }
279             set
280             {
281                 _bevelSmoothness = value;
282                 UpdateVisual();
283             }
284         }
285
286         /// <summary>
287         /// Gets or sets the position, in the stage space, of the point light that applies lighting to the model.<br />
288         /// This is based off the stage's dimensions, so using the width and the height of the stage halved will correspond to the center,
289         /// and using all zeroes will place the light at the top-left corner.<br />
290         /// If not specified, the default is an offset outwards from the center of the screen.<br />
291         /// Applies to all shapes.<br />
292         /// Optional.
293         /// </summary>
294         /// <since_tizen> 3 </since_tizen>
295         public Vector3 LightPosition
296         {
297             get
298             {
299                 return _lightPosition;
300             }
301             set
302             {
303                 _lightPosition = value;
304                 UpdateVisual();
305             }
306         }
307
308         /// <summary>
309         /// Compose the out visual map.
310         /// </summary>
311         /// <since_tizen> 3 </since_tizen>
312         protected override void ComposingPropertyMap()
313         {
314             _outputVisualMap = new PropertyMap(); ;
315             _outputVisualMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Primitive));
316             if (_shape != null) { _outputVisualMap.Add(PrimitiveVisualProperty.Shape, new PropertyValue((int)_shape)); }
317             if (_mixColorForPrimitiveVisual != null) { _outputVisualMap.Add(PrimitiveVisualProperty.MixColor, new PropertyValue(_mixColorForPrimitiveVisual)); }
318             if (_slices != null) { _outputVisualMap.Add(PrimitiveVisualProperty.Slices, new PropertyValue((int)_slices)); }
319             if (_stacks != null) { _outputVisualMap.Add(PrimitiveVisualProperty.Stacks, new PropertyValue((int)_stacks)); }
320             if (_scaleTopRadius != null) { _outputVisualMap.Add(PrimitiveVisualProperty.ScaleTopRadius, new PropertyValue((float)_scaleTopRadius)); }
321             if (_scaleBottomRadius != null) { _outputVisualMap.Add(PrimitiveVisualProperty.ScaleBottomRadius, new PropertyValue((float)_scaleBottomRadius)); }
322             if (_scaleHeight != null) { _outputVisualMap.Add(PrimitiveVisualProperty.ScaleHeight, new PropertyValue((float)_scaleHeight)); }
323             if (_scaleRadius != null) { _outputVisualMap.Add(PrimitiveVisualProperty.ScaleRadius, new PropertyValue((float)_scaleRadius)); }
324             if (_scaleDimensions != null) { _outputVisualMap.Add(PrimitiveVisualProperty.ScaleDimensions, new PropertyValue(_scaleDimensions)); }
325             if (_bevelPercentage != null) { _outputVisualMap.Add(PrimitiveVisualProperty.BevelPercentage, new PropertyValue((float)_bevelPercentage)); }
326             if (_bevelSmoothness != null) { _outputVisualMap.Add(PrimitiveVisualProperty.BevelSmoothness, new PropertyValue((float)_bevelSmoothness)); }
327             if (_lightPosition != null) { _outputVisualMap.Add(PrimitiveVisualProperty.LightPosition, new PropertyValue(_lightPosition)); }
328             base.ComposingPropertyMap();
329         }
330     }
331 }