[NUI] Refine codes to reduce code duplication (#1096)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / BorderVisual.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 border visual.
22     /// </summary>
23     /// <since_tizen> 3 </since_tizen>
24     public class BorderVisual : VisualMap
25     {
26         private Color _color = null;
27         private float? _size = null;
28         private bool? _antiAliasing = null;
29
30         /// <summary>
31         /// Constructor.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public BorderVisual() : base()
35         {
36         }
37
38         /// <summary>
39         /// Gets or sets the color of the border.<br />
40         /// Mandatory.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         public Color Color
44         {
45             get
46             {
47                 return _color;
48             }
49             set
50             {
51                 _color = value;
52                 UpdateVisual();
53             }
54         }
55
56         /// <summary>
57         /// Gets or sets the width of the border (in pixels).<br />
58         /// Mandatory.
59         /// </summary>
60         /// <since_tizen> 3 </since_tizen>
61         public float BorderSize
62         {
63             get
64             {
65                 return _size ?? (-1.0f);
66             }
67             set
68             {
69                 _size = value;
70                 UpdateVisual();
71             }
72         }
73
74         /// <summary>
75         /// Gets or sets whether the anti-aliasing of the border is required.<br />
76         /// If not supplied, the default is false.<br />
77         /// Optional.
78         /// </summary>
79         /// <since_tizen> 3 </since_tizen>
80         public bool AntiAliasing
81         {
82             get
83             {
84                 return _antiAliasing ?? (false);
85             }
86             set
87             {
88                 _antiAliasing = value;
89                 UpdateVisual();
90             }
91         }
92
93         /// <summary>
94         /// Compose the out visual map.
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         protected override void ComposingPropertyMap()
98         {
99             if (_color != null && _size != null)
100             {
101                 _outputVisualMap = new PropertyMap();
102                 _outputVisualMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Border));
103                 _outputVisualMap.Add(BorderVisualProperty.Size, new PropertyValue((float)_size));
104                 _outputVisualMap.Add(BorderVisualProperty.Color, new PropertyValue(_color));
105                 if (_antiAliasing != null) { _outputVisualMap.Add(BorderVisualProperty.AntiAliasing, new PropertyValue((bool)_antiAliasing)); }
106                 base.ComposingPropertyMap();
107             }
108         }
109     }
110 }