[NUI] Revert patch about StyleManager (#1970)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / ViewProperty / Shadow.cs
1 /*
2  * Copyright(c) 2020 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 using System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23
24     /// <summary>
25     /// Represents a shadow with color and blur radius for a View.
26     /// </summary>
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class Shadow : ShadowBase, ICloneable
29     {
30         private static readonly Color noColor = new Color(0, 0, 0, 0);
31
32         private static readonly Color defaultColor = new Color(0, 0, 0, 0.5f);
33
34         /// <summary>
35         /// Create a Shadow with default values.
36         /// </summary>
37         [EditorBrowsable(EditorBrowsableState.Never)]
38         public Shadow() : base()
39         {
40             BlurRadius = 0;
41             Color = defaultColor;
42         }
43
44         /// <summary>
45         /// Create a Shadow with custom values.
46         /// </summary>
47         [EditorBrowsable(EditorBrowsableState.Never)]
48         public Shadow(float blurRadius, Vector2 offset, Color color, Vector2 extents) : base(offset, extents)
49         {
50             BlurRadius = blurRadius;
51             Color = new Color(color);
52         }
53
54         /// <summary>
55         /// Copy constructor.
56         /// </summary>
57         [EditorBrowsable(EditorBrowsableState.Never)]
58         public Shadow(Shadow other) : this(other.BlurRadius, other.Offset, other.Color, other.Extents)
59         {
60         }
61
62         /// <summary>
63         /// Create a Shadow from a propertyMap.
64         /// </summary>
65         [EditorBrowsable(EditorBrowsableState.Never)]
66         internal Shadow(PropertyMap propertyMap) : base(propertyMap)
67         {
68         }
69
70         /// <summary>
71         /// The color for the shadow.
72         /// </summary>
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public Color Color { get; set; }
75
76         /// <summary>
77         /// The blur radius value for the shadow. Bigger value, much blurry.
78         /// </summary>
79         /// <remark>
80         /// Negative value is ignored. (no blur)
81         /// </remark>
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public float BlurRadius { get; set; }
84
85         /// <inheritdoc/>
86         [EditorBrowsable(EditorBrowsableState.Never)]
87         public override bool Equals(object other)
88         {
89             if (!base.Equals(other))
90             {
91                 return false;
92             }
93
94             var otherShadow = (Shadow)other;
95
96             if (!((Color == null) ? otherShadow.Color == null : Color.Equals(otherShadow.Color)))
97             {
98                 return false;
99             }
100
101             return BlurRadius.Equals(otherShadow.BlurRadius);
102         }
103
104         /// <inheritdoc/>
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public override int GetHashCode()
107         {
108             unchecked
109             {
110                 int hash = base.GetHashCode();
111                 hash = (hash * 7) + (Color == null ? 0 : Color.GetHashCode());
112                 hash = (hash * 7) + (BlurRadius.GetHashCode());
113                 return hash;
114             }
115         }
116
117         /// <inheritdoc/>
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public object Clone() => new Shadow(this);
120
121         internal override bool IsEmpty()
122         {
123             return (Color == null || Color.A == 0);
124         }
125
126         /// <inheritdoc/>
127         [EditorBrowsable(EditorBrowsableState.Never)]
128         protected override PropertyMap GetPropertyMap()
129         {
130             var map = base.GetPropertyMap();
131
132             map[Visual.Property.Type] = new PropertyValue((int)Visual.Type.Color);
133
134             map[ColorVisualProperty.MixColor] = new PropertyValue(Color ?? noColor);
135
136             map[ColorVisualProperty.BlurRadius] = new PropertyValue(BlurRadius < 0 ? 0 : BlurRadius);
137
138             return map;
139         }
140
141         /// <inheritdoc/>
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         protected override bool SetPropertyMap(PropertyMap propertyMap)
144         {
145             if (!base.SetPropertyMap(propertyMap))
146             {
147                 return false;
148             }
149
150             Color = noColor;
151             propertyMap.Find(ColorVisualProperty.MixColor)?.Get(Color);
152
153             float blurRadius = 0;
154             propertyMap.Find(ColorVisualProperty.BlurRadius)?.Get(out blurRadius);
155             BlurRadius = blurRadius;
156
157             return true;
158         }
159     }
160 }
161
162