bacde982469e7df4c6e012696ac2219a8ebf7f4b
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / ColorVisual.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 color visual.
22     /// </summary>
23     /// <since_tizen> 3 </since_tizen>
24     public class ColorVisual : VisualMap
25     {
26         private Color _mixColorForColorVisual = null;
27         private bool? _renderIfTransparent = false;
28
29         /// <summary>
30         /// Constructor.
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         public ColorVisual() : base()
34         {
35         }
36
37         /// <summary>
38         /// Gets or sets the solid color required.<br />
39         /// Mandatory.
40         /// </summary>
41         /// <since_tizen> 3 </since_tizen>
42         public Color Color
43         {
44             get
45             {
46                 return _mixColorForColorVisual;
47             }
48             set
49             {
50                 _mixColorForColorVisual = value;
51                 UpdateVisual();
52             }
53         }
54
55         /// <summary>
56         /// Gets or sets whether to render if the MixColor is transparent.
57         /// By default it is false, which means that the ColorVisual will not render if the MIX_COLOR is transparent.
58         /// </summary>
59         /// <since_tizen> 5 </since_tizen>
60         public bool RenderIfTransparent
61         {
62             get
63             {
64                 return _renderIfTransparent ?? (false);
65             }
66             set
67             {
68                 _renderIfTransparent = value;
69                 UpdateVisual();
70             }
71         }
72
73         /// <summary>
74         /// Compose the out visual map.
75         /// </summary>
76         /// <since_tizen> 3 </since_tizen>
77         protected override void ComposingPropertyMap()
78         {
79             Color color = _mixColorForColorVisual ?? _mixColor;
80
81             if (color != null)
82             {
83                 _outputVisualMap = null;
84
85                 base.ComposingPropertyMap();
86
87                 _outputVisualMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color));
88                 _outputVisualMap.Add(ColorVisualProperty.MixColor, new PropertyValue(color));
89             }
90             else
91             {
92                 _outputVisualMap = new PropertyMap();
93             }
94         }
95     }
96 }